内容简介:今天给大家介绍一个在Linux下如何捕获程序崩溃异常的方法一、Google Breakpad源码的下载和编译1、https://github.com/google/breakpad.git,源码地址,git clone XXX克隆即可
今天给大家介绍一个在 Linux 下如何捕获程序崩溃异常的方法
一、Google Breakpad源码的下载和编译
1、https://github.com/google/breakpad.git,源码地址,git clone XXX克隆即可
2、cd breakpad
3、./configure
4、make
5、make完这里会报错breakpad/src/third_party/lss/linux_syscall_support.h没有这个文件,编译时会出现这个错误
6、该文件可在https://chromium.googlesource.com/linux-syscall-support/下载,并放到breakpad/src/third_party/lss/中,若实在无法下载的同学,可以在以下链接下载linux_syscall_support.h:
可以到Linux公社资源站下载:
------------------------------------------分割线------------------------------------------
免费下载地址在 http://linux.linuxidc.com/
用户名与密码都是 www.linuxidc.com
具体下载目录在/2018年资料/9月/12日/Qt中使用Google Breakpad捕获程序崩溃异常/
下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm
------------------------------------------分割线------------------------------------------
7、再次执行3和4,即可成功
二、如何使用
#include "client/linux/handler/exception_handler.h"
// 写完minidump后的回调函数
static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded)
{
printf("Dump path: %s\n", descriptor.path()); return succeeded;
}
// 触发crash来测试
void crash()
{
volatile int* a = (int*)(NULL); *a = 1;
}
int main(int argc, char* argv[])
{
// 初始化
ExceptionHandler google_breakpad::MinidumpDescriptor descriptor("/tmp");
// minidump文件写入到的目录
google_breakpad::ExceptionHandler eh(descriptor, NULL, dumpCallback, NULL, true, -1); crash();
return 0;
}
1、这样就会在/tmp下生成.dmp文件
2、为了生成可读的stack trace, breakpad需要你将binaries里的调试符号(debugging symbols)转换成基于文本格式的symbol files。
3、接着运行 dump_syms 命令来生成 symbol files,如下:$ google-breakpad/src/tools/linux/dump_syms/dump_syms ./test > test.sym
4、breakpad包含一个叫做 minidump_stackwalk 的 工具 来将 minidump 文件,外加symbol files来生成一个人可读的stack trace
5、$ google-breakpad/src/processor/minidump_stackwalk minidump.dmp test.sym > test.txt
6、test.txt就是最终生成的可读的异常文件用于分析
Linux公社的RSS地址: https://www.linuxidc.com/rssFeed.aspx
本文永久更新链接地址: https://www.linuxidc.com/Linux/2018-09/154032.htm
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Programming Python
Mark Lutz / O'Reilly Media / 2006-8-30 / USD 59.99
Already the industry standard for Python users, "Programming Python" from O'Reilly just got even better. This third edition has been updated to reflect current best practices and the abundance of chan......一起来看看 《Programming Python》 这本书的介绍吧!
HTML 压缩/解压工具
在线压缩/解压 HTML 代码
Markdown 在线编辑器
Markdown 在线编辑器