mirror of
https://github.com/monero-project/monero.git
synced 2024-12-13 20:06:32 +02:00
util: log stack trace on crash
This commit is contained in:
parent
1f96755ddc
commit
d8584fc8d7
@ -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__
|
||||
|
Loading…
Reference in New Issue
Block a user