windows下dump捕获 crashpad

前言:

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的原因

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值