Linux gdb 除錯,perror 解惑

2021-09-28 22:56:54 字數 941 閱讀 1727

用gdb除錯程式(一) ——陳皓

在編譯程式時需要-g引數,為程式加上除錯資訊。

cc hello.c -g -o hello
進入後的 help 命令只是列出命令種類,需要進一步help command

shell command用來執行 shell 命令,例如shell ls

file裝載程式檔案

l列出程式源**,已檢查是否裝載上

break設定斷點

rrun 的簡寫,執行程式

nnext 簡寫,執行下一條語句

ccontinue 簡寫,繼續執行程式

void

perror

(const

char

*s);

// first (if s is not null and *s is not a null byte ('\0')), the argument string s is printed, followed by a colon and a blank.

#include

#include

#include

#include

intmain

(int argc,

char

*ar**)

輸出分析:

~]$  ./a.out hello.txt

hello.txt: no such file or directory

所需要的標頭檔案#include

linux gdb除錯彙編

1 除錯hello,要求編譯時指定了 gstabs選項 2 執行hello deepfuture lx deepfuture lx desktop private mytest hello hello,world abcd 3 用gdb開啟hello deepfuture lx deepfuture...

Linux gdb除錯總結

進入除錯 1 輸入gdb 檔名 2 輸入gdb file 檔名 l 顯示源 預設顯示main函式所在檔案的源 list 檔名 num 顯示指定檔案指定行附近的源 b breakpoint的簡寫,設定斷點。b 行號 給指定行新增斷點 b 函式名 給指定函式新增斷點 b 檔名 行號 給指定檔案指定行新增...

Linux gdb除錯總結

在windows作業系統下,我們的執行程式有兩個版本。debug開發除錯版本 得到的可執行檔案.exe檔案相對較大,其中包含除錯資訊。且不做任何優化,未開發人員提供強大的應用除錯能力 release發行版本 檔案相對較小,不包含除錯資訊,並進行了各種優化,以期達到 最小和速度最優。為使用者的使用提供...