环境:Windows10 qtcreator5.14 Debugging Tools for Windows(X64+X86)
源码:qBreakpad Breakpad LSS(linux-syscall-support)
1.将qBreakpad下载解压
将Breakpad下载解压
将Linux Syscall Support下载解压
将Breakpad解压的文件放到qBreakpad下third_party下的breakpad下,将Linux Syscall Support解压的文件放到qBreakpad下third_party下的lss下。
2.qBreakpad的编译方法
用Qtcreator打开qBreakpad-master\handler\handler.pro单独编译
编译运行后获得qBreakpad.lib
3.测试
打开Qtcreator新建一个项目
在项目路径下新建文件夹3rdparty,并且把qBreakpad-master项目拷贝到3rdparty下,修改文件名为qBreakpad
修改项目配置文件
############
#qBreakpad
############
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testCrash
TEMPLATE = app
#config for qBreakpad
#CONFIG -= app_bundle #配置上这个参数以后 你的图形界面程序就会以命令行方式运行,
CONFIG += warn_on
CONFIG += thread exceptions rtti stl
macx: LIBS += -framework AppKit
#without c++11 & AppKit library compiler can't solve address for symbols
CONFIG += c++11
#link qBreakpad library
include($$PWD/3rdparty/qBreakpad/qBreakpad.pri)
#end of config for qBreakpad
修改main.cpp
#include "widget.h"
#include <QApplication>
#include "QBreakpadHandler.h"
void crash()
{
volatile int* a = (int*)(NULL);
*a = 1;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// 设置生成dump文件路径
QBreakpadInstance.setDumpPath(QLatin1String("crashes"));
Widget w;
w.show();
crash();
return a.exec();
}
测试运行,生成.dmp文件
///
linux下测试运行
用Qtcreator打开qBreakpad-master/handler/handler.pro单独编译,生成Linux库文件
新建一个linux的Qt项目,同样是新建一个3rdparty文件,将qBreakpad项目包含进去
修改项目配置文件
#-------------------------------------------------
#
# Project created by QtCreator 2021-09-02T10:59:09
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Test_qBreakpad
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
main.cpp \
widget.cpp
HEADERS += \
widget.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
############
#qBreakpad
############
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testCrash
TEMPLATE = app
#config for qBreakpad
#CONFIG -= app_bundle #配置上这个参数以后 你的图形界面程序就会以命令行方式运行,
CONFIG += warn_on
CONFIG += thread exceptions rtti stl
macx: LIBS += -framework AppKit
#without c++11 & AppKit library compiler can't solve address for symbols
CONFIG += c++11
#link qBreakpad library
include($$PWD/3rdparty/qBreakpad/qBreakpad.pri)
#end of config for qBreakpad
修改main.cpp
#include "widget.h"
#include <QApplication>
#include "QBreakpadHandler.h"
void crash()
{
volatile int* a = (int*)(NULL);
*a = 1;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// 设置生成dump文件路径
QBreakpadInstance.setDumpPath(QLatin1String("crashes"));
Widget w;
w.show();
crash();
return a.exec();
}
编译运行,获得一个.dmp文件