Skip to content

Commit 46b3076

Browse files
committed
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<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) (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) XRPLF#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
1 parent a82c492 commit 46b3076

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

port/stack_trace.cc

+15-11
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,23 @@ void PrintStackTraceLine(const char* symbol, void* frame) {
7070
#elif OS_MACOSX
7171

7272
void PrintStackTraceLine(const char* symbol, void* frame) {
73-
if (symbol) {
74-
char filename[64], function[512], plus[2], line[10];
75-
sscanf(symbol, "%*s %64s %*s %512s %2s %10s", filename, function, plus,
76-
line);
77-
int status;
78-
char* demangled = abi::__cxa_demangle(function, 0, 0, &status);
79-
fprintf(stderr, "%s %s %s %s", filename,
80-
(status == 0) ? demangled : function, plus, line);
81-
if (demangled) {
82-
free(demangled);
73+
static int pid = getpid();
74+
// out source to atos, for the address translation
75+
const int kLineMax = 256;
76+
char cmd[kLineMax];
77+
snprintf(cmd, kLineMax, "xcrun atos %p -p %d 2>&1", frame, pid);
78+
auto f = popen(cmd, "r");
79+
if (f) {
80+
char line[kLineMax];
81+
while (fgets(line, sizeof(line), f)) {
82+
line[strlen(line) - 1] = 0; // remove newline
83+
fprintf(stderr, "%s\t", line);
8384
}
85+
pclose(f);
86+
} else if (symbol) {
87+
fprintf(stderr, "%s ", symbol);
8488
}
85-
fprintf(stderr, " %p", frame);
89+
8690
fprintf(stderr, "\n");
8791
}
8892

util/testharness.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
// found in the LICENSE file. See the AUTHORS file for names of contributors.
99

1010
#include "util/testharness.h"
11-
#include "port/stack_trace.h"
12-
1311
#include <string>
1412
#include <stdlib.h>
1513
#include <sys/stat.h>
1614
#include <sys/types.h>
15+
#include "port/stack_trace.h"
1716

1817
namespace rocksdb {
1918
namespace test {

0 commit comments

Comments
 (0)