From 46b3076c910639e833aaa26bc18965058dfe7170 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Fri, 25 Apr 2014 09:50:51 -0400 Subject: [PATCH] Better stack trace in MAC Summary: Now this gives us the real deal stack trace: Assertion failed: (false), function GetProperty, file db/db_impl.cc, line 4072. Received signal 6 (Abort trap: 6) #0 0x7fff57ce39b9 #1 abort (in libsystem_c.dylib) + 125 #2 basename (in libsystem_c.dylib) + 0 #3 rocksdb::DBImpl::GetProperty(rocksdb::ColumnFamilyHandle*, rocksdb::Slice const&, std::__1::basic_string, std::__1::allocator >*) (in db_test) (db_impl.cc:4072) #4 rocksdb::_Test_Empty::_Run() (in db_test) (testharness.h:68) #5 rocksdb::_Test_Empty::_RunIt() (in db_test) (db_test.cc:1005) #6 rocksdb::test::RunAllTests() (in db_test) (testharness.cc:60) #7 main (in db_test) (db_test.cc:6697) #8 start (in libdyld.dylib) + 1 Test Plan: added artificial assert, saw great stack trace Reviewers: haobo, dhruba, ljin Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D18309 --- port/stack_trace.cc | 26 +++++++++++++++----------- util/testharness.cc | 3 +-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/port/stack_trace.cc b/port/stack_trace.cc index b1a9ba08d8f..76866e63cc8 100644 --- a/port/stack_trace.cc +++ b/port/stack_trace.cc @@ -70,19 +70,23 @@ void PrintStackTraceLine(const char* symbol, void* frame) { #elif OS_MACOSX void PrintStackTraceLine(const char* symbol, void* frame) { - if (symbol) { - char filename[64], function[512], plus[2], line[10]; - sscanf(symbol, "%*s %64s %*s %512s %2s %10s", filename, function, plus, - line); - int status; - char* demangled = abi::__cxa_demangle(function, 0, 0, &status); - fprintf(stderr, "%s %s %s %s", filename, - (status == 0) ? demangled : function, plus, line); - if (demangled) { - free(demangled); + static int pid = getpid(); + // out source to atos, for the address translation + const int kLineMax = 256; + char cmd[kLineMax]; + snprintf(cmd, kLineMax, "xcrun atos %p -p %d 2>&1", frame, pid); + auto f = popen(cmd, "r"); + if (f) { + char line[kLineMax]; + while (fgets(line, sizeof(line), f)) { + line[strlen(line) - 1] = 0; // remove newline + fprintf(stderr, "%s\t", line); } + pclose(f); + } else if (symbol) { + fprintf(stderr, "%s ", symbol); } - fprintf(stderr, " %p", frame); + fprintf(stderr, "\n"); } diff --git a/util/testharness.cc b/util/testharness.cc index 7051ccf6690..4208d2c46a2 100644 --- a/util/testharness.cc +++ b/util/testharness.cc @@ -8,12 +8,11 @@ // found in the LICENSE file. See the AUTHORS file for names of contributors. #include "util/testharness.h" -#include "port/stack_trace.h" - #include #include #include #include +#include "port/stack_trace.h" namespace rocksdb { namespace test {