gdb 除錯入門(二) 使用終端進行 gdb 除錯

2021-10-05 02:38:20 字數 1373 閱讀 9254

在安裝完 gdb 後,就可以嘗試使用 gdb 在終端中除錯程式了,如果對安裝 gdb 存在疑惑,請參考 gdb 除錯入門(一):windows/linux/ubuntu 下安裝 gdb。

首先編寫乙個簡單的helloworld.c:

#include

intmain()

你也可以定位到你需要除錯的 .c 程式,然後開始下一步。

在含helloworld.c的目錄終端下輸入:

gcc -g helloworld.c -o helloworld
然後可以發現在此目錄下生成了乙個名為helloworld的可執行檔案。

在上節的終端裡繼續輸入 gdb + 上節生成的要除錯程式的可執行檔名:

gdb helloworld
可以發現終端列印了以下 log 資訊:

gnu gdb (gdb) 7.12

license gplv3+: gnu gpl version 3 or later <>

this is free software: you are free to change and redistribute it.

there is no warranty, to the extent permitted by law. type "show copying"

and "show warranty"

for details.

this gdb was configured as "x86_64-pc-linux-gnu"

.type "show configuration"

for configuration details.

for bug reporting instructions, please see:

<>.

find the gdb manual and other documentation resources online at:

<>.

for help, type

"help"

.type "apropos word" to search for commands related to "word"

...reading symbols from helloworld...done.

然後就可以進行除錯了,比如輸入list,可以看到如下 log:

(gdb) list

1 #include

2 int main(

)3

開始盡情除錯吧~

利用終端進行GDB除錯

眾所周知,除錯的辦法有 折半插斷點輸出的方式,還有區域性注釋編譯執行的方式之外,就是gdb除錯了 現總結gdb除錯中常用的語句操作。首選,利用終端編譯檔案的時候,需要使用選擇項 g 編譯可執行檔案,不然的花,無法進行gdb除錯 gdb的基本語句 命令 list 顯示區域性 b 行號 在第幾行插入斷點...

使用GDB進行除錯

使用gdb除錯c程式 gdb是gnu開源組織發布的乙個非圖形化的unix下的程式除錯軟體。它能使使用者在程式執行時觀察資料的內部結構和記憶體使用情況。gdb提供的主要功能 1 監視程式中的變數值 2 設定斷點,使程式在指定 行停止。3 單步執行 4 動態改變程式的執行環境 等一 除錯乙個簡單的程式 ...

使用gdb進行除錯

gdb主要幫忙你完成下面四個方面的功能 1 啟動你的程式,可以按照你的自定義的要求隨心所欲的執行程式。2 可讓被除錯的程式在你所指定的調置的斷點處停住。斷點可以是條件表示式 3 當程式被停住時,可以檢查此時你的程式中所發生的事。4 動態的改變你程式的執行環境。一般來說gdb主要除錯的是c c 的程式...