Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Waiting with a crash for a debugger?

When an assert fails or there is a segmentation fault, it would be very convenient that one of the following happens:

  • Program ask whether to run a debugger.
  • Program waits with crashing until debugger is attached.
  • Program leaves something (core dump?) that we can resume execution from this point and investigate.

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.

like image 852
Łukasz Lew Avatar asked Sep 23 '09 11:09

Łukasz Lew


3 Answers

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.

like image 170
gnud Avatar answered Nov 15 '22 16:11

gnud


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.

like image 2
sbi Avatar answered Nov 15 '22 16:11

sbi


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.

like image 1
Liran Orevi Avatar answered Nov 15 '22 17:11

Liran Orevi