linux gdb配合core檔案進行強強聯手

來源:互聯網
上載者:User

首先,向gnu的前輩們致敬。

 

linux下調試工具gdb是很強大的調試器,此次講的是使用core檔案進行程式出錯的記錄,要使用core這個功能項,必須先設定,設定方法為:

 

使用ulimit命令進行查看,如下:

[sam@UFO testc]$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 16381
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

 

注意core file size          (blocks, -c) 0 這行,這表示的是分配給core檔案的長度(單位為塊,一個塊的大小要分系統而定了),為0肯定是不得行的,那就修改之,輸入如下命令:

ulimit -c 1024

然後就可以使用gdb 執行編譯為debug版本的程式了,在這個程式出錯後,出錯的資訊就會儲存到一個預設以core開頭的檔案中了

 

具體操作有二種方式:

(1)在gdb中由於錯誤而停止的地方,再輸入要繼續執行的指令,如:c  s  n諸如此類的命令,再退出,再看看當前偵錯工具所在的目錄,就有相應的core檔案了

(2)在gdb中由於錯誤而停止的地方,在gdb中輸入generate-core-file,也就產生了對應的錯core檔案了。

 

關鍵步:

要退出了調試環境後,若想再次查看剛才的那個出錯資訊的話,那麼現在就是core檔案大現身手的時候了,使用gdb  debugfilename  core.*****

 

注意: debugfilename 必須和core.*****是一一對應的,才能夠看到出錯的資訊。core.****中的****是此程式在運行時的PID號。在偵錯工具運動中,可以通過top | pgrep debugfilename查看對應的PID號。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.