CrashPad在Windows下的使用
·
gyp安装
git clone https://chromium.googlesource.com/external/gyp
python setup.py install
检测是否已经安装好,可以在命令行中输入gyp,没有报命令不存在即可。
编译CrashPad
- 使用gyp生成vs项目。
git clone https://chromium.googlesource.com/crashpad/crashpad
gyp --no-circular-check src/client/windows/breakpad_client.gyp
- 打开生成的 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;
更多推荐




所有评论(0)