From d060348df07424e0517184fb77bc8e57652bcd85 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 13 Jun 2022 13:48:37 -0600 Subject: [PATCH] main: add a SIGUSR1 handler to allow dynamic triggering of debug bits --- gtk2_ardour/main.cc | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc index 43faab8c11..7284a57871 100644 --- a/gtk2_ardour/main.cc +++ b/gtk2_ardour/main.cc @@ -173,6 +173,19 @@ Click OK to exit %1."), PROGRAM_NAME, AudioEngine::instance()->current_backend_n return false; /* do not call again */ } +#ifndef NDEBUG +static void +sigusr1_handler (int /* signal */) +{ + cerr << "SIGUSR1 received in thread " << pthread_name() << endl; + char const * adf = g_getenv ("ARDOUR_DEBUG_FLAGS"); + if (!adf) { + return; + } + PBD::parse_debug_options (adf); +} +#endif + #ifndef PLATFORM_WINDOWS static void sigpipe_handler (int /*signal*/) @@ -309,9 +322,11 @@ int main (int argc, char *argv[]) { #ifndef NDEBUG - const char *adf; + const char * adf; if ((adf = g_getenv ("ARDOUR_DEBUG_FLAGS"))) { - PBD::parse_debug_options (adf); + if (!g_getenv ("ARDOUR_DEBUG_ON_SIGUSR1")) { + PBD::parse_debug_options (adf); + } } #endif /* NDEBUG */ } @@ -402,6 +417,16 @@ int main (int argc, char *argv[]) } #endif +#ifndef NDEBUG + if (g_getenv ("ARDOUR_DEBUG_ON_SIGUSR1")) { + if (::signal (SIGUSR1, sigusr1_handler)) { + cerr << _("Cannot install SIGUSR1 error handler") << endl; + } else { + cerr << _("Installed SIGUSR1 debug handler") << endl; + } + } +#endif + DEBUG_TRACE (DEBUG::Locale, string_compose ("main() locale '%1'\n", setlocale (LC_NUMERIC, NULL))); if (UIConfiguration::instance().pre_gui_init ()) {