aboutsummaryrefslogtreecommitdiff
path: root/src/common/stack_trace.cpp
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-01-15 20:31:16 -0500
committerRiccardo Spagni <ric@spagni.net>2017-01-15 20:31:16 -0500
commitac7df193ca47261c2dfd91b230489e20955013a2 (patch)
treee4d312059948a0528583e7ea58d2c0b40307a494 /src/common/stack_trace.cpp
parentMerge pull request #1578 (diff)
parentChange logging to easylogging++ (diff)
downloadmonero-ac7df193ca47261c2dfd91b230489e20955013a2.tar.xz
Merge pull request #1522
5833d66f Change logging to easylogging++ (moneromooo-monero) dc98019b easylogging++: fix logging with static const header only data members (moneromooo-monero) 3b46617b easylogging++: add ELPP_DISABLE_CHECK_MACROS (moneromooo-monero) 6fe39d90 easylogging++: allow clipping a common filename prefix (moneromooo-monero) 43abf6ff easylogging++: add file-only logs (moneromooo-monero) c313bea4 eayslogging++: Fix bad memory access before opening any files (moneromooo-monero) 0af5d168 easylogging++: avoid creating directory/filename for the builtin default log file (moneromooo-monero) 28362847 easylogging++: allow setting thread names (moneromooo-monero) ec71ce8d easylogging++: Print thread ID in a nicer way (moneromooo-monero) 2a0bf783 easylogging++: Add logging categories (moneromooo-monero) c50bbbfe easylogging++: import upstream (moneromooo-monero)
Diffstat (limited to 'src/common/stack_trace.cpp')
-rw-r--r--src/common/stack_trace.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/common/stack_trace.cpp b/src/common/stack_trace.cpp
index 5bbd3e252..ce05b7e04 100644
--- a/src/common/stack_trace.cpp
+++ b/src/common/stack_trace.cpp
@@ -35,6 +35,11 @@
#include <dlfcn.h>
#endif
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "stacktrace"
+
+#define ST_LOG(x) CERROR(el::base::Writer,el::base::DispatchAction::FileOnlyLog,MONERO_DEFAULT_LOG_CATEGORY) << x
+
// from http://stackoverflow.com/questions/11665829/how-can-i-print-stack-trace-for-caught-exceptions-in-c-code-injection-in-c
// The decl of __cxa_throw in /usr/include/.../cxxabi.h uses
@@ -103,34 +108,34 @@ void log_stack_trace(const char *msg)
const char *log = stack_trace_log.empty() ? NULL : stack_trace_log.c_str();
if (msg)
- LOG_PRINT2(log, msg, LOG_LEVEL_0);
- LOG_PRINT2(log, "Unwound call stack:", LOG_LEVEL_0);
+ ST_LOG(msg);
+ ST_LOG("Unwound call stack:");
if (unw_getcontext(&ctx) < 0) {
- LOG_PRINT2(log, "Failed to create unwind context", LOG_LEVEL_0);
+ ST_LOG("Failed to create unwind context");
return;
}
if (unw_init_local(&cur, &ctx) < 0) {
- LOG_PRINT2(log, "Failed to find the first unwind frame", LOG_LEVEL_0);
+ ST_LOG("Failed to find the first unwind frame");
return;
}
for (level = 1; level < 999; ++level) { // 999 for safety
int ret = unw_step(&cur);
if (ret < 0) {
- LOG_PRINT2(log, "Failed to find the next frame", LOG_LEVEL_0);
+ ST_LOG("Failed to find the next frame");
return;
}
if (ret == 0)
break;
if (unw_get_reg(&cur, UNW_REG_IP, &ip) < 0) {
- LOG_PRINT2(log, " " << std::setw(4) << level, LOG_LEVEL_0);
+ ST_LOG(" " << std::setw(4) << level);
continue;
}
if (unw_get_proc_name(&cur, sym, sizeof(sym), &off) < 0) {
- LOG_PRINT2(log, " " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip, LOG_LEVEL_0);
+ ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip);
continue;
}
dsym = abi::__cxa_demangle(sym, NULL, NULL, &status);
- LOG_PRINT2(log, " " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip << " " << (!status && dsym ? dsym : sym) << " + " << "0x" << off, LOG_LEVEL_0);
+ ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip << " " << (!status && dsym ? dsym : sym) << " + " << "0x" << off);
free(dsym);
}
}