GDB除錯技巧,除錯命令

2022-09-18 15:15:09 字數 2522 閱讀 4479

除錯時檢視依賴dso

pidof tvm_rpc_server

cat /proc//maps

子程序除錯

1.vscode

"setupcommands": [

, /output/cpu_simu_dev/bin:$ld_library_path",

"ignorefailures": false

},

-exec catch throw
2.gdb
gdb --args ./tvm_rpc_server --port=9080

gdb> set follow-fork-mode child

gdb> catch throw

補充知識:catch point

有時程式中有未捕獲的異常會導致程式異常的行為甚至導致程式的直接退出。 這對伺服器程式來說是不可接受的。

可以使用gdb的catch命令來幫助我們除錯異常。

使用gdb捕獲異常的扔出點(相當於在扔出異常的地方新增斷點):

catch pthread_exit

這樣,如果相應的事件發生,gdb就會中斷程式的執行, 就可以使用gdb的bt命令來檢查出現錯誤的呼叫棧了。

cache命令:

(gdb) help catch

set catchpoints to catch events.

raised signals may be caught:

catch signal - all signals

catch signal - a particular signal

raised exceptions may be caught:

catch throw - all exceptions, when thrown

catch throw - a particular exception, when thrown

catch catch - all exceptions, when caught

catch catch - a particular exception, when caught

thread or process events may be caught:

catch thread_start - any threads, just after creation

catch thread_exit - any threads, just before expiration

catch thread_join - any threads, just after joins

process events may be caught:

catch start - any processes, just after creation

catch exit - any processes, just before expiration

catch fork - calls to fork()

catch vfork - calls to vfork()

catch exec - calls to exec()

dynamically-linked library events may be caught:

catch load - loads of any library

catch load - loads of a particular library

catch unload - unloads of any library

catch unload - unloads of a particular library

the act of your program's execution stopping may also be caught:

catch stop

c++ exceptions may be caught:

catch throw - all exceptions, when thrown

catch catch - all exceptions, when caught

do "help set follow-fork-mode" for info on debugging your program

after a fork or vfork is caught.

do "help breakpoints" for info on other commands dealing with breakpoints.

參考:

使用gdb除錯異常

gdb doc -- setting catchpoints

GDB除錯技巧

在公司工作了一段時間,發現 b s結構的 除錯很麻煩,經常用的手段是通過 printf 打一串訊息來進行跟蹤,然後估計問題出在 通過逐步新增 printf 語句,獲得越來越多的資訊最終確定問題的根源。我感覺這樣比較麻煩,如果能把 gdb的單步除錯功能用上就好了。工作之餘,做了一定的嘗試,希望對跟我一...

GDB除錯技巧

談到gdb,不能不對他的強大功能所折服,在我所用過的所有偵錯程式中,這實在是乙個強大的除錯工具,今天就說說gdb的簡單用法。gdb是gnu開源組織發布的乙個強大的unix下的程式除錯工具。或許,各位比較喜歡那種圖形介面方式的,像vc bcb等ide的除錯,但如果你是在 unix平台下做軟體,你會發現...

gdb除錯技巧

1 以結構體形式訪問某個記憶體 print type addr 其中type是結構體型別,addr是記憶體的位址 2 顯示符號表 info symbol info symbol symbol addr symbol addr為對應的位址 print 符號名 3 檢視型別的原型定義 有時候在除錯大型程...