简介
breakpad是一组用于实现崩溃报告系统的客户端和服务器组件。c++hromium的breakpad是目前native崩溃捕获中最成熟的方案。它是一套完整的工具集,从crash的捕获到crash的dump,都提供了相对应的工具。它记录了崩溃时的.dump文件,无论我们是在本地或者发送到服务器端,都可以用相对应的工具来解析.dump文件帮助我们查找c和c++堆栈踪迹。
工作原理:

breakpad:GitHub - google/breakpad: Mirror of Google Breakpad project
编译安装linux平台下
linux的编译安装稍简单些。
LSS:linux-syscall-support: clickhouse submodule sentry-native submodulehttps://chromium.googlesource.com/linux-syscall-support
1.下载breakpad和LSS源码 2.将LSS中的linux_syscall_support.h移动到breakpad/src/third_party/lss/目录下(没有就自己新建一个) 3.编译,步骤如下
代码语言:javascript代码运行次数:0运行复制<code class="javascript">cd breakpad./configuremakesudo make install# sudo checkinstall</code>
Windows下的安装
稍麻烦些,推荐使用vcpkg安装。
先cd到vcpkg的安装目录,然后执行下条指令,:x64-windows表示安装win64版本。
代码语言:javascript代码运行次数:0运行复制<code class="javascript">./vcpkg install breakpad:x64-windows</code>
因为众所周知的原因,下载可能会很慢。不过有大佬给了国内镜像。
详情查看链接链接:https://blog.csdn.net/jackboos/article/details/105026109
使用breakpad在QT中的测试:
在vcpkg/packages/breakpad_x64-windows中可以找到breakpad的头文件可库。
将breakpad_x64-windows拷贝到项目的同级目录中。
在qt的项目文件.pro中增加以下配置:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/breakpad_x64-windows/lib/ -llibbreakpad -llibbreakpad_clientwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/breakpad_x64-windows/lib/ -llibbreakpad -llibbreakpad_clientelse:unix: LIBS += -L$$PWD/breakpad_x64-windows/lib/ -llibbreakpaINCLUDEPATH += $$PWD/breakpad_x64-windows/includeDEPENDPATH += $$PWD/breakpad_x64-windows/include</code>
接下来一个简单的测试:
代码语言:javascript代码运行次数:0运行复制<code class="javascript">#include <QCoreApplication>#include<QDebug>#include <QDir>#include "breakpad_x64-windows/include/client/windows/handler/exception_handler.h"bool callback(const wchar_t* dump_path, const wchar_t* id, void* context, EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion, bool succeeded) { if (succeeded) { qDebug() << "Create dump file success"; } else { qDebug() << "Create dump file failed"; } return succeeded;}// 触发crash来测试void crash() { volatile int* a = (int*)(NULL); *a = 1;}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); qDebug() << "hello test"; //获取程序当前运行目录 QString appDirPath = QCoreApplication::applicationDirPath() + "/crash"; QDir dir; if (!dir.exists(appDirPath)) { bool res = dir.mkpath(appDirPath); qDebug() << "New mkdir " << appDirPath << " " << res; } google_breakpad::ExceptionHandler eh( L".", NULL, callback, NULL, google_breakpad::ExceptionHandler::HANDLER_ALL); crash(); return a.exec();}</code>运行起来看到已经生成成功啦,生成了文件3af12e91-8dca-4587-b5f3-d13d5cb3d637.dmp
解析dmp文件解析文件可以使用minidump_stackwalk,解析的结果存放到test.txt文件中。
代码语言:javascript代码运行次数:0运行复制<code class="javascript">./minidump_stackwalk.exe test.dmp >test.txt</code>
minidump_stackwalk.exe工具下载,放在我的资源里了,可以直接下载使用。
引用:Breakpad使用(window)_narkang的博客-CSDN博客_breakpad
通过vcpkg编译breakpad并在qt项目中应用,VS编译器_沐大人的博客-CSDN博客
https://blog.csdn.net/qq_17766199/article/details/85716750
https://blog.csdn.net/lm111111/article/details/105623432
通过vcpkg编译breakpad并在qt项目中应用,VS编译器_沐大人的博客-CSDN博客
Breakpad(跨平台crash工具)_奇小葩的博客-CSDN博客_breakpad
Google Breakpad:脱离符号的调试工具-电子头条-EEWORLD电子工程世界
Ubuntu搭建breakpad环境及查看dmp文件_Geroff的博客-CSDN博客_breakpad linux
breakpad尝试 - Leehm - 博客园
breakpad的正确编译和常规用法 - 简书
以上就是Breakpad跨平台crash捕获和生成工具使用的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号