CrashPad在Windows下的使用

gyp安装

git clone https://chromium.googlesource.com/external/gyp
python setup.py install

检测是否已经安装好,可以在命令行中输入gyp,没有报命令不存在即可。

编译CrashPad

  1. 使用gyp生成vs项目。
git clone https://chromium.googlesource.com/crashpad/crashpad
gyp --no-circular-check src/client/windows/breakpad_client.gyp
  1. 打开生成的 breakpad_client.sln
    右键build_all->生成
    可能会报gtest相关文件找不到等错误,我们这里只用到生成静态库,不需要单元测试,不用理会。
    生成的文件有:
    common.lib,crash_generation_client.lib,crash_generation_server.lib,crash_report_sender.lib,exception_handler.lib,processor_bits.lib

CrashPad的原理

在这里插入图片描述

也就是说,可以创建一个守护程序CrashServer,监控目标程序的启动,退出和crash,当crash时,存储dmp文件到本地。(上图只标明了Crash的情况)

CrashServer的核心代码

项目中依赖common.lib和crash_generation_server.lib

crash_server = new CrashGenerationServer(kPipeName,
		NULL,
		ShowClientConnected,
		NULL,
		ShowClientCrashed,
		NULL,
		ShowClientExited,
		NULL,
		NULL,
		NULL,
		true,
		&dump_path);

其中ShowClientConnected、ShowClientCrashed、ShowClientExited视为客户端连接、Crash、正常退出的回调。

CrashClient的核心代码

handler = new ExceptionHandler(L"C:\\dumps\\",
		NULL,
		ShowDumpResults,
		NULL,
		ExceptionHandler::HANDLER_ALL,
		MiniDumpNormal,
		kPipeName,
		&custom_info);
//空指针赋值错误引发程序崩溃
int* x = 0;
	*x = 1;
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值