l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
October 7: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2002 Sep 21 13:06

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] bug in gdb?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] bug in gdb?



Try this.  :-)

#!/usr/bin/perl
sub bob() { (@_[0] > 0 ? @_[0] : "no") . " bottle" . (@_[0] == 1 ? "" : "s") . " of beer" }
my $s = "s";
my $bob = " bottle$s of beer";
my $wall = " on the wall\n";
my $fall = "\nIf one of those bottles should happen to fall\nThere'll be ";
my $i = 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 this
> is a bug or feature.
>
> here's the code:
>
>    int main(void)
>    {
>       int i = 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 reason
> 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=4 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.
>
>
> 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

_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.