13
0

Print stacktrace when plugin-scanner app crashes

This commit is contained in:
Robin Gareus 2021-07-12 04:00:43 +02:00
parent 7d39205350
commit 6af9b0194e
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 83 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include <cstdio> #include <cstdio>
#include <getopt.h> #include <getopt.h>
#include <iostream> #include <iostream>
#include <signal.h>
#include <string> #include <string>
#include <strings.h> #include <strings.h>
@ -28,6 +29,7 @@
#include "pbd/transmitter.h" #include "pbd/transmitter.h"
#include "pbd/receiver.h" #include "pbd/receiver.h"
#include "pbd/pbd.h" #include "pbd/pbd.h"
#include "pbd/stacktrace.h"
using namespace std; using namespace std;
@ -94,6 +96,14 @@ scan_auv2 (CAComponentDescription& desc, bool force, bool verbose)
return true; 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 static void
usage () usage ()
{ {
@ -186,6 +196,11 @@ main (int argc, char **argv)
verbose = false; verbose = false;
} }
signal (SIGSEGV, sig_handler);
signal (SIGBUS, sig_handler);
signal (SIGILL, sig_handler);
#endif
bool err = false; bool err = false;
CFStringRef s_type = CFStringCreateWithCString (kCFAllocatorDefault, argv[optind++], kCFStringEncodingUTF8); CFStringRef s_type = CFStringCreateWithCString (kCFAllocatorDefault, argv[optind++], kCFStringEncodingUTF8);

View File

@ -23,6 +23,12 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#ifdef PLATFORM_WINDOWS
#include <windows.h>
#else
#include <signal.h>
#endif
#ifdef COMPILER_MSVC #ifdef COMPILER_MSVC
#include <sys/utime.h> #include <sys/utime.h>
#else #else
@ -38,6 +44,7 @@
#include "pbd/transmitter.h" #include "pbd/transmitter.h"
#include "pbd/receiver.h" #include "pbd/receiver.h"
#include "pbd/pbd.h" #include "pbd/pbd.h"
#include "pbd/stacktrace.h"
#include "pbd/win_console.h" #include "pbd/win_console.h"
#include "pbd/xml++.h" #include "pbd/xml++.h"
@ -123,6 +130,25 @@ scan_vst2 (std::string const& path, ARDOUR::PluginType type, bool force, bool ve
return true; 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 static void
usage () usage ()
{ {
@ -224,6 +250,14 @@ main (int argc, char **argv)
bool err = false; 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) { while (optind < argc) {
const char* dllpath = argv[optind++]; const char* dllpath = argv[optind++];
const size_t slen = strlen (dllpath); const size_t slen = strlen (dllpath);

View File

@ -22,6 +22,12 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#ifdef PLATFORM_WINDOWS
#include <windows.h>
#else
#include <signal.h>
#endif
#ifdef COMPILER_MSVC #ifdef COMPILER_MSVC
#include <sys/utime.h> #include <sys/utime.h>
#else #else
@ -32,6 +38,7 @@
#include "pbd/transmitter.h" #include "pbd/transmitter.h"
#include "pbd/receiver.h" #include "pbd/receiver.h"
#include "pbd/pbd.h" #include "pbd/pbd.h"
#include "pbd/stacktrace.h"
#include "pbd/win_console.h" #include "pbd/win_console.h"
#include "pbd/xml++.h" #include "pbd/xml++.h"
@ -110,6 +117,25 @@ scan_vst3 (std::string const& bundle_path, bool force, bool verbose)
return true; 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 static void
usage () usage ()
{ {
@ -209,6 +235,14 @@ main (int argc, char **argv)
verbose = false; 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; bool err = false;
while (optind < argc) { while (optind < argc) {