gdb init配置檔案的使用(2)

2021-10-04 10:54:53 字數 2721 閱讀 2768

使用gdb除錯大型c++程式的時候,經常遇到的場景是反覆除錯某個bin/out,簡單修改再編譯除錯,因此每次進入gdb後重複執行某些操作很麻煩(如打多個斷點),這時就可以用gdb命令指令碼了,它能夠很好的完成這些工作。

以設定多個斷點為例,我寫的命令指令碼為

[dev@szvphicprd90255 linux_output]$ cat ~/.gdbinit

#filename: .gdbinit

#gdb will read it when starting

file testrunner

b main

b l2xxmemxxstub.cpp:220

b l2memoub2.cpp:213

b l2xxhrinit.c:147

r.gdbinit檔案位於何處,如何使用,配置

建立乙個名為.gdbinit的新檔案。現在每次gdb啟動它都將執行此檔案中的命令。

可以將.gdbinit放入除錯程式所在資料夾中,這樣可以更適用於除錯不同的應用程式。gdb啟動將自動載入./.gdbinit以進行當前除錯。

也可以放在使用者主目錄中 ~/.gdbinit,使其配置對所有除錯程式生效

但使用過程中一定要注意在 .gdbinit中要指明除錯的檔案 filename,否則後續命令不知道是打給誰的。

for help, type 「help」.

type 「apropos word」 to search for commands related to 「word」…

no symbol table is loaded. use the 「file」 command.

make breakpoint pending on future shared library load? (y or [n]) [answered n; input not from terminal]

no symbol table is loaded. use the 「file」 command.

make breakpoint pending on future shared library load? (y or [n]) [answered n; input not from terminal]

no symbol table is loaded. use the 「file」 command.

make breakpoint pending on future shared library load? (y or [n]) [answered n; input not from terminal]

no symbol table is loaded. use the 「file」 command.

make breakpoint pending on future shared library load? (y or [n]) [answered n; input not from terminal]

reading symbols from ./testrunner…

(gdb) info b

no breakpoints or watchpoints.

(gdb) q

[dev@szvph

新增filename後,gdbinit符合預期

for help, type 「help」.

type 「apropos word」 to search for commands related to 「word」.

breakpoint 1 at 0x41b30c: file …/l2_pcst/testrunner/base/main.cpp, line 30.

breakpoint 2 at 0x1403be8: file …stub2.cpp, line 220.

breakpoint 3 at 0x1403bb0: file …stub1.cpp, line 213.

breakpoint 4 at 0xecb618: file ***nit.c, line 147.

(gdb) info b

num type disp enb address what

1 breakpoint keep y 0x000000000041b30c in main(int, char**) at …/l2_pcst/testrunner/base/main.cpp:30

2 breakpoint keep y 0x0000000001403be8 in sssmemllocalign

at …/l2_tssxx/lx2ixnf_stub/l2oxs/l2oxsemorstub.cpp:220

3 breakpoint keep y 0x0000000001403bb0 in ***allocalign(

at …/***xmemorystub.cpp:213

4 breakpoint keep y 0x0000000000ecb618 in l2allocchrtagmem at ***_init.c:147

(gdb)

有兩種方式來使用這個指令碼:

1)啟動gdb時候

gdb在啟動的時候,會在當前目錄下查詢".gdbinit"這個檔案,並把它的內容作為gdb命令進行解釋,所以如果我把指令碼命名為".gdbinit",這樣在啟動的時候就會處理這些命令。

2)gdb執行期間

可以使用 source script-file 來解釋gdb命令指令碼script-file

常用 .gdbinit 檔案參考:

部分ref:

2 配置檔案

configuration 配置properties 屬性settings 設定typealiases 型別別名 typehandlers 型別處理器 objectfactory 物件工廠 plugins 外掛程式environments 環境配置 environment 環境變數 transact...

讀配置檔案2

資料 host 1 ip 16.173.234.228 port 21,80,873,3306 cpu 10 freemem 3 conconn 1000 checkgw 1 freedisk 10 swapused 30000 host host 2 ip 16.173.235.25 port 2...

spring cloud配置檔案2

在上篇文章裡提到了通過禁用服務發現和配置中心來方便開發,那麼問題來了,如果我們要用ribbon訪問某遠端服務,我們該如何做呢。雖然開發環境禁用了服務發現,無法獲取服務列表,但我們可以通過配置檔案為某服務配置乙個靜態位址。pda sync ribbon listofservers 13.13.31.9...