[轉] GDB attach

來源:互聯網
上載者:User

標籤:

轉:http://blog.csdn.net/wangeen/article/details/14230171

attach是GDB一種重要的debug模式,在MPI程式debug中發揮重要的作用。

具體的執行步驟如下:

1) 首先在程式開始的地方添加如下代碼, 注意這是個死迴圈,之所以用死迴圈就是讓他一直在等待attch

{    int i = 0;    char hostname[256];    gethostname(hostname, sizeof(hostname));    printf("PID %d on %s ready for attach\n", getpid(), hostname);    fflush(stdout);    while (0 == i)        sleep(5);}

啟動程式會得到如下語句

PID 15425 on XXX ready for attach

PID 15426 on XXX ready for attach


2) 啟動GDB

$gdb

(gdb) attach 15425

(gdb) up      // 這裡的up非常重要,見misc

(gdb) set var i=1

這樣跳出死迴圈,繼續執行。


3) misc 

 

關於GDB的使用

過去我們總覺得GDB很難用,很多debug資訊都沒有能顯示出來,尤其是在多線程的情況下,我在使用gdb attach MPI 程式的時候找到了其中的原因,因為gdb總是不停的在嘗試暫停程式抓取stack中的內容到frame,如果遇到sleep之類的情況,gdb就擷取不到任何資訊,在這樣的情況下我們需要使用up down來切換frame。

[轉] GDB attach

聯繫我們

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