gdb來調式多線程

來源:互聯網
上載者:User

gdb來調式多線程, 真的不怎麼好用, 不知道怎麼讓一個線程逐步執行, 在當前調式的總只有一個線程.
在調式當前線程的時候其它線程就一直在運行, 不好控制. 自己也很不喜歡多線程調式, 通常都是將多線程程式想辦法轉換為單線程來調式,
把每個函數調式成功了再一起來運行. 在不就使用原始的print大法了.

------------------
下面來源: http://book.77169.org/ask30/how210438.htm

要點是先運行程式,再attach線程號進行調試。
1。先運行你的主程式
2。使用ps查看你程式的線程號,或者線上程程式裡列印出來
3。運行gdb,運行“attach 線程號”
4。info stack看運行到哪裡了,設線程檔案中的斷點
5。跟蹤調試
6。“detach 線程號”取消調試該線程

我試過,成敗基本對半開。
------------------

怎麼查看線程號:
To get info about threads:
   ps -eLf
   ps axms

When used with -L, the NLWP (number of threads) and LWP (thread ID)

------------------
core檔案怎麼產生:
[gan@localhost tmp]$ ulimit -a
core file size          (blocks, -c) 0
...
[gan@localhost tmp]$ ulimit -c unlimited
[gan@localhost tmp]$ ulimit -a
core file size          (blocks, -c) unlimited
...
[gan@localhost tmp]$ ./a.out
段錯誤 (core dumped)

在目前的目錄下就產生core.[pid]的core檔案了.

-------------------
還需要注意: gcc -g 參數就可以使用gdb調式了,但如果就只給你一個執行檔案, 調式也是沒有辦法的. 今天剛測試完把別人的機器上的該執行檔案拿到自己機器上gdb, 原來gdb需要訪問原檔案.c檔案來顯示詳細的代碼資訊的.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.