From: Pedro Alves <palves@redhat.com>
To: Nancy <nancydreaming@gmail.com>, gdb@sourceware.org
Subject: Re: Is that a GDB bug?
Date: Mon, 12 Oct 2015 14:14:00 -0000 [thread overview]
Message-ID: <561BC039.9050708@redhat.com> (raw)
In-Reply-To: <CADdyJmk-gKUVEUYRwqmXPknUL8QiT=x+J6ZA2BL8WjK1Nf+Z3A@mail.gmail.com>
On 10/12/2015 01:46 PM, Nancy wrote:
> Hi,
>
> Why line 5 execute twice? Is that a GDB bug?
>
> debug.c :
> 1 int main()
> 2 {
> 3 int x;
> 4 x=0;
> 5 L1: switch(x) { case 0: x=1; goto L1; case 1: if(x==0)
> goto L1; else break; }
> 6 x=2;
> 7 }
>
> $ gcc -O0 -g debug.c -o debug
> $ gdb debug
> GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
> Copyright (C) 2014 Free Software Foundation, Inc.
> ....................
> Reading symbols from debug...done.
> (gdb) b 5
> Breakpoint 1 at 0x80483fa: file debug.c, line 5.
> (gdb) r
> Starting program: /mnt/hgfs/cygwin/tmp/debug
>
> Breakpoint 1, main () at debug.c:5
> 5 L1: switch(x) { case 0: x=1; goto L1; case 1: if(x==0) goto
> L1; else break; }
> (gdb) n
x starts as 0. So the fist time, "goto L1" is executed. That makes execution
flow back to the address where the breakpoint was inserted, so you get another
breakpoint hit:
>
> Breakpoint 1, main () at debug.c:5
> 5 L1: switch(x) { case 0: x=1; goto L1; case 1: if(x==0) goto
> L1; else break; }
It doesn't matter that "next" was in progress. The breakpoint hit takes
priority.
> (gdb) n
> 6 x=2;
>
>
Thanks,
Pedro Alves
prev parent reply other threads:[~2015-10-12 14:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-12 12:46 Nancy
2015-10-12 13:20 ` Mike Frysinger
2015-10-12 13:32 ` Andreas Schwab
2015-10-12 16:39 ` Mike Frysinger
2015-10-12 16:56 ` Simon Marchi
2015-10-12 16:59 ` Andreas Schwab
2015-10-12 14:14 ` Pedro Alves [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=561BC039.9050708@redhat.com \
--to=palves@redhat.com \
--cc=gdb@sourceware.org \
--cc=nancydreaming@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox