Reputation: 50298
When an assert fails or there is a segmentation fault, it would be very convenient that one of the following happens:
The question is quite general due to variety of platforms, languages and debuggers. I'm asking about C++ and I guess that Windows (VS), Linux (gdb), Mac (gdb?) solutions would be most useful for community. I'm interested in Linux + gdb.
Upvotes: 5
Views: 1106
Reputation: 298
I've implemented such a functionality as a LD_PRELOAD
able library in https://github.com/l29ah/waitgdb
Basically it handles debug-worthy signals and stops the process sending it SIGSTOP
so you can attach your debugger later.
Upvotes: 0
Reputation: 7448
Additionally to ulimit suggested by gnud, it could be a good idea to use a crash reporter: http://code.google.com/p/google-breakpad/w/list
Upvotes: 0
Reputation: 224079
On Windows there is DebugBreak()
(and IsDebuggerPresent()
), which is one of the options of what can happen when an assert
fails.
On MacOS there are similar API calls (Debugger()
or SysBreak()
).
I don't know much about Linux, but AFAIK a failed assertion on Linux will cause a coredump, which can be looked at in the debugger.
Upvotes: 2
Reputation: 6827
Unfortunately, my response only extends to Windows but it would make sense that Linux would also have some way to signal a debugger.
Any machine with Visual Studio installed on it should have Just in Time debugging enabled. This essentially means that the debugger does not have to be running when a process encounters a fatal exception.
Just in Time debugging is enabled through a registry key. Check out the link above for additional details.
If your looking to capture a process snap, for review later, then this is generally accomplished via Adplus.vbs (attended) or DebugDiag (unattended). Adplus is available through the Debugging Toolkit for Windows, but DebugDiag is a separate download.
Upvotes: 1
Reputation: 4903
On Linux, Basically when something horrible happens, your program receives a signal, There is a default behavior for the program if you do not 'mask' this signal, but you can usually 'mask' it to do something else, such as opening the gdb. You can find how to mask and a lot more from here, specifically here.
Regarding the assert, you can easily create your own version of assert, to do whatever you want.
Upvotes: 1