博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Build BreakPad on Linux program---保存一下
阅读量:6655 次
发布时间:2019-06-25

本文共 4690 字,大约阅读时间需要 15 分钟。

LinuxStarterGuide
  
A quick overview of using Breakpad on Linux
  ,
 
Updated
 
Oct 11, 2012
 by
 

How To Add Breakpad To Your Linux Application

 

 

This document is an overview of using the Breakpad client libraries on Linux.

Building the Breakpad libraries

Breakpad provides an Autotools build system that will build both the Linux client libraries and the processor libraries. Running ./configure && make in the Breakpad source directory will produce src/client/linux/libbreakpad_client.a, which contains all the code necessary to produce minidumps from an application.

Integrating Breakpad into your Application

First, configure your build process to link libbreakpad_client.a into your binary, and set your include paths to include the src directory in thegoogle-breakpad source tree. Next, include the exception handler header:

#include"client/linux/handler/exception_handler.h"

Now you can instantiate an ExceptionHandler object. Exception handling is active for the lifetime of the ExceptionHandler object, so you should instantiate it as early as possible in your application's startup process, and keep it alive for as close to shutdown as possible. To do anything useful, the ExceptionHandler constructor requires a path where it can write minidumps, as well as a callback function to receive information about minidumps that were written:

staticbool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,                          void* context,                          bool succeeded){
  printf("Dump path: %s\n", descriptor.path());   return succeeded;} void crash(){
  volatileint* a =(int*)(NULL);   *a =1;} int main(int argc,char* argv[]){
  google_breakpad::MinidumpDescriptor descriptor("/tmp");   google_breakpad::ExceptionHandler eh(descriptor,                                        NULL,                                        dumpCallback,                                        NULL,                                        true,                                        -1);   crash();   return0;}

Compiling and running this example should produce a minidump file in /tmp, and it should print the minidump filename before exiting. You can read more about the other parameters to the ExceptionHandler constructor .

Note: You should do as little work as possible in the callback function. Your application is in an unsafe state. It may not be safe to allocate memory or call functions from other shared libraries. The safest thing to do is fork and exec a new process to do any work you need to do. If you must do some work in the callback, the Breakpad source contains , to avoid calling directly into libc, as well as  (in src/third_party/lss) to avoid calling into other shared libraries.

Sending the minidump file

In a real application, you would want to handle the minidump in some way, likely by sending it to a server for analysis. The Breakpad source tree contains  that you might find useful, as well as .

Producing symbols for your application

To produce useful stack traces, Breakpad requires you to convert the debugging symbols in your binaries to . First, ensure that you've compiled your binaries with -g to include debugging symbols. Next, compile the dump_syms tool by running configure && make in the Breakpad source directory. Next, run dump_syms on your binaries to produce the text-format symbols. For example, if your main binary was named test:

$ google-breakpad/src/tools/linux/dump_syms/dump_syms ./test > test.sym

In order to use these symbols with the minidump_stackwalk tool, you will need to place them in a specific directory structure. The first line of the symbol file contains the information you need to produce this directory structure, for example (your output will vary):

$ head -n1 test.sym MODULE Linux x86_64 6EDC6ACDB282125843FD59DA9C81BD830 test $ mkdir -p ./symbols/test/6EDC6ACDB282125843FD59DA9C81BD830 $ mv test.sym ./symbols/test/6EDC6ACDB282125843FD59DA9C81BD830

You may also find the  script in the Mozilla repository useful, as it encapsulates these steps.

Processing the minidump to produce a stack trace

Breakpad includes a tool called minidump_stackwalk which can take a minidump plus its corresponding text-format symbols and produce a symbolized stacktrace. It should be in the google-breakpad/src/processor directory if you compiled the Breakpad source using the directions above. Simply pass it the minidump and the symbol path as commandline parameters:

google-breakpad/src/processor/minidump_stackwalk minidump.dmp ./symbols

It produces verbose output on stderr, and the stacktrace on stdout, so you may want to redirect stderr.

转载于:https://www.cnblogs.com/runner42/archive/2013/03/23/2977814.html

你可能感兴趣的文章
java 结构式cas 插件_单点登录终极方案之 CAS 应用及原理
查看>>
java 9 jigsaw_[译]Java 9一步步迁移项目到Jigsaw(模块化)
查看>>
java date 今天凌晨_java获取整点与凌晨的时间戳
查看>>
java i 报表设计器,FineReport报表设计器(UI)
查看>>
php数字最大值和最小值,php max() min() 返回最大值和最小值
查看>>
php 获取 所有请求参数错误,curl获取错误信息 php请求api接口方法
查看>>
php构析方法,php面向对象全攻略 (四)构造方法与析构方法
查看>>
php优化是干什么的,PHP优化
查看>>
个是php的,PHP
查看>>
宝塔定时监控cron.php,宝塔Linux面板定时删除网站监控报表日志
查看>>
matlab 图像保存为视频教程,山东大学《数字图像处理(MATLAB)》江铭炎视频教程
查看>>
matlab svm实验,Matlab SVM模式分类方法的实验系统
查看>>
php电商实现流程图,线上电商运营流程绘制流程图分享
查看>>
有关php天气论文概述,关于天气网的10篇文章推荐
查看>>
基于matlab的雷达和通信系统,基于MATLAB的多功能通信信号源仿真
查看>>
python改了代码没有生效,关于python:为什么我在使用这段代码时没有更改列表?...
查看>>
linux下php测试文本,php连接linux命令函数自己测试心得
查看>>
php framework interop group,PHP最佳实践系列之标准
查看>>
oracle中resource权限,Oracle内置角色connect与resource的权限
查看>>
微软 Build 2017 开发者大会:Azure 与 AI 的快速发展
查看>>