[vox-tech] bug in gdb?
Rod Roark
vox-tech@lists.lugod.org
Fri, 20 Sep 2002 18:45:24 -0700
Try this. :-)
#!/usr/bin/perl
sub bob() { (@_[0] > 0 ? @_[0] : "no") . " bottle" . (@_[0] =3D=3D 1 ? ""=
: "s") . " of beer" }
my $s =3D "s";
my $bob =3D " bottle$s of beer";
my $wall =3D " on the wall\n";
my $fall =3D "\nIf one of those bottles should happen to fall\nThere'll b=
e ";
my $i =3D 99;
print &bob($i), $wall, &bob($i), $fall, &bob(--$i), $wall, "\n" while ($i=
> 0);
-- Rod
http://www.sunsetsystems.com/
On Friday 20 September 2002 05:52 pm, Peter Jay Salzman wrote:
> gdb isn't doing something i'm expecting it to do. i'm wondering if thi=
s
> is a bug or feature.
>
> here's the code:
>
> int main(void)
> {
> int i =3D 5;
>
> while (i)
> --i;
>
> return 0;
> }
>
>
> my goal is to teach gdb how to sing the "bottles of beer" song.
>
> here are the commands. blank lines indicate that gdb is singing, so
> there will be output. you can cut and paste this into a gdb session,
> but cut and paste it in blocks (so do the 1st block first, let gdb run,
> then repeat for the 2nd and 3rd blocks).
>
> note, breakpoint 1 is set simply to let the variable "i" come into
> scope. after that, i don't need it anymore so i delete breakpoint 1.
>
>
> break main
> run
> break 6
> commands 2
> printf "%d bottles of beer on the wall, %d bottles of beer.\n", i, i
> printf "If one of those bottles happen to fall...\n"
> end
> continue
>
>
> commands 2
> silent
> printf "%d bottles of beer on the wall, %d bottles of beer.\n", i, i
> printf "If one of those bottles happen to fall...\n"
> continue
> end
> delete 1
> run
>
>
> break 6 if i < 5
> commands 3
> silent
> printf "%d bottles of beer on the wall!\n", i - 1
> continue
> end
> run
>
>
> if you think about it, i didn't do things quite efficiently. the reaso=
n
> for this is that this is part of a tutorial i'm writing. but it should
> still work.
>
> after the last "run", here's the output:
>
> (gdb) run
> 5 bottles of beer on the wall, 5 bottles of beer.
> If one of those bottles happen to fall...
> 4 bottles of beer on the wall, 4 bottles of beer.
> If one of those bottles happen to fall...
> 3 bottles of beer on the wall, 3 bottles of beer.
> If one of those bottles happen to fall...
> 2 bottles of beer on the wall, 2 bottles of beer.
> If one of those bottles happen to fall...
> 1 bottles of beer on the wall, 1 bottles of beer.
> If one of those bottles happen to fall...
>
> the problem is that breakpoint #3 isn't printing anything:
>
> (gdb) i b
> Num Type Disp Enb Address What
> 2 breakpoint keep y 0x080483d8 in main at sing.c:6
> breakpoint already hit 5 times
> silent
> printf "%d bottles of beer on the wall, %d bottles of beer.\n=
",
> i, i printf "If one of those bottles happen to fall...\n"
> continue
> 3 breakpoint keep y 0x080483d8 in main at sing.c:6
> stop only if i < 5
> breakpoint already hit 4 times
> silent
> printf "%d bottle of beer on the wall!\n", i - 1
> continue
>
> what if i delete the 2nd breakpoint:
>
> (gdb) disable 2
> (gdb) run
> Starting program: /home/p/writing/ddd/src/sing
> 3 bottle of beer on the wall!
> 2 bottle of beer on the wall!
> 1 bottle of beer on the wall!
> 0 bottle of beer on the wall!
>
> looks ok, but i'm not sure why i=3D4 isn't being printed. anyway, now
> i'll re-enable the 2nd breakpoint:
>
> (gdb) enable 2
> (gdb) run
> Starting program: /home/p/writing/ddd/src/sing
> 5 bottles of beer on the wall, 5 bottles of beer.
> If one of those bottles happen to fall...
> 4 bottles of beer on the wall, 4 bottles of beer.
> If one of those bottles happen to fall...
> 3 bottles of beer on the wall, 3 bottles of beer.
> If one of those bottles happen to fall...
> 2 bottles of beer on the wall, 2 bottles of beer.
> If one of those bottles happen to fall...
> 1 bottles of beer on the wall, 1 bottles of beer.
> If one of those bottles happen to fall...
>
> once the 2nd breakpoint is enabled, the 3rd breakpoint doesn't print
> anything. however, as you can see, the 3rd breakpoint was hit 4 times=
=2E
>
>
> i can't find anything in the user manual that talks about command lists
> for breakpoints set on top of each other.
>
> is this a bug or am i missing something?
>
> pete