debug: enable debugging features by default

This commit is contained in:
Danny Robson 2018-03-27 15:50:29 +11:00
parent 1b023f7c8d
commit 67c8c9c69c
2 changed files with 15 additions and 8 deletions

View File

@ -76,20 +76,27 @@ warn (const char *msg)
////////////////////////////////////////////////////////////////////////////////
void
util::debug::init (void)
util::debug::init [[gnu::constructor]] (void)
{
if (debug_enabled || getenv("DEBUG")) {
LOG_INFO ("minimal debug setup");
enable_fpe ();
force_console ();
prepare_debugger ();
if (getenv ("DEBUG_WAIT"))
await_debugger ();
}
}
///////////////////////////////////////////////////////////////////////////////
static void
debug_wait [[gnu::constructor]] (void) {
debug_wait [[gnu::constructor]] (void)
{
if (auto val = getenv ("DEBUG_WAIT")) {
LOG_NOTICE ("awaiting debugger");
if (std::string ("0") != val)
await_debugger ();
}

View File

@ -102,7 +102,7 @@ await_debugger (void)
void
enable_fpe (void)
{
feenableexcept (FE_DIVBYZERO | FE_INVALID);
feenableexcept (FE_INVALID);
}
@ -118,7 +118,7 @@ disable_fpe (void)
void
force_console (void)
{
if (!isatty (fileno (stdout))) {
if (!isatty (fileno (stdout) && !isatty (fileno (stderr)))) {
LOG_WARN ("expected debugging under a console");
}
}