Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 如何正确使用gdb?_Multithreading_Debugging_Segmentation Fault_Gdb - Fatal编程技术网

Multithreading 如何正确使用gdb?

Multithreading 如何正确使用gdb?,multithreading,debugging,segmentation-fault,gdb,Multithreading,Debugging,Segmentation Fault,Gdb,我希望gdb只显示我的代码(跳过包含的标题)。我正在努力解决我的多线程程序随机抛出的分段错误。在gdb中,我可以看到: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffeffff700 (LWP 27533)] 0x0000000000409939 in std::thread::joinable (this=0x0) at /usr/include/c++/4.9.2/thread:

我希望gdb只显示我的代码(跳过包含的标题)。我正在努力解决我的多线程程序随机抛出的分段错误。在gdb中,我可以看到:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffeffff700 (LWP 27533)]
0x0000000000409939 in std::thread::joinable (this=0x0) at /usr/include/c++/4.9.2/thread:162
162     { return !(_M_id == id()); }
(gdb) bt
#0  0x0000000000409939 in std::thread::joinable (this=0x0) at /usr/include/c++/4.9.2/thread:162
#1  0x0000000000404562 in Finder::join_threads (this=0x7ffff0000cd0) at global_search.cpp:25
#2  0x0000000000416ea9 in std::_Mem_fn<void (Finder::*)()>::operator()<, void>(Finder&) const (this=0x7ffff00013c0, __object=...) at /usr/include/c++/4.9.2/functional:556
#3  0x0000000000416d1e in std::_Mem_fn<void (Finder::*)()>::operator()<Finder<>, void>(std::reference_wrapper<Finder<> >, (void&&)...) const (this=0x7ffff00013c0, __ref=...)
    at /usr/include/c++/4.9.2/functional:585
#4  0x00000000004166fe in std::_Bind_simple<std::_Mem_fn<void (Finder::*)()> (std::reference_wrapper<Finder>)>::_M_invoke<0ul>(std::_Index_tuple<0ul>) (this=0x7ffff00013b8)
    at /usr/include/c++/4.9.2/functional:1700
#5  0x00000000004160eb in std::_Bind_simple<std::_Mem_fn<void (Finder::*)()> (std::reference_wrapper<Finder>)>::operator()() (this=0x7ffff00013b8)
    at /usr/include/c++/4.9.2/functional:1688
#6  0x0000000000415b12 in std::thread::_Impl<std::_Bind_simple<std::_Mem_fn<void (Finder::*)()> (std::reference_wrapper<Finder>)> >::_M_run() (this=0x7ffff00013a0)
    at /usr/include/c++/4.9.2/thread:115
#7  0x00007ffff76b4d90 in execute_native_thread_routine () from /usr/lib/libstdc++.so.6
#8  0x00007ffff7910374 in start_thread () from /usr/lib/libpthread.so.0
#9  0x00007ffff6e2427d in clone () from /usr/lib/libc.so.6
程序接收信号SIGSEGV,分段故障。
[切换到线程0x7FFFEFF700(LWP 27533)]
std::thread::joinable(this=0x0)at/usr/include/c++/4.9.2/thread:162中的0x0000000000409939
162{return!(_M_id==id());}
(gdb)英国电信
#std::thread::joinable(this=0x0)at/usr/include/c++/4.9.2/thread:162中的0 0x0000000000409939
#查找器中的1 0x000000000040562::在全局搜索中加入线程(此=0x7ffff0000cd0)。cpp:25
#在/usr/include/c++/4.9.2/functional:556处的std:_Mem_fn::operator()(Finder&)const(this=0x7ffff00013c0,__对象=…)中的2 0x0000000000416ea9
#标准中的3 0x0000000000416d1e::_Mem_fn::operator()(标准::引用_包装,(无效和)…)常量(this=0x7ffff00013c0,_引用=…)
at/usr/include/c++/4.9.2/functional:585
#4 0x00000000004166fe在std::_Bind_simple:_M_invoke(std::_Index_tuple)(this=0x7ffff00013b8)
at/usr/include/c++/4.9.2/functional:1700
#std:_Bind_simple::operator()()(此值=0x7ffff00013b8)中的5 0x00000000004160eb
at/usr/include/c++/4.9.2/functional:1688
#std::thread::_Impl::_M_run()(this=0x7ffff00013a0)中的6 0x0000000000415b12
at/usr/include/c++/4.9.2/thread:115
#7 0x00007FF76B4D90,位于/usr/lib/libstdc++.so.6中的execute_native_thread_例程()中
#8 0x00007FF7910374位于/usr/lib/libpthread.so.0的start_线程()中
#来自/usr/lib/libc.so.6的克隆()中的9 0x00007ffff6e2427d

在我的代码中(不是在线程库中)什么时候发生了错误?或者至少是哪个对thread::joinable()函数的调用导致了错误?有可能得到这样的信息吗?我很抱歉问这样的问题,但我对使用gdb进行调试是完全陌生的。

这里有两种情况

有一个案例——您的问题中的一个——涉及堆栈跟踪。在这种情况下,根本无法消除来自程序外部的帧。我想gdb可以通过某种方式来实现这一点,比如说使用帧过滤器,但在实践中这会让人困惑,因为调试器随后会对正在调试的程序的当前状态提供一个伪造的视图

对于这种情况,我通常只使用“up”命令在堆栈中遍历,直到看到我感兴趣的东西

另一种情况是步进。对于这种情况,gdb提供了“skip”命令,该命令指示它不要单步执行特定的代码位。这可以方便地删除访问器和外来代码。请注意,这与从堆栈跟踪中删除信息的问题不同,因为gdb没有伪造任何信息,它只是将“步骤”和“下一步”视为较长操作的简写。

最内层(活动)堆栈帧是帧0,调用者是帧1,依此类推。从上到下看,我注意到frame#0位于名称空间
std
内的函数中,并将系统头文件作为源代码引用,但frame#1已经提到了名为
Finder
的类中的一个方法,该方法不是由标准库提供的,而且源代码路径也没有引用系统头文件。此外,快速谷歌搜索不会产生结果表明
Finder
类是知名框架的一部分,因此它很可能是您的代码

Finder::join_threads
在global_search.cpp第25行的std::thread指针上调用joinable,该指针是
nullptr
(又称
NULL