前言:
windows 下应用程序 肯定离不开crash , crash 不怕, 可怕的是不知道怎么复现 没有相关的头绪
所有dump文件很重要帮助我们分析定位问题
crashpad
本篇介绍使用 crashpad 来进行dump 的捕获
怎么使用呢?
crashpad 的介绍这里也不提了
肯定要编译了 这里就不介绍怎么编译 因为我直接提供了 编译好的 include + lib + pdb
放到 github了
点我进行下载
配置使用 crashpad
拿vs 2019 举例 属性 -> c/c++ 常规 加入 crashpad/include
链接器 -> 输入
crashpad\lib\win32\based.lib
crashpad\lib\win32\clientd.lib
crashpad\lib\win32\utild.lib
crashpad\lib\win32\client.lib
crashpad\lib\win32\util.lib
这样就配置好了
代码中使用 crashpad
#include <client/crash_report_database.h>
#include <client/settings.h>
#include <client/crashpad_client.h>
bool initCrashPad()
{
using namespace crashpad;
std::map<std::string, std::string> annotations;
std::vector<std::string> arguments;
//改为自己的crashpad_handler.exe 路径
QString exePath = exeDir + QDir::separator() + "crashpad_handler.exe";
std::string url("http://127.0.0.1:8000");
arguments.push_back("--no-rate-limit");
//放dump的文件夹 按需改
base::FilePath db(crashDirPath.toStdWString());
//crashpad_handler.exe 按需改
base::FilePath handler(exePath.toStdWString());
std::unique_ptr<CrashReportDatabase> database =
crashpad::CrashReportDatabase::Initialize(db);
if (database == nullptr || database->GetSettings() == NULL)
{
LOG(ERROR) << "CrashReportDatabase Init Error";
return false;
}
database->GetSettings()->SetUploadsEnabled(true);
CrashpadClient client;
bool ret = client.StartHandler(handler,
db,
db,
url,
annotations,
arguments,
true,
true);
if (ret == false)
{
return false;
}
ret = client.WaitForHandlerStart(INFINITE);
if (ret == false)
{
LOG(ERROR) << "CrashpadClient Start Error";
return false;
}
return true;
}
ok 这样就可以了 , 简单的测试一个崩溃
就会生成一个dump
dump 就生成了, 我们可以根据dump 看堆栈 查找dump的原因