From 67c8c9c69c020fe978e9eb49fb2bd6ead295aad6 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 27 Mar 2018 15:50:29 +1100 Subject: [PATCH] debug: enable debugging features by default --- debug.cpp | 19 +++++++++++++------ debug_posix.cpp | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/debug.cpp b/debug.cpp index 31847bdb..31640e45 100644 --- a/debug.cpp +++ b/debug.cpp @@ -76,20 +76,27 @@ warn (const char *msg) //////////////////////////////////////////////////////////////////////////////// void -util::debug::init (void) +util::debug::init [[gnu::constructor]] (void) { - force_console (); - prepare_debugger (); + if (debug_enabled || getenv("DEBUG")) { + LOG_INFO ("minimal debug setup"); + enable_fpe (); + force_console (); + prepare_debugger (); - if (getenv ("DEBUG_WAIT")) - await_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 (); } diff --git a/debug_posix.cpp b/debug_posix.cpp index 93db5332..a3af05a8 100644 --- a/debug_posix.cpp +++ b/debug_posix.cpp @@ -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"); } }