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.
On Linux (and probably OSX and other unixen), you can allow programs to leave a coredump with the ulimit
utility.
Here's a quick howto.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With