Use libunwindbacktrace for debug malloc code.
Create a method of disabling the debug allocation code paths so that
it's possible to use the libunwindbacktrace library without any
modifications.
Use this path to create and destroy the maps for the process. It's not
stricly necessary in the init code since the symbols are not modified
until after the initialize calls.
Also, remove the debug_XXX source files that doesn't need to be in libc.so.
Fix the maps reading code since it was completely broken for 64 bit.
Bug: 16408686
(cherry picked from commit 861c0ef37b)
Change-Id: I04445f0cf9a1e85172b64d57df92eb7939ce2332
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "debug_mapinfo.h"
|
||||
#include "malloc_debug_disable.h"
|
||||
#include "private/libc_logging.h"
|
||||
|
||||
#if defined(__LP64__)
|
||||
@@ -56,6 +57,8 @@ typedef char* (*DemanglerFn)(const char*, char*, size_t*, int*);
|
||||
static DemanglerFn g_demangler_fn = NULL;
|
||||
|
||||
__LIBC_HIDDEN__ void backtrace_startup() {
|
||||
ScopedDisableDebugCalls disable;
|
||||
|
||||
g_map_info = mapinfo_create(getpid());
|
||||
g_demangler = dlopen("libgccdemangle.so", RTLD_NOW);
|
||||
if (g_demangler != NULL) {
|
||||
@@ -65,6 +68,8 @@ __LIBC_HIDDEN__ void backtrace_startup() {
|
||||
}
|
||||
|
||||
__LIBC_HIDDEN__ void backtrace_shutdown() {
|
||||
ScopedDisableDebugCalls disable;
|
||||
|
||||
mapinfo_destroy(g_map_info);
|
||||
dlclose(g_demangler);
|
||||
}
|
||||
@@ -98,7 +103,7 @@ static _Unwind_Reason_Code trace_function(__unwind_context* context, void* arg)
|
||||
return _URC_NO_REASON;
|
||||
}
|
||||
|
||||
#ifdef __arm__
|
||||
#if defined(__arm__)
|
||||
/*
|
||||
* The instruction pointer is pointing at the instruction after the bl(x), and
|
||||
* the _Unwind_Backtrace routine already masks the Thumb mode indicator (LSB
|
||||
@@ -121,12 +126,16 @@ static _Unwind_Reason_Code trace_function(__unwind_context* context, void* arg)
|
||||
}
|
||||
|
||||
__LIBC_HIDDEN__ int get_backtrace(uintptr_t* frames, size_t max_depth) {
|
||||
ScopedDisableDebugCalls disable;
|
||||
|
||||
stack_crawl_state_t state(frames, max_depth);
|
||||
_Unwind_Backtrace(trace_function, &state);
|
||||
return state.frame_count;
|
||||
}
|
||||
|
||||
__LIBC_HIDDEN__ void log_backtrace(uintptr_t* frames, size_t frame_count) {
|
||||
ScopedDisableDebugCalls disable;
|
||||
|
||||
uintptr_t self_bt[16];
|
||||
if (frames == NULL) {
|
||||
frame_count = get_backtrace(self_bt, 16);
|
||||
@@ -146,7 +155,7 @@ __LIBC_HIDDEN__ void log_backtrace(uintptr_t* frames, size_t frame_count) {
|
||||
symbol = info.dli_sname;
|
||||
}
|
||||
|
||||
uintptr_t rel_pc;
|
||||
uintptr_t rel_pc = offset;
|
||||
const mapinfo_t* mi = (g_map_info != NULL) ? mapinfo_find(g_map_info, frames[i], &rel_pc) : NULL;
|
||||
const char* soname = (mi != NULL) ? mi->name : info.dli_fname;
|
||||
if (soname == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user