aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2018-04-21 21:55:01 +0200
committerRiccardo Spagni <ric@spagni.net>2018-04-21 21:55:02 +0200
commite6cf9c06fc63c6d4cbcfee5633a990e8fbd76ed1 (patch)
treea9c8b3f244d2e26733f38385d79b11e2152b6d2c /src
parentMerge pull request #3672 (diff)
parentutil: log stack trace on crash (diff)
downloadmonero-e6cf9c06fc63c6d4cbcfee5633a990e8fbd76ed1.tar.xz
Merge pull request #3624
d8584fc8 util: log stack trace on crash (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r--src/common/util.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/common/util.cpp b/src/common/util.cpp
index 1877acb57..7e77e19b1 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -43,6 +43,7 @@ using namespace epee;
#include "crypto/crypto.h"
#include "util.h"
+#include "stack_trace.h"
#include "memwipe.h"
#include "cryptonote_config.h"
#include "net/http_client.h" // epee::net_utils::...
@@ -560,10 +561,48 @@ std::string get_nix_version_display_string()
}
return false;
}
+
+#ifdef STACK_TRACE
+#ifdef _WIN32
+ // https://stackoverflow.com/questions/1992816/how-to-handle-seg-faults-under-windows
+ static LONG WINAPI windows_crash_handler(PEXCEPTION_POINTERS pExceptionInfo)
+ {
+ tools::log_stack_trace("crashing");
+ exit(1);
+ return EXCEPTION_CONTINUE_SEARCH;
+ }
+ static void setup_crash_dump()
+ {
+ SetUnhandledExceptionFilter(windows_crash_handler);
+ }
+#else
+ static void posix_crash_handler(int signal)
+ {
+ tools::log_stack_trace(("crashing with fatal signal " + std::to_string(signal)).c_str());
+#ifdef NDEBUG
+ _exit(1);
+#else
+ abort();
+#endif
+ }
+ static void setup_crash_dump()
+ {
+ signal(SIGSEGV, posix_crash_handler);
+ signal(SIGBUS, posix_crash_handler);
+ signal(SIGILL, posix_crash_handler);
+ signal(SIGFPE, posix_crash_handler);
+ }
+#endif
+#else
+ static void setup_crash_dump() {}
+#endif
+
bool on_startup()
{
mlog_configure("", true);
+ setup_crash_dump();
+
sanitize_locale();
#ifdef __GLIBC__