GDB 的几个用法(until, finish, tui)

来源:互联网 发布:java通过ip获取城市名 编辑:程序博客网 时间:2024/05/04 18:07

1. until

这个用于执行完循环。

在执行完循环体内的最后一条语句之后执行 until, 就会执行完循环体到后面的一个语句停下。

2. finish

执行完当前的函数。

3. tui

是一个命令行的界面,能同时把代码显示出来。

inf


4. 设置条件断点的方法:

4.1 break [location]  if condition

(gdb) l2{3int i;4int k = 0;5for(i = 0; i < 10; i++)6{7k = i * i;8}910return 0;11}(gdb) break 7 if i == 5Breakpoint 4 at 0x80483ca: file testloop.c, line 7.(gdb) rThe program being debugged has been started already.Start it from the beginning? (y or n) yStarting program: /home/charles/code/testloop Breakpoint 4, main () at testloop.c:77k = i * i;(gdb) p i$7 = 5(gdb) 
4.2 使用 condition  N condition.  N是一个 breakpoint number.

(gdb) l1int main(void)2{3int i;4int k = 0;5for(i = 0; i < 10; i++)6{7k = i * i;8}910return 0;(gdb) break 7Breakpoint 1 at 0x80483ca: file testloop.c, line 7.(gdb) info breakpoints Num     Type           Disp Enb Address    What1       breakpoint     keep y   0x080483ca in main at testloop.c:7(gdb) help condition Specify breakpoint number N to break only if COND is true.Usage is `condition N COND', where N is an integer and COND is anexpression to be evaluated whenever breakpoint N is reached.(gdb) condition  1 i == 4(gdb) info breakpoints Num     Type           Disp Enb Address    What1       breakpoint     keep y   0x080483ca in main at testloop.c:7stop only if i == 4(gdb) rStarting program: /home/charles/code/testloop Breakpoint 1, main () at testloop.c:77k = i * i;(gdb) p i$1 = 4


5. 多线程下禁止线程切换:

set scheduler-locking on


0 0