Use the new AndroidUnwinder object.

Replaces libbacktrace in CallStack. There is one small behavioral
change, the BuildId data is added to the unwinds.

Bug: 120606663

Test: All unit tests pass.
Test: Run the fuzzer for over an hour without any crashes.
Change-Id: Ic8a4247c515ce0d3cdc4d2cc15167d1948b15fa5
This commit is contained in:
Christopher Ferris 2022-05-10 16:13:02 -07:00
parent 37a5303642
commit ab63124cd9
3 changed files with 19 additions and 17 deletions

View file

@ -44,14 +44,6 @@ cc_library_headers {
export_include_dirs: ["include"],
target: {
android: {
header_libs: ["libbacktrace_headers"],
export_header_lib_headers: ["libbacktrace_headers"],
},
host_linux: {
header_libs: ["libbacktrace_headers"],
export_header_lib_headers: ["libbacktrace_headers"],
},
linux_bionic: {
enabled: true,
},
@ -196,7 +188,7 @@ cc_library {
shared_libs: [
"libutils",
"libbacktrace",
"libunwindstack",
],
target: {

View file

@ -20,7 +20,7 @@
#include <utils/Errors.h>
#include <utils/Log.h>
#include <backtrace/Backtrace.h>
#include <unwindstack/AndroidUnwinder.h>
#define CALLSTACK_WEAK // Don't generate weak definitions.
#include <utils/CallStack.h>
@ -39,14 +39,25 @@ CallStack::~CallStack() {
}
void CallStack::update(int32_t ignoreDepth, pid_t tid) {
if (ignoreDepth < 0) {
ignoreDepth = 0;
}
mFrameLines.clear();
std::unique_ptr<Backtrace> backtrace(Backtrace::Create(BACKTRACE_CURRENT_PROCESS, tid));
if (!backtrace->Unwind(ignoreDepth)) {
ALOGW("%s: Failed to unwind callstack.", __FUNCTION__);
unwindstack::AndroidLocalUnwinder unwinder;
unwindstack::AndroidUnwinderData data;
std::optional<pid_t> tid_val;
if (tid != -1) {
*tid_val = tid;
}
for (size_t i = 0; i < backtrace->NumFrames(); i++) {
mFrameLines.push_back(String8(backtrace->FormatFrameData(i).c_str()));
if (!unwinder.Unwind(tid_val, data)) {
ALOGW("%s: Failed to unwind callstack: %s", __FUNCTION__, data.GetErrorString().c_str());
}
for (size_t i = ignoreDepth; i < data.frames.size(); i++) {
auto& frame = data.frames[i];
frame.num -= ignoreDepth;
mFrameLines.push_back(String8(unwinder.FormatFrame(frame).c_str()));
}
}

View file

@ -20,7 +20,6 @@
#include <memory>
#include <android/log.h>
#include <backtrace/backtrace_constants.h>
#include <utils/String8.h>
#include <utils/Vector.h>
@ -59,7 +58,7 @@ public:
// Immediately collect the stack traces for the specified thread.
// The default is to dump the stack of the current call.
void update(int32_t ignoreDepth = 1, pid_t tid = BACKTRACE_CURRENT_THREAD);
void update(int32_t ignoreDepth = 1, pid_t tid = -1);
// Dump a stack trace to the log using the supplied logtag.
void log(const char* logtag,