This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Is that a GDB bug?
- From: Simon Marchi <simon dot marchi at polymtl dot ca>
- To: Andreas Schwab <schwab at suse dot de>, Nancy <nancydreaming at gmail dot com>, "gdb at sourceware dot org" <gdb at sourceware dot org>
- Date: Mon, 12 Oct 2015 12:55:49 -0400
- Subject: Re: Is that a GDB bug?
- Authentication-results: sourceware.org; auth=none
- References: <CADdyJmk-gKUVEUYRwqmXPknUL8QiT=x+J6ZA2BL8WjK1Nf+Z3A at mail dot gmail dot com> <20151012132040 dot GA28674 at vapier dot lan> <mvm8u78yzz4 dot fsf at hawking dot suse dot de> <20151012163933 dot GA4446 at vapier dot lan>
On 12 October 2015 at 12:39, Mike Frysinger <vapier@gentoo.org> wrote:
> On 12 Oct 2015 15:32, Andreas Schwab wrote:
>> Mike Frysinger <vapier@gentoo.org> writes:
>> > next operates on statements, not lines.
>>
>> That's not true.
>>
>> (gdb) help step
>> Step program until it reaches a different source line.
>
> "next" != "step"
Andreas probably pasted the help for "step" because the help for
"next" refers to "step":
(gdb) help next
Step program, proceeding through subroutine calls.
Usage: next [N]
Unlike "step", if the current source line calls a subroutine,
this command does not enter the subroutine, but instead steps over
the call, in effect treating it as a single source line.
If I understand correctly (and please correct me if I'm wrong), the
debug info only maps each instruction to a line of the original source
file. The algorithm for step/next when no subroutines are involved is
equivalent to "step instructions as long as they belong to the same
source line". When the CPU is about to execute an instruction that
belongs to an other source line, we stop. So there is no knowledge of
statements.
You can verify what Pedro said by removing the breakpoint before doing the next:
(gdb) b 5
Breakpoint 1 at 0x80483d8: file test.c, line 5.
(gdb) r
Starting program: /tmp/binutils-gdb/gdb/test
Breakpoint 1, main () at test.c:5
5 L1: switch(x) { case 0: x=1; goto L1; case 1: if(x==0) goto
L1; else break; }
(gdb) delete 1
(gdb) n
6 x=2;
(gdb)
Here, the next is not interrupted by the breakpoint, so the program
stops just before executing the first instruction that belongs to
x=2;.
Simon