2013-05-26 100 views
3

全部使用GDB調試多線程程序(openmp)

我打算在Fedora中使用gdb調試24個線程的程序,並且我有以下GDB輸出。當我想切換到發生分段錯誤的特定線程時,我無法使用線程命令(GDB輸出中的最後4行)切換到該線程。你能幫我一下嗎?你知道它是什麼錯誤嗎? GDB輸出如下:

[[email protected] nameComponentEncoding]# gdb NCE_david 
GNU gdb (GDB) Fedora (7.2.90.20110429-36.fc15) 
Copyright (C) 2011 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. Type "show copying" 
and "show warranty" for details. 
This GDB was configured as "x86_64-redhat-linux-gnu". 
For bug reporting instructions, please see: 
<http://www.gnu.org/software/gdb/bugs/>... 
Reading symbols from /mnt/disk2/experiments_BLOODMOON/two_stage_bloom_filter/programs/nameComponentEncoding/NCE_david 
(gdb) r 
Starting program: 
[Thread debugging using libthread_db enabled] 

[New Thread 0x7fffd2bf5700 (LWP 11538)] 
[New Thread 0x7fffd23f4700 (LWP 11539)] 
[New Thread 0x7fffd1bf3700 (LWP 11540)] 
[New Thread 0x7fffd13f2700 (LWP 11541)] 
[New Thread 0x7fffd0bf1700 (LWP 11542)] 
[New Thread 0x7fffd03f0700 (LWP 11543)] 
[New Thread 0x7fffcfbef700 (LWP 11544)] 
[New Thread 0x7fffcf3ee700 (LWP 11545)] 
[New Thread 0x7fffcebed700 (LWP 11546)] 
[New Thread 0x7fffce3ec700 (LWP 11547)] 
[New Thread 0x7fffcdbeb700 (LWP 11548)] 
[New Thread 0x7fffcd3ea700 (LWP 11549)] 
[New Thread 0x7fffccbe9700 (LWP 11550)] 
[New Thread 0x7fffcc3e8700 (LWP 11551)] 
[New Thread 0x7fffcbbe7700 (LWP 11552)] 
[New Thread 0x7fffcb3e6700 (LWP 11553)] 
[New Thread 0x7fffcabe5700 (LWP 11554)] 
[New Thread 0x7fffca3e4700 (LWP 11555)] 
[New Thread 0x7fffc9be3700 (LWP 11556)] 
[New Thread 0x7fffc93e2700 (LWP 11557)] 
[New Thread 0x7fffc8be1700 (LWP 11558)] 
[New Thread 0x7fffc83e0700 (LWP 11559)] 
[New Thread 0x7fffc7bdf700 (LWP 11560)] 

Program received signal SIGSEGV, Segmentation fault. 
[Switching to Thread 0x7fffd2bf5700 (LWP 11538)] 
compare (__str="art", this=0xbf934d0) at /usr/lib/gcc/x86_64-redhat-linux/4.6.0/ 
2175   const size_type __size = this->size(); 
(gdb) thread 11538 
Thread ID 11538 not known. 
(gdb) thread 0x7fffd2bf5700 
Thread ID -759212288 not known. 

回答

5

GDB有自己的線程編號。這樣做:

(gdb) info threads 

    Id Target Id   Frame 
    <... snip ...> 
    2 Thread 0x7ffff7fc1700 (LWP 11538) ... 
* 1 Thread 0x7ffff7fc2740 (LWP 11537) ... 
# thread with PID 11538 is GDB thread number 2 
(gdb) thread 2 

Program received signal SIGSEGV, Segmentation fault. 
[Switching to Thread 0x7fffd2bf5700 (LWP 11538)] 
compare (__str="art", this=0xbf934d0) at /usr/lib/gcc/x86_64-redhat-linux/4.6.0/ 
2175   const size_type __size = this->size(); 

它似乎是段錯誤是由線程11538.造成使用pthread_setname_np()來命名你的線程會使調試在GDB容易。

我的猜測是,this,C++實例變量,在那一點上是空的(很容易驗證),你的情況是一個「免費使用後」的錯誤。

+0

是的,它的工作原理。你認爲分段錯誤發生在該線程11538上嗎? – Bloodmoon

+0

@血月,是的。我已經修改了我的答案。 – scottt

+0

非常感謝。我是GDB的新手,在切換到線程後,我不知道下一步該怎麼做。我不知道應該在哪裏添加斷點......我是否應該推斷'compare()'函數的調用位置,並在那裏添加斷點? – Bloodmoon