This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: watchpoints inside 'commands'


> Date: Sun, 8 Apr 2001 16:58:52 -0700
> From: Edward Peschko <edwardp@excitehome.net>
> 
> if you say something like:
> 
> b 20
> Breakpoint 1 at 0x10924: file a.c, line 20.
> commands 1
> > silent
> > watch data[0];
> > continue
> 
> then, gdb will set up a watchpoint (which I assume is a breakpoint)
> at 20 when line #20 is hit. So far so good.
> 
> But the watchpoint has a different *number* each time it comes up (ie: watch
> data[0] is 'watchpoint 2' on the first way round, watch data[0] is
> 'watchpoint 3' the second time round, etc. etc.

The command `commands' can be used with no argument, in which case it
refers to the last breakpoint or watchpoint set.  So this (UNTESTED):

 b 20
 Breakpoint 1 at 0x10924: file a.c, line 20.
 commands 1
 > silent
 > watch data[0]
 > set $wpnum = $bpnum
 > tbreak 25
 > commands
 > > silent
 > > delete $wpnum
 > > continue
 > > end
 > continue
 > end

should do the trick.

> And in any case, wouldn't it be easier to say -
> 
> watch data[0] 22 25
> 
> meaning 'watch the memory space represented by data[0] from line 22
> to line 25'?

I think the above just about implements this ;-).  You can define a
new command which does that, save it to your .gdbinit, and then use it
at will.

> > That's true, but you could handle this with watchpoint commands: they
> > could simply print their usual stuff and then continue.  Later you
> > could examine the session script and decide which of the breaks were
> > false alarms and which not.
> 
> That would be fine, if watchpoints didn't change their number each time you 
> created and deleted them...

I think you can solve this with $bpnum and `commands' without an
argument.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]