Skip to content

Commit

Permalink
Print stacktrace when plugin-scanner app crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
x42 committed Jul 12, 2021
1 parent 7d39205 commit 6af9b01
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libs/auscan/au-scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
#include <cstdio>
#include <getopt.h>
#include <iostream>
#include <signal.h>
#include <string>
#include <strings.h>

#include "pbd/error.h"
#include "pbd/transmitter.h"
#include "pbd/receiver.h"
#include "pbd/pbd.h"
#include "pbd/stacktrace.h"

using namespace std;

Expand Down Expand Up @@ -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 ()
{
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 34 additions & 0 deletions libs/fst/vst2-scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
#include <iostream>
#include <string>

#ifdef PLATFORM_WINDOWS
#include <windows.h>
#else
#include <signal.h>
#endif

#ifdef COMPILER_MSVC
#include <sys/utime.h>
#else
Expand All @@ -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"

Expand Down Expand Up @@ -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 ()
{
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 34 additions & 0 deletions libs/fst/vst3-scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
#include <iostream>
#include <string>

#ifdef PLATFORM_WINDOWS
#include <windows.h>
#else
#include <signal.h>
#endif

#ifdef COMPILER_MSVC
#include <sys/utime.h>
#else
Expand All @@ -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"

Expand Down Expand Up @@ -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 ()
{
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6af9b01

Please sign in to comment.