aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-02-04 12:33:03 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-02-04 12:33:03 +0000
commitcd34fc655d5bf4ed5d9425222b78a771b7a55294 (patch)
tree1192907b0dee5ecea635d63ccbcf8cd5d2ca75e3 /src/common
parentMerge pull request #1663 (diff)
downloadmonero-cd34fc655d5bf4ed5d9425222b78a771b7a55294.tar.xz
Use easylogging++'s stack trace facility where possible
This avoids using libunwind, which often causes trouble.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/stack_trace.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/common/stack_trace.cpp b/src/common/stack_trace.cpp
index 99e4bda2c..67065aae7 100644
--- a/src/common/stack_trace.cpp
+++ b/src/common/stack_trace.cpp
@@ -26,11 +26,17 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#if !defined __GNUC__ || defined __MINGW32__ || defined __MINGW64__
+#define USE_UNWIND
+#endif
+
#include "common/stack_trace.h"
#include "misc_log_ex.h"
+#ifdef USE_UNWIND
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#include <cxxabi.h>
+#endif
#ifndef STATICLIB
#include <dlfcn.h>
#endif
@@ -99,6 +105,7 @@ void set_stack_trace_log(const std::string &log)
void log_stack_trace(const char *msg)
{
+#ifdef USE_UNWIND
unw_context_t ctx;
unw_cursor_t cur;
unw_word_t ip, off;
@@ -106,10 +113,13 @@ void log_stack_trace(const char *msg)
char sym[512], *dsym;
int status;
const char *log = stack_trace_log.empty() ? NULL : stack_trace_log.c_str();
+#endif
if (msg)
ST_LOG(msg);
ST_LOG("Unwound call stack:");
+
+#ifdef USE_UNWIND
if (unw_getcontext(&ctx) < 0) {
ST_LOG("Failed to create unwind context");
return;
@@ -138,6 +148,15 @@ void log_stack_trace(const char *msg)
ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip << " " << (!status && dsym ? dsym : sym) << " + " << "0x" << off);
free(dsym);
}
+#else
+ std::stringstream ss;
+ ss << el::base::debug::StackTrace();
+ std::vector<std::string> lines;
+ std::string s = ss.str();
+ boost::split(lines, s, boost::is_any_of("\n"));
+ for (const auto &line: lines)
+ ST_LOG(line);
+#endif
}
} // namespace tools