diff --git a/libunwindstack/Android.bp b/libunwindstack/Android.bp index a0a6b4fd5..46fd69ec4 100644 --- a/libunwindstack/Android.bp +++ b/libunwindstack/Android.bp @@ -125,10 +125,6 @@ cc_library { }, }, - whole_static_libs: [ - "libdemangle" - ], - static_libs: [ "libprocinfo", ], diff --git a/libunwindstack/Unwinder.cpp b/libunwindstack/Unwinder.cpp index c95f85282..755648297 100644 --- a/libunwindstack/Unwinder.cpp +++ b/libunwindstack/Unwinder.cpp @@ -27,8 +27,6 @@ #include #include -#include - #include #include #include @@ -40,6 +38,9 @@ #include #endif +// Use the demangler from libc++. +extern "C" char* __cxa_demangle(const char*, char*, size_t*, int* status); + namespace unwindstack { // Inject extra 'virtual' frame that represents the dex pc data. @@ -330,7 +331,14 @@ std::string Unwinder::FormatFrame(const FrameData& frame) { } if (!frame.function_name.empty()) { - data += " (" + demangle(frame.function_name.c_str()); + char* demangled_name = __cxa_demangle(frame.function_name.c_str(), nullptr, nullptr, nullptr); + if (demangled_name == nullptr) { + data += " (" + frame.function_name; + } else { + data += " ("; + data += demangled_name; + free(demangled_name); + } if (frame.function_offset != 0) { data += android::base::StringPrintf("+%" PRId64, frame.function_offset); } diff --git a/libunwindstack/tests/UnwindOfflineTest.cpp b/libunwindstack/tests/UnwindOfflineTest.cpp index e6158a268..bded57aca 100644 --- a/libunwindstack/tests/UnwindOfflineTest.cpp +++ b/libunwindstack/tests/UnwindOfflineTest.cpp @@ -1482,11 +1482,15 @@ TEST_F(UnwindOfflineTest, load_bias_ro_rx_x86_64) { " #09 pc 0000000000ed5e25 perfetto_unittests " "(testing::internal::UnitTestImpl::RunAllTests()+581)\n" " #10 pc 0000000000ef63f3 perfetto_unittests " - "(_ZN7testing8internal38HandleSehExceptionsInMethodIfSupportedINS0_12UnitTestImplEbEET0_PT_" - "MS4_FS3_vEPKc+131)\n" + "(bool " + "testing::internal::HandleSehExceptionsInMethodIfSupported(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char " + "const*)+131)\n" " #11 pc 0000000000ee2a21 perfetto_unittests " - "(_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS0_12UnitTestImplEbEET0_PT_MS4_" - "FS3_vEPKc+113)\n" + "(bool " + "testing::internal::HandleExceptionsInMethodIfSupported(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char " + "const*)+113)\n" " #12 pc 0000000000ed5bb9 perfetto_unittests (testing::UnitTest::Run()+185)\n" " #13 pc 0000000000e900f0 perfetto_unittests (RUN_ALL_TESTS()+16)\n" " #14 pc 0000000000e900d8 perfetto_unittests (main+56)\n"