Use the libcxxabi __cxa_demangle.
Bug: 18930951 Change-Id: If2ea3633ac6dfd4ec975c0f16bdf3dd58e05c614
This commit is contained in:
parent
8e5f9bc8a4
commit
6e54c3e519
@ -1221,7 +1221,8 @@ LOCAL_CXX_STL := none
|
|||||||
LOCAL_SYSTEM_SHARED_LIBRARIES :=
|
LOCAL_SYSTEM_SHARED_LIBRARIES :=
|
||||||
# Only need this for arm since libc++ uses its own unwind code that
|
# Only need this for arm since libc++ uses its own unwind code that
|
||||||
# doesn't mix with the other default unwind code.
|
# doesn't mix with the other default unwind code.
|
||||||
LOCAL_STATIC_LIBRARIES_arm := libunwind_llvm libc++abi
|
LOCAL_STATIC_LIBRARIES_arm := libunwind_llvm
|
||||||
|
LOCAL_STATIC_LIBRARIES += libc++abi
|
||||||
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
|
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
|
||||||
|
|
||||||
# Don't install on release build
|
# Don't install on release build
|
||||||
|
@ -47,34 +47,20 @@
|
|||||||
|
|
||||||
typedef struct _Unwind_Context __unwind_context;
|
typedef struct _Unwind_Context __unwind_context;
|
||||||
|
|
||||||
|
extern "C" char* __cxa_demangle(const char*, char*, size_t*, int*);
|
||||||
|
|
||||||
static mapinfo_t* g_map_info = NULL;
|
static mapinfo_t* g_map_info = NULL;
|
||||||
static void* g_demangler;
|
|
||||||
typedef char* (*DemanglerFn)(const char*, char*, size_t*, int*);
|
|
||||||
static DemanglerFn g_demangler_fn = NULL;
|
|
||||||
|
|
||||||
__LIBC_HIDDEN__ void backtrace_startup() {
|
__LIBC_HIDDEN__ void backtrace_startup() {
|
||||||
ScopedDisableDebugCalls disable;
|
ScopedDisableDebugCalls disable;
|
||||||
|
|
||||||
g_map_info = mapinfo_create(getpid());
|
g_map_info = mapinfo_create(getpid());
|
||||||
g_demangler = dlopen("libgccdemangle.so", RTLD_NOW);
|
|
||||||
if (g_demangler != NULL) {
|
|
||||||
void* sym = dlsym(g_demangler, "__cxa_demangle");
|
|
||||||
g_demangler_fn = reinterpret_cast<DemanglerFn>(sym);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__LIBC_HIDDEN__ void backtrace_shutdown() {
|
__LIBC_HIDDEN__ void backtrace_shutdown() {
|
||||||
ScopedDisableDebugCalls disable;
|
ScopedDisableDebugCalls disable;
|
||||||
|
|
||||||
mapinfo_destroy(g_map_info);
|
mapinfo_destroy(g_map_info);
|
||||||
dlclose(g_demangler);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char* demangle(const char* symbol) {
|
|
||||||
if (g_demangler_fn == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return (*g_demangler_fn)(symbol, NULL, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stack_crawl_state_t {
|
struct stack_crawl_state_t {
|
||||||
@ -158,8 +144,7 @@ __LIBC_HIDDEN__ void log_backtrace(uintptr_t* frames, size_t frame_count) {
|
|||||||
soname = "<unknown>";
|
soname = "<unknown>";
|
||||||
}
|
}
|
||||||
if (symbol != NULL) {
|
if (symbol != NULL) {
|
||||||
// TODO: we might need a flag to say whether it's safe to allocate (demangling allocates).
|
char* demangled_symbol = __cxa_demangle(symbol, NULL, NULL, NULL);
|
||||||
char* demangled_symbol = demangle(symbol);
|
|
||||||
const char* best_name = (demangled_symbol != NULL) ? demangled_symbol : symbol;
|
const char* best_name = (demangled_symbol != NULL) ? demangled_symbol : symbol;
|
||||||
|
|
||||||
__libc_format_log(ANDROID_LOG_ERROR, "libc",
|
__libc_format_log(ANDROID_LOG_ERROR, "libc",
|
||||||
|
Loading…
Reference in New Issue
Block a user