使用Google开源库breakpad实现错误报告功能(Windows环境)

本文介绍了如何在Windows环境下使用Google的breakpad开源库来实现错误报告功能。从环境搭建、编译breakpad、部署应用到处理应用程序崩溃,并生成及上传sym文件进行调试,详细讲解了整个流程。
摘要由CSDN通过智能技术生成

layout: post
title: “使用Google开源库breakpad实现错误报告功能(Windows环境)”
subtitle: “Google大法好”
date: “2017-08-16”
author: “cj”
tags:
breakpad
c++
windows
google
bugreport

Windows环境下以前使用的CrashRpt1403错误报告系统出了点问题,问题上传端口(80)被微信服务器测试环境占用了,索性使用breakpad更新之。

目录

  1. 环境搭建
    1. 下载
    2. 编译
  2. 部署
    1. 生成sym并上传
      1. windows-publish
      2. linux-publish
    2. 应用程序植入breakpad
    3. 处理应用程序崩溃
      1. windows-report
      2. linux-report
    4. 邮件示例
  3. 参考资料

环境搭建

下载

按照官方教程,下载源码

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

有几个第三方库默认情况没有下载,按需手动下载到breakpad/src/thirdparty中

cd breakpad
git clone https://chromium.googlesource.com/linux-syscall-support src/third_party/lss

编译

与linux环境下直接configure&&make不同,Windows下需要google另一个工具gyp生成visual studio 的sln文件。另外gyp依赖Python2.x版本,如果系统环境变量PATH中指定的python.exe已经是Python3.x版的话,需要手动修改。Python2.x与3.x共用方案网上一搜大把不再赘述。

安装gyp:

git clone https://chromium.googlesource.com/external/gyp
cd gyp
python setup.py install

生成sln解决方案:

your-path-to-gyp/gyp.bat your-path-to-breakpad/src/client/windows/breakpad_client.gyp --no-circular-check

打开breakpad_client.sln并编译所需的库文件:

  • ommon.lib
  • exception_handler.lib
  • crash_generation_client.lib

部署

在Windows下编译好应用程序后,使用breakpad的工具dump_syms.exe生成sym符号表,并上传至服务器。当客户环境中的应用程序崩溃时,调用一个脚本将dump信息上传至服务器,服务器端处理一下并生成stack walk信息发送到自己的邮箱。思路与上一篇linux版完全一样,只不过生成sym的环境换成了Windows,并增加了web服务以便处理。

下面以分为新版本发布时的“生成sym”和崩溃发生时的“处理dmp”记录一下。

生成sym并上传

新版本发布时,自动生成sym文件并上传

windows-publish

参考了这篇文章,摘录如下:

Decoding Windows crash dumps on Linux

Windows crash dumps can be decoded the same way as Linux crash dumps. The issue is mainly getting the debugging symbols as a .sym file instead of a .pdb file.

To convert a .pdb file to a .sym file:

  1. Obtain the .pdb file and put it on a Windows machine. (It may be possible to do this with Wine, YMMV.)
  2. Download dump_syms.exe.
  3. Run: dump_syms foo.pdb > foo.sym
    • If no error messages, then you are done.
    • If you get: CoCreateInstance CLSID_DiaSource failed (msdia80.dll unregistered?), go to step 4.
  4. Get a copy of msdia80.dll and put it in c:\Program Files\Common Files\Microsoft Shared\VC\.
  5. As Administrator, run: regsvr32 c:\Program Files\Common Files\Microsoft Shared\VC\msdia80.dll.
    • On success, retry step 3.
    • If you get error 0x80004005, you did not run as Administrator.

2020年1月13日23:57:56增补

win10 系统一直报 CoCreateInstance CLSID_DiaSource {3BFCEA48-620F-4B6B-81F7-B9AF75454C7D} failed (msdia*.dll unregistered?) Open failed 错误,按照上述方法注册了 c:\Program Files\Common Files\Microsoft Shared\VC\ 文件夹下存在的 msdia80.dll, msdia90.dll, msdia100.dll,问题依旧。

everything 搜索 msdia,发现一大堆,试着注册了几个,试到 "C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.net.native.compiler\1.7.6\tools\Runtime\x86\msdia120.dll" 的时候成功了。

懒人的解决方案:publish.bat

@echo off
rem 引用dump_sym.exe
set dump_syms="D:\dev_libs\google\breakpad\src\tools\windows\binaries\dump_syms.exe"

rem 需要使用7z进行压缩
set the_7z="..\7-Zip\7z.exe"

rem fciv是Windows发布的一个生成文件MD5值的小工具
set fciv="fciv.exe"

rem 需要使用curl上传文件
set curl="curl.exe"

