[vox-tech] gdb: until doesn't work as advertised?

vox-tech@lists.lugod.org vox-tech@lists.lugod.org
Fri, 20 Sep 2002 14:56:42 -0400


On Thu, Sep 19, 2002 at 05:02:35PM -0700, Peter Jay Salzman wrote:
> begin msimons@moria.simons-clan.com <msimons@moria.simons-clan.com> 
> i agree the above is clearly written.  the real problem, i guess, is
> that i should've given you a sample of what i'm talking about.  :)  so
> here it is:

  This sample is good.  The only difference I saw between this and the
other emails are explict commands on each line (instead of just using
return to repeat the previous command).

> p@satan% gdb until_demo
> (gdb) l
> 1       #include <stdio.h>
> 2
> 3       int main(void)
> 4       {
> 5               int i=0, j=0;
> 6               scanf("%d", &i);
> 7
> 8               while (i) {
> 9                       i--;
> 10                      j++;
> (gdb) break 9
> Breakpoint 1 at 0x8048420: file until_demo.c, line 9.
[...]
> so you see, until doesn't seem to step out of this loop.   from looking
> at this, it looks like until is behaving exactly like next.

  You set a breakpoint inside the loop.  The description for "until" 
doesn't say that it will disable all breakpoints until a higher code
address is reached.  It will run the program until a higher line or (for
good reason), another break condition is hit... (breakpoint, watchpoint,
signal, whatever).


> Breakpoint 1, main () at until_demo.c:9
> 9                       i--;
> $1 = 10
> (gdb) until
> 10                      j++;
> (gdb) 
> 11              }
> (gdb) 
> 
> Breakpoint 1, main () at until_demo.c:9
> 9                       i--;

  You might noticed if you try the above with "next" that you also 
see the "while (i)" line each time the loop happens... a loop looks more 
like (with the stared lines being different from "until"):
====
** 8	   while (i) {
** (gdb) 

Breakpoint 1, main () at bar.c:9
9	      i--;
(gdb) 
10	      j++;
(gdb) 
11	   }
====


> >   "until" steps to the next line of code (preventing the debugger from 
> > going back to a previous line in the same function because
> > of a jump), you don't give until a line number, it's more like "run
> > until the next line of code happens".
> 
> just like next and step, until _can_ take a numerical argument.
> see below.
[...]
> "until 12" resumes execution until line 12 is reached of the current
> stack frame _or_ just after the current stack frame goes out of scope.

  Okay tested, I agree, until with a number argument does run until that
line number is reached or the function being run returns.


  So another suggestion about the breakpoint with commands, test this out:
====
break 9
commands
silent
printf "%d\n", i
continue
end
====

  ... or for even more meyham.
====
break 10
commands
  silent
  printf "i = %d, j = %d\n", i, j
  if (j < 40 && i == 1)
    set variable i=i+1
    end
  continue
end
====