Browse Source

Add fatal signal handling on Mac, with better stability in the handler function.

tags/v1.1.2
Andrew Belt 5 years ago
parent
commit
7a86e4cc7c
2 changed files with 15 additions and 11 deletions
  1. +10
    -10
      src/main.cpp
  2. +5
    -1
      src/system.cpp

+ 10
- 10
src/main.cpp View File

@@ -30,18 +30,19 @@ using namespace rack;


static void fatalSignalHandler(int sig) {
// Only catch one signal
static bool caught = false;
bool localCaught = caught;
caught = true;
if (localCaught)
exit(1);
// Ignore this signal to avoid recursion.
signal(sig, NULL);
// Ignore abort() since we call it below.
signal(SIGABRT, NULL);

FATAL("Fatal signal %d. Stack trace:\n%s", sig, system::getStackTrace().c_str());

osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "Rack has crashed. See log.txt for details.");
// This might fail because we might not be in the main thread.
// But oh well, we're crashing anyway.
std::string text = app::APP_NAME + " has crashed. See log.txt for details.";
osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, text.c_str());

exit(1);
abort();
}


@@ -97,8 +98,7 @@ int main(int argc, char *argv[]) {
logger::init();

// We can now install a signal handler and log the output
// Mac has its own decent crash handler
#if defined ARCH_LIN
#if defined ARCH_LIN || defined ARCH_MAC
if (!settings::devMode) {
signal(SIGABRT, fatalSignalHandler);
signal(SIGFPE, fatalSignalHandler);


+ 5
- 1
src/system.cpp View File

@@ -171,10 +171,11 @@ std::string getStackTrace() {
// Skip the first line because it's this function.
for (int i = 1; i < stackLen; i++) {
s += string::f("%d: ", stackLen - i - 1);
std::string line = strings[i];
#if 0
// Parse line
std::regex r(R"((.*)\((.*)\+(.*)\) (.*))");
std::smatch match;
std::string line = strings[i];
if (std::regex_search(line, match, r)) {
s += match[1].str();
s += "(";
@@ -190,6 +191,9 @@ std::string getStackTrace() {
s += match[3].str();
s += ")";
}
#else
s += line;
#endif
s += "\n";
}
free(strings);


Loading…
Cancel
Save