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]

Why does gdb stop at a different line than âi b â shows while returning from function?


Here is the program I am trying to debug:

#include <stdio.h>
int i = 5;

int main(void)
{
    int x = 3;

    display(x);
    return 0;
}


void display(int x)
{
for ( i=0; i<x; ++i ) {
    printf("i is %d.\n", i);
}
}


This code is coming from here http://www.dirac.org/linux/gdb/05-Stepping_And_Resuming.php#breakpointsandwatchpoints26. Here is the problem:

(gdb) break display 
Breakpoint 1 at 0x40051e: file try5.c, line 15.
(gdb) run
Starting program: /home/ja/gdb/learning/try5 

Breakpoint 1, display (x=3) at try5.c:15
(gdb) frame 1
#1  0x000000000040050c in main () at try5.c:8
(gdb) break 
Breakpoint 2 at 0x40050c: file try5.c, line 8.
(gdb) c
Continuing.
i is 0.
i is 1.
i is 2.

Breakpoint 2, main () at try5.c:9
(gdb) i b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x000000000040051e in display at try5.c:15
    breakpoint already hit 1 time
2       breakpoint     keep y   0x000000000040050c in main at try5.c:8
    breakpoint already hit 1 time
(gdb) c
Continuing.

Program exited normally.
(gdb) q

Debugger finished


It was supposed to stop at line 8 in main() but it stopped at line 9 it main(). For me it's misleading. I think it should stop at line 9, because this is what 'break' commands does - sets a break point at the very next instruction. But why "info breakpoints" said that the break point was set at line 8?


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