Move to the libc++ demangler.
The previous versions of the libc++ demangler crashed on bad input.
However, the new version passes a fuzzer and has a lot of tests. Since
it's more complete than the local demangler, use it instead.
Modified the expected output of an offline test since the new demangler
handles a case that didn't work before.
Verified that the time it takes for the check_for_leak tests did not
change after this.
Bug: 136138882
Test: Ran the unit tests.
Test: Verified the __cxa_demangle function passes the fuzzer when run for
Test: hours. Both the 32 bit and 64 bit version of __cxa_demangle were
Test: fuzzed using external/libcxxabi/fuzz.
Change-Id: I10c06b589d57c36d89dbecba020b1ef2da69634a
diff --git a/libunwindstack/Unwinder.cpp b/libunwindstack/Unwinder.cpp
index c95f852..7556482 100644
--- a/libunwindstack/Unwinder.cpp
+++ b/libunwindstack/Unwinder.cpp
@@ -27,8 +27,6 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
-#include <demangle.h>
-
#include <unwindstack/Elf.h>
#include <unwindstack/JitDebug.h>
#include <unwindstack/MapInfo.h>
@@ -40,6 +38,9 @@
#include <unwindstack/DexFiles.h>
#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 @@
}
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);
}