Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Fleece/Support/Backtrace+capture-linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ namespace fleece {
}

#ifdef HAVE_LIBBACKTRACE
static void btErrorNoop(void*, const char*, int) {}

static backtrace_state* getBacktraceState() {
static std::once_flag once;
static backtrace_state* state;
std::call_once(once, [] { state = backtrace_create_state(nullptr, /*threaded=*/1, nullptr, nullptr); });
std::call_once(once, [] { state = backtrace_create_state(nullptr, /*threaded=*/1, btErrorNoop, nullptr); });
return state;
}

Expand All @@ -51,9 +53,11 @@ namespace fleece {
};

static ResolvedInfo backtraceResolve(uintptr_t pc) {
ResolvedInfo info;
ResolvedInfo info{};
auto state = getBacktraceState();
if (!state) return info;
backtrace_pcinfo(
getBacktraceState(), pc,
state, pc,
[](void* data, uintptr_t, const char* file, int line, const char* fn) -> int {
auto* r = static_cast<ResolvedInfo*>(data);
if ( fn && !r->function ) r->function = fn;
Expand All @@ -63,17 +67,17 @@ namespace fleece {
}
return 0;
},
nullptr, &info);
btErrorNoop, &info);

// Always call syminfo: provides symval (function start) for offset, and function name fallback
backtrace_syminfo(
getBacktraceState(), pc,
state, pc,
[](void* data, uintptr_t, const char* sym, uintptr_t symval, uintptr_t) {
auto* r = static_cast<ResolvedInfo*>(data);
if ( !r->function && sym ) r->function = sym;
if ( symval ) r->symval = symval;
},
nullptr, &info);
btErrorNoop, &info);
return info;
}
#endif // HAVE_LIBBACKTRACE
Expand Down
Loading