深入浅出Android NDK之打印调用堆栈
目录 上一篇 深入浅出Android NDK之崩溃分析 为了能在native层打印函数的调用堆栈,找了好久的资料,最后终于找到一个靠谱的链接: https://www.jianshu.com/p/4a5eeeee6d29 主要通过调用_Unwind_Backtrace函数来获得函数的调用堆栈,但是原文的并不好用,地址通过addr2line转换以后得不到函数名和行号,主要原因我们得到的地址是运行时地址,应该减去SO的基地址再来转换,下面看我改造后的例子,更好用。 #include <unwind.h> #include <dlfcn.h> #include <vector> #include <string> #include <android/log.h> static _Unwind_Reason_Code unwindCallback(struct _Unwind_Context* context, void* arg) { std::vector<_Unwind_Word> &stack = *(std::vector<_Unwind_Word>*)arg; stack.push_back(_Unwind_GetIP(context)); return _URC_NO_REASON; } void callstackDump(std::string &dump) { std: