From dfb50b448f86a284bdad12d65feab0d158f38e2f Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Wed, 23 Mar 2022 12:37:58 -0700 Subject: Move from libbacktrace to libunwindstack. Use the new AndroidUnwinder object to replace the libbacktrace version. Bug: 120606663 Test: Run unit tests. Test: Force a call to CallStack::log() and verify the backtrace is Test: reasonable. Change-Id: I73d909821a33f716d7b0e0997d43c6ab11c7c4f9 --- opengl/libs/Android.bp | 2 +- opengl/libs/EGL/CallStack.h | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'opengl/libs') diff --git a/opengl/libs/Android.bp b/opengl/libs/Android.bp index c9fce8ad52..c1e935aab0 100644 --- a/opengl/libs/Android.bp +++ b/opengl/libs/Android.bp @@ -108,7 +108,6 @@ cc_defaults { // In particular, DO NOT add libutils nor anything "above" libui "libgraphicsenv", "libnativewindow", - "libbacktrace", "libbase", ], } @@ -165,6 +164,7 @@ cc_library_shared { "libnativeloader_lazy", "libutils", "libSurfaceFlingerProp", + "libunwindstack", ], static_libs: [ "libEGL_getProcAddress", diff --git a/opengl/libs/EGL/CallStack.h b/opengl/libs/EGL/CallStack.h index b7fdf97cbe..96437c37d9 100644 --- a/opengl/libs/EGL/CallStack.h +++ b/opengl/libs/EGL/CallStack.h @@ -16,8 +16,8 @@ #pragma once -#include #include +#include #include @@ -26,12 +26,15 @@ public: // Create a callstack with the current thread's stack trace. // Immediately dump it to logcat using the given logtag. static void log(const char* logtag) noexcept { - std::unique_ptr backtrace( - Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD)); - if (backtrace->Unwind(2)) { - for (size_t i = 0, c = backtrace->NumFrames(); i < c; i++) { + unwindstack::AndroidLocalUnwinder unwinder; + unwindstack::AndroidUnwinderData data; + if (unwinder.Unwind(data)) { + for (size_t i = 2, c = data.frames.size(); i < c; i++) { + auto& frame = data.frames[i]; + // Trim the first two frames. + frame.num -= 2; __android_log_print(ANDROID_LOG_DEBUG, logtag, "%s", - backtrace->FormatFrameData(i).c_str()); + unwinder.FormatFrame(frame).c_str()); } } } -- cgit v1.2.3-59-g8ed1b