Google Breakpad之七,android平台簡明用法

來源:互聯網
上載者:User

google breakpad android簡易使用方法:
breakpad是一個跨平台的c++崩潰處理系統。
包括:dmp產生模組、 上傳模組、 伺服器儲存模組、解析dmp模組 等。

初級只使用dmp產生模組,再加上手動分析dmp即可。
1、編譯靜態庫
解壓並拷貝breakpad源碼目錄到項目中,編譯:
./configure --host=arm-linux-androideabi
make -j2

產生的庫是:
src/client/linux/libbreakpad_client.a

2、源碼中include標頭檔:
#include "client/linux/handler/exception_handler.h"
然後在源碼中加入:
#ifdef USE_DUMP
#ifdef __linux__//下面是linux下的聲明方法,其他平台有所不同
 google_breakpad::MinidumpDescriptor descriptor("/");//dmp產生的目錄
 google_breakpad::ExceptionHandler eh(descriptor,
  NULL,
  NULL,
  NULL,
  true,
  -1);
#endif
#endif

ExceptionHandler的變數eh在範圍內有效。
比如在main的最開始就加上這兩行,那麼在整個程式生命週期的異常crash皆可被捕獲。

3、修改Android.mk檔案,通過USE_DUMP宏可控制是否產生帶breakpad的項目版本

確保Application.mk裡有APP_STL設定,STLport 或者 GNU libstdc++,然後
在   LOCAL_CFLAGS += \
最後加上一行-DUSE_DUMP
比如:
   LOCAL_CFLAGS += \
      -DANDROID_SDK \
      -DUSE_DUMP

在LOCAL_STATIC_LIBRARIES := \
代碼塊後加上一行:

LOCAL_STATIC_LIBRARIES += breakpad_client

在mk檔案末尾加上:
include ./jni/src/common/breakpad/android/google_breakpad/Android.mk

4、編譯專案檔
ndk-build
注意obj檔案夾裡的專案檔是帶符號資訊的,lib檔案夾裡的不帶,
所以cp出obj裡的檔案,部署到測試環境,程式死掉時會產生dmp檔案。

5、dmp檔案解析

把src/processor/minidump_stackwalk用adb push 到android裝置上,比如/目錄,然後chmod一下
src/tools/linux/dump_syms/dump_syms同上
解析dmp檔案,比如test是我的專案檔,5ee28168-f798-caba-749b962b-312eaf19.dmp 是掛掉後的dmp檔案
./dump_syms ./test > test.sym
busybox head -n1 test.sym
螢幕顯示:
MODULE Linux arm 6EDC6ACDB282125843FD59DA9C81BD830 test
然後:
mkdir -p ./symbols/test/6EDC6ACDB282125843FD59DA9C81BD830
mv test.sym ./symbols/test/6EDC6ACDB282125843FD59DA9C81BD830
./minidump_stackwalk 5ee28168-f798-caba-749b962b-312eaf19.dmp ./symbols

螢幕顯示堆棧資訊:
Operating system: Linux
                   0.0.0 Linux 2.6.32-279.11.1.el6.x86_64 #1 SMP Tue Oct 16 15:57:10 UTC 2012 x86_64
 CPU: amd64
      family 6 model 42 stepping 7
      1 CPU

Crash reason:  SIGSEGV//掛掉類型
Crash address: 0x0

Thread 0 (crashed)//掛掉線程id
  0  test!crash() [test.cc : 10 + 0x4]//代碼:   *a = 1; //a是一個int*的指標,值為NULL,給NULL賦值1,掛在源碼的第10行,從左至右第四個字元的位置掛了,即a。
    rbx = 0x00007fff6c4b8a90   r12 = 0x0000000000401a00
     r13 = 0x00007fff6c4b8bc0   r14 = 0x0000000000000000
     r15 = 0x0000000000000000   rip = 0x0000000000401b2d
     rsp = 0x00007fff6c4b89e0   rbp = 0x00007fff6c4b89e0
     Found by: given as instruction pointer in context
  1  test!main [test.cc : 16 + 0x4]
     rbx = 0x00007fff6c4b8a90   r12 = 0x0000000000401a00
     r13 = 0x00007fff6c4b8bc0   r14 = 0x0000000000000000
     r15 = 0x0000000000000000   rip = 0x0000000000401c29
     rsp = 0x00007fff6c4b89f0   rbp = 0x00007fff6c4b8ae0
     Found by: call frame info
  2  libc-2.12.so + 0x1ecdc
     rbx = 0x0000000000000000   r12 = 0x0000000000401a00
     r13 = 0x00007fff6c4b8bc0   r14 = 0x0000000000000000
     r15 = 0x0000000000000000   rip = 0x0000003d64e1ecdd
     rsp = 0x00007fff6c4b8af0   rbp = 0x0000000000000000
     Found by: call frame info
  3  test!crash() [test.cc : 11 + 0x1]
     rip = 0x0000000000401b35   rsp = 0x00007fff6c4b8b10
     Found by: stack scanning

Loaded modules:
 0x00400000 - 0x00412fff  test  ???  (main)
 0x3d64a00000 - 0x3d64a1ffff  ld-2.12.so  ???
 0x3d64e00000 - 0x3d6518dfff  libc-2.12.so  ???
 0x3d65600000 - 0x3d65818fff  libpthread-2.12.so  ???
 0x3d65a00000 - 0x3d65c83fff  libm-2.12.so  ???
 0x3d6a600000 - 0x3d6a815fff  libgcc_s-4.4.6-20120305.so.1  ???
 0x3d6c600000 - 0x3d6c8f0fff  libstdc++.so.6.0.13  ???
 0x7fff6c4f9000 - 0x7fff6c4f9fff  linux-gate.so  ???

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.