diff --git a/libbacktrace/Android.bp b/libbacktrace/Android.bp index 9ece8479c..565f2c35e 100644 --- a/libbacktrace/Android.bp +++ b/libbacktrace/Android.bp @@ -97,7 +97,6 @@ cc_library { cflags: ["-DNO_LIBDEXFILE_SUPPORT"], }, }, - whole_static_libs: ["libdemangle"], } cc_test_library { diff --git a/libbacktrace/Backtrace.cpp b/libbacktrace/Backtrace.cpp index 71980d7a5..3e050ab68 100644 --- a/libbacktrace/Backtrace.cpp +++ b/libbacktrace/Backtrace.cpp @@ -28,13 +28,13 @@ #include #include -#include - #include "BacktraceLog.h" #include "UnwindStack.h" using android::base::StringPrintf; +extern "C" char* __cxa_demangle(const char*, char*, size_t*, int*); + //------------------------------------------------------------------------- // Backtrace functions. //------------------------------------------------------------------------- @@ -63,7 +63,14 @@ std::string Backtrace::GetFunctionName(uint64_t pc, uint64_t* offset, const back if (map->start == 0 || (map->flags & PROT_DEVICE_MAP)) { return ""; } - return demangle(GetFunctionNameRaw(pc, offset).c_str()); + std::string name(GetFunctionNameRaw(pc, offset)); + char* demangled_name = __cxa_demangle(name.c_str(), nullptr, nullptr, nullptr); + if (demangled_name != nullptr) { + name = demangled_name; + free(demangled_name); + return name; + } + return name; } bool Backtrace::VerifyReadWordArgs(uint64_t ptr, word_t* out_value) { diff --git a/libbacktrace/UnwindStack.cpp b/libbacktrace/UnwindStack.cpp index a12862398..624711f79 100644 --- a/libbacktrace/UnwindStack.cpp +++ b/libbacktrace/UnwindStack.cpp @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -41,6 +40,8 @@ #include "UnwindStack.h" #include "UnwindStackMap.h" +extern "C" char* __cxa_demangle(const char*, char*, size_t*, int*); + bool Backtrace::Unwind(unwindstack::Regs* regs, BacktraceMap* back_map, std::vector* frames, size_t num_ignore_frames, std::vector* skip_names, BacktraceUnwindError* error) { @@ -115,7 +116,13 @@ bool Backtrace::Unwind(unwindstack::Regs* regs, BacktraceMap* back_map, back_frame->pc = frame->pc; back_frame->sp = frame->sp; - back_frame->func_name = demangle(frame->function_name.c_str()); + char* demangled_name = __cxa_demangle(frame->function_name.c_str(), nullptr, nullptr, nullptr); + if (demangled_name != nullptr) { + back_frame->func_name = demangled_name; + free(demangled_name); + } else { + back_frame->func_name = frame->function_name; + } back_frame->func_offset = frame->function_offset; back_frame->map.name = frame->map_name;