|
|
| Watchpoints with condition |
  United States |
2007-11-30 10:25:19 |
GDB presently allow a watchpoint to have a condition, and I
wonder
what are the use-cases for that.
If anybody has used watchpoint in condition in practice when
debugging
real problem (as opposed to just playing with gdb, or making
up
possible uses), can he share why it was needed?
- Volodya
|
|
| Re: Watchpoints with condition |
  United States |
2007-11-30 10:37:45 |
On Fri, Nov 30, 2007 at 07:25:19PM +0300, Vladimir Prus
wrote:
>
> GDB presently allow a watchpoint to have a condition,
and I wonder
> what are the use-cases for that.
>
> If anybody has used watchpoint in condition in practice
when debugging
> real problem (as opposed to just playing with gdb, or
making up
> possible uses), can he share why it was needed?
I haven't, but here's a use case: if the condition is
something you
couldn't set a watchpoint on or would take too many hardware
resources
to watch. E.g.
set $name = "my_function"
watch global_variable if strcmp (cfun->name, $name) ==
0
--
Daniel Jacobowitz
CodeSourcery
|
|
| Re: Watchpoints with condition |
  United States |
2007-11-30 17:30:21 |
Eli Zaretskii <eliz at gnu.org> writes:
>> From: Vladimir Prus <vladimir codesourcery.com>
>> Date: Fri, 30 Nov 2007 19:25:19 +0300
>>
>>
>> GDB presently allow a watchpoint to have a
condition, and I wonder
>> what are the use-cases for that.
>>
>> If anybody has used watchpoint in condition in
practice when debugging
>> real problem (as opposed to just playing with gdb,
or making up
>> possible uses), can he share why it was needed?
>
> I use it quite a lot. The simplest use case is like
this:
>
> (gdb) watch foo if foo == 1
Isn't that equivalent to 'watch foo == 1'?
|
|
| Re: Watchpoints with condition |
  United States |
2007-11-30 17:48:54 |
On Fri, Nov 30, 2007 at 03:30:21PM -0800, Jim Blandy wrote:
> Isn't that equivalent to 'watch foo == 1'?
Not quite.
watch foo == 1
stops when foo becomes 1 or non-1.
watch foo if foo == 1
stops only when foo becomes 1.
--
Daniel Jacobowitz
CodeSourcery
|
|
| Re: Watchpoints with condition |
  Australia |
2007-11-30 19:10:24 |
Vladimir Prus wrote:
> GDB presently allow a watchpoint to have a condition,
and I wonder
> what are the use-cases for that.
>
> If anybody has used watchpoint in condition in practice
when debugging
> real problem (as opposed to just playing with gdb, or
making up
> possible uses), can he share why it was needed?
I frequently need to enable or set a breakpoint only if
another
previous point in the program has been passed. How do i do
that?
|
|
| Re: Watchpoints with condition |
  United States |
2007-11-30 19:32:51 |
On Sat, 2007-12-01 at 12:10 +1100, Russell Shaw wrote:
> Vladimir Prus wrote:
> > GDB presently allow a watchpoint to have a
condition, and I wonder
> > what are the use-cases for that.
> >
> > If anybody has used watchpoint in condition in
practice when debugging
> > real problem (as opposed to just playing with gdb,
or making up
> > possible uses), can he share why it was needed?
>
> I frequently need to enable or set a breakpoint only if
another
> previous point in the program has been passed. How do i
do that?
set $passed_milestone = 0
break milestone_func
commands
silent
set $passed_milestone = 1
end
break conditional_func if ($passed_milestone)
|
|
| Re: Watchpoints with condition |
  Israel |
2007-12-01 03:15:45 |
> From: Michael Snyder <msnyder specifix.com>
> Cc: gdb sources.redhat.com
> Date: Fri, 30 Nov 2007 17:32:51 -0800
>
> > I frequently need to enable or set a breakpoint
only if another
> > previous point in the program has been passed. How
do i do that?
>
>
> set $passed_milestone = 0
> break milestone_func
> commands
> silent
> set $passed_milestone = 1
> end
> break conditional_func if ($passed_milestone)
Or just
tbreak milestone_func
commands
silent
break conditional_func
continue
end
|
|
| Re: Watchpoints with condition |
  Israel |
2007-12-03 14:59:37 |
> From: Jim Blandy <jimb codesourcery.com>
> Date: Mon, 03 Dec 2007 09:54:41 -0800
>
> Okay, so 'watch foo if foo == 1' has some interesting
behavior:
> - if foo is 1 when the watchpoint is set, then the
watchpoint doesn't
> trigger until foo becomes != 1, and then becomes 1
again.
> - If foo is != 1 when the watchpoint is set, then the
command is
> equivalent to watch foo == 1.
>
> The first case seems really obscure; I assumed that
wasn't what Eli
> was using conditional watchpoints for "quite a
lot".
Right. You can "set foo = something that is not
1", before starting
to watch like that. But that's normally not a problem in
real life,
because this use case is for catching writes of _rare_
values, not
frequent ones.
> I think the only valuable use case for conditional
watchpoints is the
> one you mentioned, where Y is something expensive, and
X is some
> cheaper conservative approximation to the condition we
really want.
Well, you are wrong (and Daniel explained one reason why).
Believe
me, this use case is very useful and important. (Actually,
it was one
of the main reasons I got involved with fixing x86 hardware
watchpoints at the time: I needed to set several watchpoints
on the
same variable, each one watching a different value being
written.)
|
|
| Re: Watchpoints with condition |
  United States |
2007-12-03 17:07:19 |
Eli Zaretskii <eliz at gnu.org> writes:
>> I think the only valuable use case for conditional
watchpoints is the
>> one you mentioned, where Y is something expensive,
and X is some
>> cheaper conservative approximation to the condition
we really want.
>
> Well, you are wrong (and Daniel explained one reason
why). Believe
> me, this use case is very useful and important.
(Actually, it was one
> of the main reasons I got involved with fixing x86
hardware
> watchpoints at the time: I needed to set several
watchpoints on the
> same variable, each one watching a different value
being written.)
I don't want to believe you; I want to understand it for
myself.
What I understand Daniel to be saying is that 'watch X if Y'
allows
you to restrict yourself to transitions into a certain
state, whereas
any 'watch Y' will always report both transitions to and
from the
state.
In the use case you mention, why wouldn't 'watch v == X';
'watch v ==
Y'; etc. have worked for you? You would have gotten more
hits than
you'd like, but only twice as many --- is that right?
|
|
| Re: Watchpoints with condition |
  United States |
2007-12-03 19:50:50 |
On Fri, 2007-11-30 at 19:25 +0300, Vladimir Prus wrote:
> GDB presently allow a watchpoint to have a condition,
and I wonder
> what are the use-cases for that.
>
> If anybody has used watchpoint in condition in practice
when debugging
> real problem (as opposed to just playing with gdb, or
making up
> possible uses), can he share why it was needed?
May I ask, what prompts the question?
Were you thinking of getting rid of it?
|
|