Merge "Use the new AndroidUnwinder object." am: af4db6749a

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2095264

Change-Id: I01127fab931da0bb5f20bc7e1f17f17ace004419
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Christopher Ferris 2022-05-11 21:29:58 +00:00 committed by Automerger Merge Worker
commit ce1c33332c
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,