码迷,mamicode.com
首页 > 系统相关 > 详细

Hello 试用 breakpad (linux)

时间:2015-04-01 15:33:08      阅读:379      评论:0      收藏:0      [点我收藏+]

标签:调试

试用了一下 breakpad

breakpad 是一个收集程序crash 信息的系统,与gdb不同的是:gdb适合自己调试crash程序用; 而 breakpad 适合release 后的程序 (收集程序在用户手中运行crash的信息)

技术分享


安装breakpad

别在 github上乱找了(我找了两个都不能编译成功,貌似别人随便放在那里的,没有维护),用svn下载(TMD访问googlecode还要翻墙)

svn checkout http://google-breakpad.googlecode.com/svn/trunk/ google-breakpad-read-only


编译

使用下面的命令,就都编译了好了

mv google-breakpad-read-only google-breakpad

cd google-breakpad; ./configure; make; 


试用

编写程序如下

cat test.cpp   
#include <iostream>
#include "client/linux/handler/exception_handler.h"


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::MinidumpDescriptor descriptor(".");
  google_breakpad::ExceptionHandler eh(descriptor,
                                       NULL,
                                       dumpCallback,
                                       NULL,
                                       true,
                                       -1);
  crash();
  return 0;
}

用命令下面的命令编译

g++ -g -I google-breakpad/src -o test test.cpp google-breakpad/src/client/linux/libbreakpad_client.a -lpthread


运行得到下面的信息

./test 
Dump path: ./2d1b6c3c-169e-a935-6582667f-75b5fac0.dmp
Segmentation fault (core dumped)


参看stack 信息

方法1:

google-breakpad/src/tools/linux/md2core/minidump-2-core 2d1b6c3c-169e-a935-6582667f-75b5fac0.dmp > core


$ gdb ./test core

...
Core was generated by `./test‘.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000000000401f26 in crash () at test.cpp:16
16        *a = 1;
(gdb) 


方法2:

$ google-breakpad/src/tools/linux/dump_syms/dump_syms ./test | head -1
MODULE Linux x86_64 F344E837CC5CA50047E4A236E36FA3BA0 test

$ mkdir -p ./symbols/test/F344E837CC5CA50047E4A236E36FA3BA0

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


$ google-breakpad/src/processor/minidump_stackwalk  2d1b6c3c-169e-a935-6582667f-75b5fac0.dmp symbols/
...
Thread 0 (crashed)
 0  test!crash [test.cpp : 16 + 0x4]
    rax = 0x0000000000000000   rdx = 0x0000000000617280
    rcx = 0x0000000000000000   rbx = 0x0000000000000000
...


本文没有讨论minidump文件的上传和下载    

ref

https://code.google.com/p/google-breakpad/wiki/GettingStartedWithBreakpad

http://jff.googlecode.com/git/notes/google-breakpad-howto.txt

Hello 试用 breakpad (linux)

标签:调试

原文地址:http://blog.csdn.net/span76/article/details/44805497

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!