一、概述
breakpad是google开源的一套用于进程crash的处理方案,跨平台。
但由于现在有沙盒技术,会导致breakpad无法生成dump,所以google又开发了一个crashpad项目,用来替代breakpad。
二、直接编译
不想自己弄这些的可以下载直接可以编译的源码:https://download.csdn.net/download/Carry_Qt/21541033
三、体验流程
1、源码下载(能访问googlesource访问googlesource,不能的github上找吧)
breakpad (crash库源码): https://github.com/google/breakpad
gyp(chromium开发的跨平台自动化项目构建工具):https://github.com/chromium/gyp
google test:https://github.com/google/googletest
python 2.7.x:https://www.python.org/downloads/release/python-2718/
2、在breakpad\src下新建testing目录,将gtest解压后的googlemock和googletest拷贝到新建的testing下
3、使用gyp生成sln文件:tools\gyp\gyp.bat --no-circular-check client\windows\breakpad_client.gyp
成功后在\client\windows\目录下有生成的breakpad_client.sln vs工程文件
四、vs工程设置
1、右键项目名(如crash_generation_client),属性 -> C/C++ -> 常规 -> 把右侧的“将警告视为错误”选项选为否
2、debug构建:属性 -> C/C++ -> 代码生成 -> 运行库 -> 多线程调试dll(/MDd)
3、release构建:属性 -> C/C++ -> 代码生成 -> 运行库 -> 多线程DLL(/MD)
五、项目使用
1、链接库:
common.lib
exception_handler.lib
crash_generation_server.lib
crash_generation_client.lib
包含路径:breakpad/client breakpad/common breakpad/google_breakpad
2、代码测试:
#include <cstdio>
#include "client/windows/handler/exception_handler.h"
namespace {
static bool callback(const wchar_t *dump_path, const wchar_t *id,
void *context, EXCEPTION_POINTERS *exinfo,
MDRawAssertionInfo *assertion,
bool succeeded) {
if (succeeded) {
printf("dump guid is %ws\n", id);
}
else {
printf("dump failed\n");
}
fflush(stdout);
return succeeded;
}
static void CrashFunction() {
int *i = reinterpret_cast<int*>(0x45);
*i = 5; // crash!
}
} // namespace
int main(int argc, char **argv) {
google_breakpad::ExceptionHandler eh(
L".", NULL, callback, NULL,
google_breakpad::ExceptionHandler::HANDLER_ALL);
CrashFunction();
printf("did not crash?\n");
return 0;
}
3、在生成路径中找到dump文件,然后用vs打开dump文件,点击使用 仅限本机 进行调试,可以看到错误详情及错误具体发生在哪行代码。
六、常见错误
1、common.lib(guid_string.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MTd_StaticDebug”不匹配值“MDd_DynamicDebug”(main.obj 中)
2、release模式下没有调式信息
qt工程
# QMAKE *.pro-file: enable debugging info in release mode
#
# gcc
#QMAKE_CXXFLAGS_RELEASE += -O0 -g
#QMAKE_CFLAGS_RELEASE += -O0 -g
#QMAKE_LFLAGS_RELEASE =
# msvc
QMAKE_CXXFLAGS_RELEASE += /Zi
QMAKE_CXXFLAGS_RELEASE += /Od
QMAKE_LFLAGS_RELEASE += /DEBUG
# DEFINES +=QT_NO_DEBUG_OUTPUT # disable debug output
DEFINES -=QT_NO_DEBUG_OUTPUT # enable debug output
INCLUDEPATH += $$PWD/3rd/breakpad/include
DEPENDPATH += $$PWD/3rd/breakpad
vs工程
属性 -> 链接器 -> 调试 -> 调试信息 -> 优化以便于调试 (/DEBUG)
七、参考博客
https://blog.csdn.net/wangshubo1989/article/details/53334033
https://blog.csdn.net/ljttianqin/article/details/78472613
https://blog.csdn.net/bingzhongdehuoyan/article/details/53860433