debug: register stack trace handler in set_terminate

This commit is contained in:
Danny Robson 2018-09-12 14:01:57 +10:00
parent 9ca093d982
commit a71ed6fe12

View File

@ -68,24 +68,29 @@ warn (const char *msg)
////////////////////////////////////////////////////////////////////////////////
#if defined(PLATFORM_WIN32)
// TODO: actually perform initialisation
void cruft::debug::init (void) { ; }
#endif
static void abort_with_info (void)
{
LOG_ALERT ("aborting: %!", debug::backtrace {});
#if !defined(PLATFORM_WIN32)
}
//-----------------------------------------------------------------------------
void
cruft::debug::init [[gnu::constructor]] (void)
{
if (debug_enabled || getenv("DEBUG")) {
LOG_INFO ("minimal debug setup");
//enable_fpe ();
force_console ();
prepare_debugger ();
std::set_terminate (abort_with_info);
if (getenv ("DEBUG_WAIT"))
await_debugger ();
}
if (!debug_enabled && !getenv ("DEBUG"))
return;
LOG_DEBUG ("setting debug environment");
//enable_fpe ();
force_console ();
prepare_debugger ();
if (getenv ("DEBUG_WAIT"))
await_debugger ();
}
@ -100,7 +105,6 @@ debug_wait [[gnu::constructor]] (void)
await_debugger ();
}
}
#endif
///////////////////////////////////////////////////////////////////////////////