这是我要调试的程序:
#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);
}
}
这段代码来自这里http://www.dirac.org/linux/gdb/05-Stepping_And_Resuming.php#breakpointsandwatchpoints。这是问题所在:
(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
它应该在 main() 的第 8 行停止,但它在 main() 的第 9 行停止。对我来说,这是误导。我认为它应该在第 9 行停止,因为这就是“break”命令的作用——在下一条指令处设置断点。但是为什么“信息断点”说断点设置在第 8 行呢?