diff --git a/libs/auscan/au-scanner.cc b/libs/auscan/au-scanner.cc index 2abec55c14..42f5427c1a 100644 --- a/libs/auscan/au-scanner.cc +++ b/libs/auscan/au-scanner.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -28,6 +29,7 @@ #include "pbd/transmitter.h" #include "pbd/receiver.h" #include "pbd/pbd.h" +#include "pbd/stacktrace.h" using namespace std; @@ -94,6 +96,14 @@ scan_auv2 (CAComponentDescription& desc, bool force, bool verbose) return true; } +static void +sig_handler (int sig) +{ + fprintf (stderr, "Error: signal %d\n", sig); + PBD::stacktrace (cerr, 15, 2); + ::exit (EXIT_FAILURE); +} + static void usage () { @@ -186,6 +196,11 @@ main (int argc, char **argv) verbose = false; } + signal (SIGSEGV, sig_handler); + signal (SIGBUS, sig_handler); + signal (SIGILL, sig_handler); + +#endif bool err = false; CFStringRef s_type = CFStringCreateWithCString (kCFAllocatorDefault, argv[optind++], kCFStringEncodingUTF8); diff --git a/libs/fst/vst2-scanner.cc b/libs/fst/vst2-scanner.cc index ce0b59521e..bf0f387d4f 100644 --- a/libs/fst/vst2-scanner.cc +++ b/libs/fst/vst2-scanner.cc @@ -23,6 +23,12 @@ #include #include +#ifdef PLATFORM_WINDOWS +#include +#else +#include +#endif + #ifdef COMPILER_MSVC #include #else @@ -38,6 +44,7 @@ #include "pbd/transmitter.h" #include "pbd/receiver.h" #include "pbd/pbd.h" +#include "pbd/stacktrace.h" #include "pbd/win_console.h" #include "pbd/xml++.h" @@ -123,6 +130,25 @@ scan_vst2 (std::string const& path, ARDOUR::PluginType type, bool force, bool ve return true; } +#ifdef PLATFORM_WINDOWS +static LONG WINAPI +crash_handler (EXCEPTION_POINTERS* exception_info) +{ + // TODO consider DrMingw if HAVE_DRMINGW + fprintf (stderr, "Error: %x\n", exception_info->ExceptionRecord->ExceptionCode); + PBD::stacktrace (cerr, 15, 2); + return EXCEPTION_CONTINUE_SEARCH; +} +#else +static void +sig_handler (int sig) +{ + fprintf (stderr, "Error: signal %d\n", sig); + PBD::stacktrace (cerr, 15, 2); + ::exit (EXIT_FAILURE); +} +#endif + static void usage () { @@ -224,6 +250,14 @@ main (int argc, char **argv) bool err = false; +#ifdef PLATFORM_WINDOWS + ::SetUnhandledExceptionFilter (crash_handler); +#else + signal (SIGSEGV, sig_handler); + signal (SIGBUS, sig_handler); + signal (SIGILL, sig_handler); +#endif + while (optind < argc) { const char* dllpath = argv[optind++]; const size_t slen = strlen (dllpath); diff --git a/libs/fst/vst3-scanner.cc b/libs/fst/vst3-scanner.cc index 8181b4a391..09f27fadea 100644 --- a/libs/fst/vst3-scanner.cc +++ b/libs/fst/vst3-scanner.cc @@ -22,6 +22,12 @@ #include #include +#ifdef PLATFORM_WINDOWS +#include +#else +#include +#endif + #ifdef COMPILER_MSVC #include #else @@ -32,6 +38,7 @@ #include "pbd/transmitter.h" #include "pbd/receiver.h" #include "pbd/pbd.h" +#include "pbd/stacktrace.h" #include "pbd/win_console.h" #include "pbd/xml++.h" @@ -110,6 +117,25 @@ scan_vst3 (std::string const& bundle_path, bool force, bool verbose) return true; } +#ifdef PLATFORM_WINDOWS +static LONG WINAPI +crash_handler (EXCEPTION_POINTERS* exception_info) +{ + // TODO consider DrMingw if HAVE_DRMINGW + fprintf (stderr, "Error: %x\n", exception_info->ExceptionRecord->ExceptionCode); + PBD::stacktrace (cerr, 15, 2); + return EXCEPTION_CONTINUE_SEARCH; +} +#else +static void +sig_handler (int sig) +{ + fprintf (stderr, "Error: signal %d\n", sig); + PBD::stacktrace (cerr, 15, 2); + ::exit (EXIT_FAILURE); +} +#endif + static void usage () { @@ -209,6 +235,14 @@ main (int argc, char **argv) verbose = false; } +#ifdef PLATFORM_WINDOWS + ::SetUnhandledExceptionFilter (crash_handler); +#else + signal (SIGSEGV, sig_handler); + signal (SIGBUS, sig_handler); + signal (SIGILL, sig_handler); +#endif + bool err = false; while (optind < argc) {