标签:android
Android 下面没有 execinfo.h, 就不能用在 glibc下打印 back trace 方法了。
glic 下打印 back trace 参见:http://blog.csdn.net/span76/article/details/11927551
我写了下面的方法,供参考:
#include <signal.h> #include <corkscrew/backtrace.h> static void pnpDumpNativeStack(int sig) { #if defined(HAVE_ANDROID_OS) || (defined(HAVE_ALIEN) && !defined(ALIEN_LIBC)) const size_t MAX_DEPTH = 32; backtrace_frame_t backtrace[MAX_DEPTH]; ssize_t frames = unwind_backtrace_thread(tid, backtrace, 0, MAX_DEPTH); if (frames > 0) { backtrace_symbol_t backtrace_symbols[MAX_DEPTH]; get_backtrace_symbols(backtrace, frames, backtrace_symbols); for (size_t i = 0; i < size_t(frames); i++) { char line[MAX_BACKTRACE_LINE_LENGTH]; format_backtrace_line(i, &backtrace[i], &backtrace_symbols[i], line, MAX_BACKTRACE_LINE_LENGTH); ALOGE("================== %s\n", line); } free_backtrace_symbols(backtrace_symbols, frames); } #endif } ... void dvmCollectGarbageInternal(const GcSpec* spec) { signal(SIGSEGV, pnpDumpNativeStack); ...
遗憾的是,我每次打印都打印不全,比如下面就2条,原因有待查明。
09-30 03:38:49.821 137 137 E dalvikvm: ================== #00 pc 00026edb /../system/lib/libdvm.so
09-30 03:38:49.821 137 137 E dalvikvm: ================== #01 pc 00000400 [vdso]
标签:android
原文地址:http://blog.csdn.net/span76/article/details/39697183