五.GDB保存断点

今天使用gdb调试了一整天,在好多关键的地方添加了断点,快要下班的时候,因为要关闭远程连接,为了便于明天继续测试,我想把所有的断点都 保存下来。但是因为断点太多了,使用“info b”虽然可以查看到断点,但是,断点的位置得自己找出来,然后保存,感觉有点麻烦。


(gdb) info b
Num Type Disp Enb Address What
1 breakpoint keep y 0x000000000040336d in main(int, char**) at RecvMain.cpp:290
breakpoint already hit 1 time
2 breakpoint keep y 0x00002aaab049c7ef in CRealCreditEventAb::LoopEventCreditCtrl(int)

……




上网想查看一下gdb是否有保存断点的方式,不过值搜到了“python 保存断点”的方法,看到使用“save breakpoints”命令,所以我来到gdb调试环境,查看了gdb是否有参数“save”,如下:

(gdb) save
“save” must be followed by the name of a save subcommand.
List of save subcommands:

save breakpoints – Save current breakpoint definitions as a script
save gdb-index – Save a
save tracepoints – Save current tracepoint definitions as a script

Type “help save” followed by save subcommand name for full documentation.
Type “apropos word” to search for commands related to “word”.
Command name abbreviations are allowed if unambiguous.
(gdb)




看到的确有“save breakpoints ”,禁不住窃喜,使用help查看该命令的含义:

(gdb) help save breakpoints
Save current breakpoint definitions as a script.
This includes all types of breakpoints (breakpoints, watchpoints,
catchpoints, tracepoints). Use the ‘source’ command in another debug
session to restore them.
(gdb)




看了一下解释,果然可以满足我的要求——把所有的断点进行保存,保存到“gdb.cfg”中,如下:

(gdb) save breakpoints gdb.cfg
Saved to file ‘gdb.cfg’.
(gdb) ^Z
[1]+ Stopped gdb RecvMain
[billing_dx@bmcs1 creditctl]$vi gdb.cfg

1 break main
2 break CRealCreditEventAb::LoopEventCreditCtrl
3 break AssignStopTask
……




最前面的是显示的行号,可以看到,我的断点的确保存了。



我又仔细看了一下上面的对于“save breakpoints”的注释,在另一个gdb session中可以使用“source”命令restore(恢复,还原)它们(断点)。测试一下:先删除所有断点,然后使用source恢复所有保存的断点,如下:

(gdb) D                                                #删除所有断点
Delete all breakpoints? (y or n) y
(gdb) info b #查看断点
No breakpoints or watchpoints.
(gdb) source gdb.cfg #加载断点
Breakpoint 9 at 0x40336d: file RecvMain.cpp, line 290.
Breakpoint 10 at 0x2aaab049c7ef: file CRealCreditEventAb.cpp, line 80.
……

(gdb) info b #查看断点
Num Type Disp Enb Address What
9 breakpoint keep y 0x000000000040336d in main(int, char**) at RecvMain.cpp:290
10 breakpoint keep y 0x00002aaab049c7ef in CRealCreditEventAb::LoopEventCreditCtrl(int)
at CRealCreditEventAb.cpp:80
……






多看一眼说明文档,又学到一个新的技巧,记录下来,希望对大家有帮助。



扩展阅读: http://ccshell.com/archives/92.html  python 保存断点

猜你喜欢

转载自blog.csdn.net/wahahaguolinaiyou/article/details/88895669