概述
1.修改Android.mk文件
在mk中所有的LOCAL_SHARED_LIBRARIES地方添加
LOCAL_SHARED_LIBRARIES:=
libcutils
libutils
2.在c中添加:
#include <stdint.h> #include <cutils/debugger.h> #include <fcntl.h> #include <errno.h> #define NE_FOLDER_PATH "/storage/sdcard1/data" #define NE_FILE_NAME "ne_dump" #define NE_DUMP (NE_FOLDER_PATH NE_FILE_NAME) //code部分 char filename[100]; sprintf(filename,"%s.txt",NE_DUMP); int fd = open(filename,O_CREAT | O_WRONLY,0777); if(fd < 0){ fprintf(stderr,"can not open %s,%sn",filename,strerror(errno)); } if(lseek(fd,0,SEEK_END)<0){ fprintf(stderr,"can not open %sn",strerror(errno)); } else { dump_backtrace_to_file(getpid(),fd); } close(fd);
3.在build,push重启后,添加权限
adb shell mkdir /storage/sdcard1/data
adb shell chmod 777 /storage/sdcard1/data
这样就能打出backtrace到文件/storage/sdcard1/data/ne_dump.txt了
在java中打印backtrace:
在指定的函数内打印相关java调用
法1:RuntimeException r = new RuntimeException("srx");
r.printStackTrace();
法2:Exception e = new Exception();
e.printStackTrace();
法3:
Log.e(TAG,Log.getStackTraceString(new Throwable()));
转载于:https://www.cnblogs.com/snowdrop/articles/3753584.html
最后
以上就是彩色草丛为你收集整理的在c file中打出backtrace到某个文件中的全部内容,希望文章能够帮你解决在c file中打出backtrace到某个文件中所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复