Windows下 breakpad编译(1)

来源:互联网 发布:韩版note8网络制式 编辑:程序博客网 时间:2024/06/06 17:16

再来一个google自带光环的开源库:Google Breakpad

什么是Google Breakpad?

Google Breakpad is a cross platform crash handler which generates minidumps when your application crash. Users can send these minidumps to you and it contains valuable information allowing you to figure out why it crashed on them.

看到了吗?是当你程序崩溃的时候产生一个minidumps文件的,之前我们也写过两篇博客: 
《windows客户端开发–让你的客户端崩溃之前生成dump文件》

《Qt–让你的客户端崩溃之前生成dump文件》

获取BreakPad

git clone https://chromium.googlesource.com/breakpad/breakpad
  • 1
  • 1

安装Python 
这里面略过了,但是记住要使用Python2.x,,Python3.x会报错

什么是gyp 
GYP(Generate Your Projects)是由 Chromium 团队开发的跨平台自动化项目构建工具,Chromium 便是通过 GYP 进行项目构建管理。

获取gyp

git clone https://chromium.googlesource.com/external/gyp
  • 1
  • 1

安装gyp

cd gyppython setup.py install
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

这里写图片描述

拷贝gyp文件夹到breakpad\src\tools文件夹下 
这里写图片描述

生成Breakpad的sln文件 
进入刚刚拷贝的gyp目录,然后执行: 
gyp.bat –no-circular-check “../../client/windows/breakpad_client.gyp”

wangs@LAPTOP-MNU6522J MINGW64 /d/chromium/src/breakpad/src/tools/gyp (master)$ gyp.bat --no-circular-check "../../client/windows/breakpad_client.gyp"Warning: Missing input files:..\..\client\windows\unittests\..\..\..\testing\src\gmock-all.cc..\..\client\windows\unittests\..\..\..\testing\gtest\src\gtest-all.cc..\..\client\windows\unittests\..\..\..\testing\src\gmock_main.cc
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

这里要注意,一定不能使用绝对路径,要使用相对路径,所以为什么要拷贝gyp文件夹到tools文件夹下面。 
这里写图片描述 
使用vs2015编译 
刚才我看看到了提示,missing几个文件,所以我们这里不能编译unittest下的两个工程,暂时不理会 
这里写图片描述

错误: 
2>C:\Program Files (x86)\Windows Kits\8.1\Include\um\dbghelp.h(1544): error C2220: 警告被视为错误 - 没有生成“object”文件 
2>C:\Program Files (x86)\Windows Kits\8.1\Include\um\dbghelp.h(1544): warning C4091: “typedef ”: 没有声明变量时忽略“”的左侧 
2>C:\Program Files (x86)\Windows Kits\8.1\Include\um\dbghelp.h(3190): warning C4091: “typedef ”: 没有声明变量时忽略“”的左侧 
4>C:\Program Files (x86)\Windows Kits\8.1\Include\um\dbghelp.h(1544): error C2220: 警告被视为错误 - 没有生成“object”文件 
4>C:\Program Files (x86)\Windows Kits\8.1\Include\um\dbghelp.h(1544): warning C4091: “typedef ”: 没有声明变量时忽略“”的左侧 
4>C:\Program Files (x86)\Windows Kits\8.1\Include\um\dbghelp.h(3190): warning C4091: “typedef ”: 没有声明变量时忽略“”的左侧

解决方案,把警告当错误 选择否。

编译后,在debug文件夹下: 
这里写图片描述

使用Breakpad生成dump文件 
前戏有点复杂,现在开始使用。把之前生成的几个lib,包含进来 
common.lib 
exception_handler.lib 
crash_generation_server.lib 
crash_generation_client.lib

头文件目录导进来: 
这里写图片描述

编写代码:

#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;}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

可能的错误: 
common.lib(guid_string.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MTd_StaticDebug”不匹配值“MDd_DynamicDebug”(main.obj 中)

解决方法: 
就是编译库的时候 和现在使用库的工程 选择的代码生成方式不一致: 
这里写图片描述

如何根据生成的dump定位错误代码 
文件->打开->文件,找到刚生成的dump文件,然后点击“使用仅限本机进行调试” 
这里写图片描述

结果: 
这里写图片描述
准确定位!!!!

0 0