This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Is that a GDB bug?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]