我在sigaction中使用libcorkscrew来获取Android上的回溯(是的,我知道libcorkscrew没有公开暴露)。
我可以从libcorkscrew获得回溯但是它给了我奇怪/不完整的结果。
我忘记了什么吗?
以下是我的工作:
typedef struct map_info_t map_info_t;
typedef struct {
uintptr_t absolute_pc;
uintptr_t stack_top;
size_t stack_size;
} backtrace_frame_t;
typedef struct {
uintptr_t relative_pc;
uintptr_t relative_symbol_addr;
char* map_name;
char* symbol_name;
char* demangled_name;
} backtrace_symbol_t;
typedef ssize_t (*t_unwind_backtrace_signal_arch)(siginfo_t* si, void* sc, const map_info_t* lst, backtrace_frame_t* bt, size_t ignore_depth, size_t max_depth);
static t_unwind_backtrace_signal_arch unwind_backtrace_signal_arch;
typedef map_info_t* (*t_acquire_my_map_info_list)();
static t_acquire_my_map_info_list acquire_my_map_info_list;
typedef void (*t_release_my_map_info_list)(map_info_t* milist);
static t_release_my_map_info_list release_my_map_info_list;
typedef void (*t_get_backtrace_symbols)(const backtrace_frame_t* backtrace, size_t frames, backtrace_symbol_t* symbols);
static t_get_backtrace_symbols get_backtrace_symbols;
typedef void (*t_free_backtrace_symbols)(backtrace_symbol_t* symbols, size_t frames);
static t_free_backtrace_symbols free_backtrace_symbols;
void nativeCrashHandler_sigaction(int signal, struct siginfo *siginfo, void *sigcontext) {
if (old_sa[signal].sa_handler)
old_sa[signal].sa_handler(signal);
if (unwind_backtrace_signal_arch != NULL) {
map_info_t *map_info = acquire_my_map_info_list();
backtrace_frame_t frames[256] = {0,};
backtrace_symbol_t symbols[256] = {0,};
const ssize_t size = unwind_backtrace_signal_arch(siginfo, sigcontext, map_info, frames, 1, 255);
get_backtrace_symbols(frames, size, symbols);
for (int i = 0; i < size; ++i)
__android_log_print(ANDROID_LOG_ERROR, "DUMP", "%s", (symbols[i].demangled_name ? symbols[i].demangled_name : symbols[i].symbol_name));
free_backtrace_symbols(symbols, size);
release_my_map_info_list(map_info);
}
}