五.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 保存斷點

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章