2015-10-05 118 views
0

我的应用程序在停止时遇到了崩溃。 GDB显示下面的堆栈(应用程序是建立与-g -O0):线程的奇怪堆栈

(gdb) bt 
#0 0x0000000000000000 in ??() 
#1 0x00007f254ea99700 in ??() 
#2 0x0000000000000000 in ??() 

短调查显示停止相应地开始以同样的方式一个线程过程中崩溃发生许多其他的应用程序:

// mListener is std::thread and member of class UA 
std::thread thr(&UA::run, this); 
mListener = std::move(thr); 

然后我在停止之前在应用程序上运行gdb,并看到线程堆栈导致崩溃和其他线程之间的差异。 所有线程的样子:

... 
#8 0x000000000043a70a in std::thread::_Impl<std::_Bind_simple<std::_Mem_fn<void (UI::Keyboard::*)()> (UI::Keyboard*)> >::_M_run() (this=0xa88fd0) 
    at /usr/include/c++/4.9/thread:115 
#9 0x00007fb6055c3970 in ??() from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 
#10 0x00007fb6083ff0a4 in start_thread (arg=0x7fb604042700) at pthread_create.c:309 
#11 0x00007fb604d3304d in clone() at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111 

但“错误”的线程总是看起来不一样:

#0 sem_wait() at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S:85 
#1 0x000000000043317d in Semaphore::wait (this=0x7fb5fc0009e8) at /home/vadius/workspace/iPhone/core/src/Core/env/Semaphore.h:28 
#2 0x0000000000432564 in SIP::UA::run (this=0x7fb5fc000980) at /home/vadius/workspace/iPhone/core/src/SIP/UA.cpp:132 
#3 0x0000000000000000 in ??() 

我认为当工人从法(SIP::UA::run)线程退出它进入的代码放在nullptr。 我的问题是: 1.我的权利和'坏'线程堆栈是错误的? 2.什么可能是这种行为的原因,以及如何避免它?

Debian的杰西X64/ GCC 4.9/ 编译标志:set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DDEBUG -g -O0")

+0

它看起来不对我。可能你的代码已经损坏了它。 – torvin

回答

1

的赠品是 “地址”。 432564"C%d"。正常地址中的字节通常不是全部ASCII。这是一个堆栈缓冲区溢出。

+0

你是我的救助者。非常感谢你。 –