rem 生成sym
%dump_syms% ..\..\Release\your-app.pdb > your-app.sym

rem 压缩
%the_7z% a publish.7z your-app.sym ..\ChangeLog.txt
del your-app.sym

rem 获取压缩文件MD5值
for /f %%i in ('%fciv% -md5 publish.7z') do set md5=%%i

rem 获取文件版本号
set /p pub_version=<..\..\Release\VersionNo.ini

rem 上传压缩文件至服务器
%curl% -F "action=upload" -F "md5=%md5%" -F "pub_version=%pub_version%" -F "publish=@publish.7z;type=application/7z" https://www.your-domain.com/crash/publish.php

del publish.7z
echo Done!

linux-publish

publish.php

<?php

// Specify the directory where to save error reports
$file_root = "/var/www/html/crash/app/";

// This is to avoid PHP warning
date_default_timezone_set('UTC');

// Writes error code and text message and then exits
function done($return_status, $message)
{
   
    // Write HTTP responce code
    header("HTTP/1.0 ".$return_status." ".$message);
    // Write HTTP responce body (for backwards compatibility)
    echo $return_status." ".$message;
    exit(0);
}

// Checks that text fild doesn't contain inacceptable symbols
function checkOK($field)
{
   
    if (stristr($field, "\\r") || stristr($field, "\\n"))
    {
   
        done(450, "Invalid input parameter.");
    }
}

$md5_hash = "";    // MD5 hash for error report ZIP
$file_name = "";   // Destination file name
$pub_version = "";  // Publish version

// Check that MD5 hash exists
if(!isset($_POST['md5']))
{
   
    done(450, "MD5 hash is missing.");
}

// Get MD5 hash
$md5_hash = $_POST['md5'];
checkOK($md5_hash);
if(strlen($md5_hash)!=32)
{
   
    done(450, "MD5 hash value has wrong length.");
}

// Get CrashGUID
if(!array_key_exists("pub_version", $_POST))
{
   
    done(450, "Publish version missing.");  
}

$pub_version =
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Qt是一种用于开发跨平台图形用户界面的框架,Google Breakpad是一种开源的异常报告。要下载qt google breakpad,首先需要在Qt官方网站上下载Qt框架的安装包。在官网上选择对应的操作系统(例如Windows,Linux,Mac等),然后选择所需的Qt版本(例如Qt5,Qt6等)。下载完成后,运行安装包并按照安装向导的指示进行安装。安装完成后,可以在系统中找到Qt的安装目录。 然后,需要在Google Breakpad的官方网站上下载Breakpad的源代码。在官网上找到源代码下载页面,并选择所需的版本。下载完成后,解压缩文件并进入源代码的目录。 接下来,需要将Breakpad源代码与Qt框架进行配置和构建。通过命令行进入Breakpad源代码目录,在该目录下创建一个新的构建目录,并进入该目录。使用CMake命令来配置Breakpad与Qt的构建。具体的配置命令根据不同的操作系统和需求而定。配置完成后,使用make或ninja等构建工具进行构建。 构建完成后,将生成的Breakpad文件(如libbreakpad.so或breakpad.dll等)与Qt应用程序进行链接。可以在Qt应用程序的.pro文件中添加链接的配置,或者在构建命令中进行链接。完成链接后,重新编译和运行Qt应用程序即可使用Google Breakpad进行异常报告的捕获和处理。 综上所述,下载Qt和Google Breakpad的过程包括下载Qt框架安装包、下载Breakpad源代码、配置和构建Breakpad与Qt的链接,并在Qt应用程序中使用Breakpad进行异常报告的处理。 ### 回答2: QT是一款强大的跨平台应用开发框架,Google Breakpad是一套用于应用程序崩溃报告的开源工具。想要在QT中下载Google Breakpad,可以按照以下步骤进行操作。 首先,在浏览器中搜索"Google Breakpad"并进入官方网站或GitHub页面。在该页面中,可以找到相关的下载链接和文档。 其次,根据自己的操作系统选择合适的版本下载。Google Breakpad支持多种操作系统,如Windows、Linux和Mac OS X等。选择与QT兼容的版本进行下载。 下载完成后,解压缩下载的文件。其中包含了Google Breakpad的源代码和示例程序等。 接下来,可以根据Google Breakpad提供的文档和示例程序进行学习和使用。文档中详细介绍了Google Breakpad使用方法和参数设置等。 最后,根据QT的需求,将Google Breakpad集成到QT应用程序中。通过在QT项目中引入Google Breakpad的代码和相关文件,可以实现应用程序的崩溃报告和分析功能。 总之,下载并集成Google Breakpad到QT中可以帮助开发者更好地追踪和分析应用程序的崩溃问题,提高应用程序的可靠性和稳定性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值