日期:2014-05-16  浏览次数:20682 次

Google Breakpad 之二,实战Linux平台本地crash定位。

Linux,今天你的C挂挂程序 挂了没有?

Linux本地程序crash定位处理,发送到服务端以后在介绍。

还是来自Google:http://code.google.com/p/google-breakpad/wiki/LinuxStarterGuide

由于有代码等原因,本人直接按自己理解,白话,E文好的直接点链接看。

怎样把Breakpad加入你的程序呢,E文是母语的直接点连接。

 

  • How To Add Breakpad To Your Linux Application
    • Building the Breakpad libraries
    • Integrating Breakpad into your Application
    • Sending the minidump file
    • Producing symbols for your application
    • Processing the minidump to produce a stack trace

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

先编译库

源码目录下运行 

./configure && make

 生成 src/client/linux/libbreakpad_client.a

把Breakpad整合进程序

首先,把libbreakpad_client.a链接进你的程序,把src目录include进去,诸如:(g++ -g test.cc -I. -L./client/linux/ -lbreakpad_client -lpthread -o test)。

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

在程序刚开始的时候实例化google_breakpad::MinidumpDescriptor和google_breakpad::ExceptionHandler 这两个东东。dump目录可改,dump时可设回调来获取dump信息,示例代码如下:

static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,
                         void* context,
                         bool succeeded)
{
  printf("Dump path: %s\n", descriptor.path());
  return succeeded;
}

void crash()
{
  volatile int* a = (int*)(NULL);
  *a = 1;
}


int main(int argc, char* argv[])
{
  google_breakpad