Skip to content

Commit

Permalink
Better stack trace in MAC
Browse files Browse the repository at this point in the history
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)
    #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
  • Loading branch information
igorcanadi committed Apr 25, 2014
1 parent a82c492 commit 46b3076
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
26 changes: 15 additions & 11 deletions port/stack_trace.cc
Expand Up @@ -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");
}

Expand Down
3 changes: 1 addition & 2 deletions util/testharness.cc
Expand Up @@ -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 <string>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "port/stack_trace.h"

namespace rocksdb {
namespace test {
Expand Down

0 comments on commit 46b3076

Please sign in to comment.