gdb 高级用法

1  条件断点

 

19 #include <stdio.h> 20 21 int main() 22 { 23 int i,j; 24 for( i = 0; i < 10; ++i) 25 { 26 j = i + 1; 27 printf("%d/n", j); 28 } 29 return 0; 30 } ~ ~

 

(gdb) b test.c:26 if j == 5
Breakpoint 3 at 0x4004a9: file test.c, line 26.
(gdb) c
Continuing.
1
2
3
4
5

Breakpoint 3, main () at test.c:26
26            int j = i + 1;

 

 

当j==5的时候,程序就停在那里了。

 

 

2  当变量被修改时设置断点

 

(gdb) watch j
Hardware watchpoint 2: j
(gdb) c
Continuing.
Hardware watchpoint 2: j

Old value = 0
New value = 1
main () at test.c:28
28            printf("%d/n", j);  

 

 

 

3  查看调用的栈:

 

可以使用 bt 或者where 查看调用的栈。

可以使用up和down查看上一个和下一个栈

 

 

 

你可能感兴趣的:(File,UP,BT)