這裏是我試圖調試的程序:爲什麼gdb停在與「i b」不同的行而不是從函數返回時顯示?
#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,但它停在第9行它的main()。對我來說這是誤導。我認爲它應該停在第9行,因爲這是'break'命令的作用 - 在下一條指令中設置一個斷點。但爲什麼「信息斷點」說斷點設置在第8行?
如何在收益0附近放置右括號? ?線條是從0還是1開始的? – 2012-07-28 15:09:48
我懷疑你的程序甚至編譯了......'void display(int x)'在**使用後定義**。這應該是一個編譯器錯誤! – YePhIcK 2012-07-28 15:13:52
@tuğrulbüyükışık - 謝謝,我修復 – user1042840 2012-07-28 15:18:49