Question

I am debugging an application and for some reason (which I'm not quite sure), when closing my application abort() is called. I'd like to try and find the reason for this, so I want to place a breakpoint on abort() so I can see the stack trace and hopefully discover the reason it was called instead of a graceful exit.

I am using Microsoft Visual Studio 2012 (Update 3) and only have the declaration for the abort() function (in stdlib.h) and so I can't set a breakpoint. Is there any way to get around this?

Was it helpful?

Solution

You don't need to do anything special. abort call from C/C++ program built by Visual Studio produces the following message:

---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Error!
Program: ...
R6010
- abort() has been called
(Press Retry to debug the application)
---------------------------
Abort   Retry   Ignore   
---------------------------

Pressing Retry opens debugger with full call stack. This functionality is available both for Debug and Release configurations, when program runs in standalone mode and under debugger. In Release configuration the dialog is different, it contains Break button, which opens debugger, like Retry in Debug configuration.

OTHER TIPS

I had the same problem and found this answer which works for me: Press CTRL+B and enter 'abort' in the text field.

Just for debug, you may overrides abort function and set a breakpoint inside.

void abort()
{
    std::cout << "aborting" << std::endl; // put break here...
    exit(-1);
}

In case of linux gdb, upon hitting abort, you could see easily stack trace with command bt. No need to add extra break point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top