Don't collect useless stack frames; do demangle C++ symbols.
Previously, we'd collect every stack frame and then throw some away
when we came to log them. This meant that stack traces were effectively
shorter than the buffers that had been allocated for them. This patch
only stores frames we'll actually output.
Also dynamically call the C++ demangler so we don't have to try to
read mangled names. Because no one knows the mangling of operator new[]
for int arrays off the top of their head.
Bug: 7291287
Change-Id: I42b022fd7cd61675d05171de4c3b2704d058ef2a
diff --git a/libc/bionic/pthread_debug.cpp b/libc/bionic/pthread_debug.cpp
index ac81837..21eac63 100644
--- a/libc/bionic/pthread_debug.cpp
+++ b/libc/bionic/pthread_debug.cpp
@@ -120,8 +120,6 @@
#define STACK_TRACE_DEPTH 16
-static mapinfo_t* gMapInfo;
-
/****************************************************************************/
/*
@@ -370,17 +368,14 @@
/* Turn off prediction temporarily in this thread while logging */
sPthreadDebugDisabledThread = gettid();
- if (gMapInfo == NULL) {
- // note: we're protected by sDbgLock.
- gMapInfo = mapinfo_create(getpid());
- }
+ backtrace_startup();
LOGW("%s\n", kStartBanner);
LOGW("pid: %d, tid: %d >>> %s <<<", getpid(), gettid(), __progname);
LOGW("Illegal lock attempt:\n");
LOGW("--- pthread_mutex_t at %p\n", obj->mutex);
stackDepth = get_backtrace(addrs, STACK_TRACE_DEPTH);
- log_backtrace(gMapInfo, addrs, stackDepth);
+ log_backtrace(addrs, stackDepth);
LOGW("+++ Currently held locks in this thread (in reverse order):");
MutexInfo* cur = obj;
@@ -391,7 +386,7 @@
if (parent->owner == ourtid) {
LOGW("--- pthread_mutex_t at %p\n", parent->mutex);
if (sPthreadDebugLevel >= CAPTURE_CALLSTACK) {
- log_backtrace(gMapInfo, parent->stackTrace, parent->stackDepth);
+ log_backtrace(parent->stackTrace, parent->stackDepth);
}
cur = parent;
break;
@@ -414,13 +409,9 @@
if (sPthreadDebugLevel >= CAPTURE_CALLSTACK) {
int index = historyListHas(&obj->parents, objParent);
if ((size_t)index < (size_t)obj->stacks.count) {
- log_backtrace(gMapInfo,
- obj->stacks.stack[index].addrs,
- obj->stacks.stack[index].depth);
+ log_backtrace(obj->stacks.stack[index].addrs, obj->stacks.stack[index].depth);
} else {
- log_backtrace(gMapInfo,
- obj->stackTrace,
- obj->stackDepth);
+ log_backtrace(obj->stackTrace, obj->stackDepth);
}
}
result = 0;
@@ -465,8 +456,7 @@
linkParentToChild(mrl, object);
if (!traverseTree(object, mrl)) {
- mapinfo_destroy(gMapInfo);
- gMapInfo = NULL;
+ backtrace_shutdown();
LOGW("%s\n", kEndBanner);
unlinkParentFromChild(mrl, object);
// reenable pthread debugging for this thread