OSDN Git Service

Use libdemangle for function names.
authorChristopher Ferris <cferris@google.com>
Thu, 1 Jun 2017 21:16:32 +0000 (14:16 -0700)
committerChristopher Ferris <cferris@google.com>
Fri, 2 Jun 2017 17:10:24 +0000 (10:10 -0700)
Bug: 62141808

Test: Ran unit tests, ran malloc debug with leaks and verified functions
Test: are demangled.
Change-Id: I1900632e9a55bb818b1aabc798224ff3eebc1fca

libc/malloc_debug/Android.bp
libc/malloc_debug/backtrace.cpp

index b071b90..06fc426 100644 (file)
@@ -13,7 +13,7 @@ cc_library_static {
 
     stl: "libc++_static",
 
-    whole_static_libs: ["libasync_safe"],
+    whole_static_libs: ["libasync_safe", "libdemangle"],
 
     include_dirs: ["bionic/libc"],
 
index 907944f..2443ba1 100644 (file)
@@ -36,6 +36,8 @@
 #include <unistd.h>
 #include <unwind.h>
 
+#include <demangle.h>
+
 #include "backtrace.h"
 #include "debug_log.h"
 #include "MapData.h"
@@ -163,13 +165,9 @@ std::string backtrace_string(const uintptr_t* frames, size_t frame_count) {
 
     char buf[1024];
     if (symbol != nullptr) {
-      char* demangled_symbol = __cxa_demangle(symbol, nullptr, nullptr, nullptr);
-      const char* best_name = (demangled_symbol != nullptr) ? demangled_symbol : symbol;
-
       async_safe_format_buffer(
           buf, sizeof(buf), "          #%02zd  pc %" PAD_PTR "  %s%s (%s+%" PRIuPTR ")\n", frame_num,
-          rel_pc, soname, offset_buf, best_name, frames[frame_num] - offset);
-      free(demangled_symbol);
+          rel_pc, soname, offset_buf, demangle(symbol).c_str(), frames[frame_num] - offset);
     } else {
       async_safe_format_buffer(
           buf, sizeof(buf), "          #%02zd  pc %" PAD_PTR "  %s%s\n", frame_num, rel_pc, soname,