Search code examples
c++visual-studioboost-thread

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


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 this 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 ?


Solution

  • 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.