標籤:調試
試用了一下 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)