开发者

My program crashes in boost::thread::thread_start_function, how can I debug

开发者 https://www.devze.com 2023-02-12 19:56 出处:网络
I\'ve build C++ program using Visual Studio 2008. Both release and debug version are crashing at random times. The frequency of the crashes depends on the machine it runs on (from once a week to every

I've build C++ program using Visual Studio 2008. Both release and debug version are crashing at random times. The frequency of the crashes depends on the machine it runs on (from once a week to every hour).

The program uses boost asio for TCP communication as well as wxWidget for UI. Nevertheless the crashes are not related to any TCP issue or UI interaction as it mostly happens when the program is idle.

Here is the call stack I have when it crashes:

msvcr90d.dll!_NMSG_WRITE(int rterrnum=10)  Line 198 C
msvcr90d.dll!abort()  Line 59 + 0x7 bytes   C
msvcr90d.dll!terminate()  Line 130  C++
enf_client.exe!boost::thread::thread_start_function(void * param=0x00161e60)  Line 184  C++
msvcr90d.dll!_callthreadstartex()  Line 348 + 0xf bytes C
msvcr90d.dll!_threadstartex(void * ptd=0x01385d28)  Line 331    C
kernel32.dll!7c80b729()     
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll

I am clueless as on how to debug thi开发者_高级运维s thing. If you have any idea of where to look for, that would be great.

EDIT

I have noticed this in my debug trace, just before the crash:

First-chance exception at 0x7c812afb in enf_client.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0189efd4..

I can not work out what is in memory at this address (looks like a lot of junk):

L.H............. ð..0.=..zH. ð...ð.......

Which functions can trigger this, beside the at function of stl containers ?


The fact that terminate() is in your call stack leads me to believe a pure virtual function is being called. It's relatively easy to provoke this with the following scenario:

  • Base class representing a thread, starts the thread in ctor. The "execute" function is pure virtual
  • Subclass implementing the "execute" function.

Now and then, the thread started from Base ctor will start running before Base ctor is completely done. The object execute is called on is therefore not completely constructed, and Base's execute is called, causing a terminate()

Such a now-and-then terminate() could be caused by several other scenarios, I'd suggest you experiment with provoking it by sleeping immediately after the call that actually creates your thread.


Have you tried setting the debugger to break when the exception is thrown? (Debug Menu -> Exceptions -> C++ exceptions -> Check the box for std::exception.)


Without seeing any code it will be hard to tell you what the problem might be.

I would do following:

It seems that terminate() is called inside boost::thread::thread_start_function in the catch block. Under Windows I would call DebugBreak() before std::terminate() and start the application (of course you have to run the debug version). When the error occurs again DebugBreak will start your Debugger and wait at that point. From there you can analyze the stacktrace and check who has started this thread and check what happens inside.


Considering I had a std::out_of_range, I looked at all my call to the at function.

And here it was:

std::string temp; ... ; if (temp.size() >= 8) temp.at(8) = '0'

Which should have been: if (temp.size() >= 9) temp.at(8) = '0'

I still don't understand why I did not have more debug information on this exception, in debug mode. It may be because it was on the UI thread, managed by wxWidget.

0

精彩评论

暂无评论...
验证码 换一张
取 消