Hello 試用 breakpad (linux)

來源:互聯網
上載者:User

標籤:調試

試用了一下 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)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.