qt嵌入式编译参数(QT使用GoogleBreakpad)

我们用QT 开发windows 应用程序,有的时候程序发生了crash ,光靠log 有的时候无法找到问题,很多时候应用程序给到其他的人使用,尤其是一些偶发的问题很难复现,这个时候我们就需要一些其他的方式来解决问题。Google 的开源项目breakpad 给我了一个很好的分析问题的方法。

breakpad 的基本介绍可以参考网上的一些文章,本文介绍在QT 中使用breakpad 的方法以及一些需要注意的地方。

Google Breakpad安装和编译(Windows)

  1、 下载Google breakpad源代码(https://github.com/google/breakpad)

  2、 安装python(2.7版本可用)

  3、 生成Windows工程文件

qt嵌入式编译参数(QT使用GoogleBreakpad)(1)

图一

编译源码可以的到相关的lib 文件,unittest 工程编译失败不影响使用。

qt嵌入式编译参数(QT使用GoogleBreakpad)(2)

图二

breakpad src 文件夹下的头文件在使用的时候需要用到。

qt嵌入式编译参数(QT使用GoogleBreakpad)(3)

图三

我们的QT 工程需要做一些设置,首先分析问题需要生产pdb 文件,所以开启相关的配置

QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO

includePATH = $$PWD/include/breakpad LIBS = -L$$PWD/include/breakpad/lib -lException_handler -lcommon -lcrash_generation_client -lcrash_generation_server -lcrash_report_sender (把生成的lib copy到lib的文件夹中,自己新建了一个breakpad 的文件夹里面放入lib 和一些头文件)

QT 中使用lib和头文件

#include "mainwindow.h" #include <QApplication> #include <QDir> #include<QtDebug> #include"client/windows/handler/exception_handler.h" using namespace::google_breakpad; using namespace std; static bool MinidumpCallback(const wchar_t* dump_path, const wchar_t* id, void* context, EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion, bool succeeded) { Q_UNUSED(context) Q_UNUSED(assertion) Q_UNUSED(exinfo) if (succeeded) { printf("dump guid is %ws\n", id); printf("dump guid is %ws\n", dump_path); qDebug()<<"dump_path:"<<dump_path<<" dump guid is:"<<id; } return succeeded; } QString SetupBreakPad(const QString& path) { QString absPath = path; if(!QDir::isAbsolutePath(absPath)) { absPath = QDir::cleanPath(qApp->applicationDirPath() "/" path); } Q_ASSERT(QDir::isAbsolutePath(absPath)); QDir().mkpath(absPath); if (!QDir().exists(absPath)) { qDebug("Failed to set dump path which not exists: %s", qPrintable(absPath)); return NULL; } return absPath; } int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); QString dumpPath=SetupBreakPad("dump"); google_breakpad::ExceptionHandler * eh = new google_breakpad::ExceptionHandler( dumpPath.toStdWString(), NULL, MinidumpCallback, NULL, google_breakpad::ExceptionHandler::HANDLER_ALL); Q_UNUSED(eh) return a.exec(); }

使用比较简单,引用头文件,然后定义一个ExceptionHandler,当工具发生crash 的时候会在指定的文件夹中生成一个dump file,我们可以用windbg 来分析dump 文件找到crash的原因。

breakpad 编译lib的时候需要注意选择MD,保持QT 和lib之间的一致。

qt嵌入式编译参数(QT使用GoogleBreakpad)(4)

图四

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页