在gdb中如何將所有線程的堆棧輸出到檔案中去

來源:互聯網
上載者:User

1.先在gdb中設定log檔案的位置,同時開啟log

2.使用 thread apply all bt輸出所有的堆棧

例子:

下面是gdb attach到httpd後的堆棧

(gdb) set logging file /tmp/test.txt(gdb) set logging onCopying output to /tmp/test.txt.(gdb) thread apply all btThread 2 (Thread 0x41ec5940 (LWP 7312)):#0  0x00002b6370d241c0 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0#1  0x00002aaab3bbf229 in ?? () from /usr/lib64/libnspr4.so#2  0x00002aaab3bbfe69 in PR_WaitCondVar () from /usr/lib64/libnspr4.so#3  0x00002aaab3bc51bc in PR_Sleep () from /usr/lib64/libnspr4.so#4  0x00002aaab302750e in ?? () from /usr/lib64/libssl3.so#5  0x00002aaab3bc55cd in ?? () from /usr/lib64/libnspr4.so#6  0x00002b6370d1f77d in start_thread (arg=<value optimized out>) at pthread_create.c:301#7  0x00002b637120d9ad in clone () from /lib64/libc.so.6Thread 1 (Thread 0x2b63731b4360 (LWP 4718)):#0  0x00002b6371206b42 in select () from /lib64/libc.so.6#1  0x00002b6370b10d25 in apr_sleep () from /usr/lib64/libapr-1.so.0#2  0x00002b636f242315 in ap_wait_or_timeout ()#3  0x00002b636f24b79e in ap_mpm_run ()#4  0x00002b636f225fd8 in main ()

然後在/tmp/test.txt中可以自由的尋找了。

refs:

http://stackoverflow.com/questions/18391808/getting-the-backtrace-for-all-the-threads-in-gdb

http://www.delorie.com/gnu/docs/gdb/gdb_25.html

http://stackoverflow.com/questions/1707167/how-extract-text-from-gdb


下面這個串連有其它的debug技巧,比如如何debug X Error,


https://wiki.debian.org/HowToGetABacktrace


聯繫我們

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