怎样快速的定位错误:

view call stack of crashed application on android

On android, when a process crashes in native code, the call stack of the process will be saved to a log file in /data/tombstomes/, and written to logcat as well. The information is helpful for debugging.
Unfortunately, the call stack doesn't show in human readable format, file name, function name. Instead, it's shown as module name (e.g., libc.so) and memory address of the instruction. We can use addr2line to translate the address to corresponding file name and function name if we have the binary of the module that contains symbol information.
To make it easier to use, this function is included in agdb tool(see herefor more). We can use "agdb.py -r -e module_name address"to find out the function name of specified address within the module.

When we have a long call stack, instead of running the command above for each line in the call stack manually, we can feed the whole call stack to agdb through pipe and get the full resolved call stack. For example, use "adb logcat | agdb.py -r"command for adb logcat output with below contents:

22F/ASessionDescription( 33): frameworks/base/media/libstagefright/rtsp/ASessionDescription.cpp:264 CHECK_GT( end,s) failed:vs.
23I/DEBUG ( 30): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
24I/DEBUG ( 30): Build fingerprint: 'generic/generic/generic:2.3.1/GINGERBREAD/eng.raymond.20101222.130550:eng/test-keys'
25I/DEBUG ( 30): pid: 33, tid: 450>>> /system/bin/mediaserver <<<
26I/DEBUG ( 30): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
27I/DEBUG ( 30):r0 deadbaadr1 0000000cr2 00000027r3 00000000
28I/DEBUG ( 30):r4 00000080r5 afd46668r6 40806c10r7 00000000
29I/DEBUG ( 30):r8 8031db1dr9 0000fae010 00100000fp 00000001
30I/DEBUG ( 30):ip ffffffffsp 40806778lr afd19375pc afd15ef0cpsr 00000030
31 I/DEBUG ( 30): #00pc 00015ef0/system/lib/libc.so
32 I/DEBUG ( 30): #01pc 00001440/system/lib/liblog.so
33I/DEBUG ( 30):
34I/DEBUG ( 30): code around pc:
35I/DEBUG ( 30): afd15ed0 68241c23 d1fb2c00 68dae027 d0042a00
36I/DEBUG ( 30): afd15ee0 20014d18 6028447d 48174790 24802227
37I/DEBUG ( 30): afd15ef0 f7f57002 2106eb56 ec92f7f6 0563aa01
38I/DEBUG ( 30): afd15f00 60932100 91016051 1c112006 e818f7f6
39I/DEBUG ( 30): afd15f10 2200a905 f7f62002 f7f5e824 2106eb42
40I/DEBUG ( 30):
41I/DEBUG ( 30): code around lr:
42I/DEBUG ( 30): afd19354 b0834a0d 589c447b 26009001 686768a5
43I/DEBUG ( 30): afd19364 220ce008 2b005eab 1c28d003 47889901
44I/DEBUG ( 30): afd19374 35544306 d5f43f01 2c006824 b003d1ee
45I/DEBUG ( 30): afd19384 bdf01c30 000281a8 ffffff88 1c0fb5f0
46I/DEBUG ( 30): afd19394 43551c3d a904b087 1c16ac01 604d9004
47I/DEBUG ( 30):
48I/DEBUG ( 30): stack:
49........................
92I/DEBUG ( 30): 408067e46f697470
93I/BootReceiver( 75): Copying /data/tombstones/tombstone_09 to DropBox (SYSTEM_TOMBSTONE)
we get:


22F/ASessionDescription( 33): frameworks/base/media/libstagefright/rtsp/ASessionDescription.cpp:264 CHECK_GT( end,s) failed:vs.
23I/DEBUG ( 30): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
24I/DEBUG ( 30): Build fingerprint: 'generic/generic/generic:2.3.1/GINGERBREAD/eng.raymond.20101222.130550:eng/test-keys'
25I/DEBUG ( 30): pid: 33, tid: 450>>> /system/bin/mediaserver <<<
26I/DEBUG ( 30): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
27I/DEBUG ( 30):r0 deadbaadr1 0000000cr2 00000027r3 00000000
28I/DEBUG ( 30):r4 00000080r5 afd46668r6 40806c10r7 00000000
29I/DEBUG ( 30):r8 8031db1dr9 0000fae010 00100000fp 00000001
30I/DEBUG ( 30):ip ffffffffsp 40806778lr afd19375pc afd15ef0cpsr 00000030
31 I/DEBUG ( 30): #00pc 00015ef0/system/lib/libc.so
32 I/DEBUG ( 30):#00__libc_android_abort: abort.c:82
33 I/DEBUG ( 30): #01pc 00001440/system/lib/liblog.so
34 I/DEBUG ( 30):#01__android_log_assert: logd_write.c:235
35I/DEBUG ( 30):
36I/DEBUG ( 30): code around pc:
37I/DEBUG ( 30): afd15ed0 68241c23 d1fb2c00 68dae027 d0042a00
38I/DEBUG ( 30): afd15ee0 20014d18 6028447d 48174790 24802227
39I/DEBUG ( 30): afd15ef0 f7f57002 2106eb56 ec92f7f6 0563aa01

Similarly, we can use"echo tombstone_01.txt | agdb.py -r"command to resolve call stack addresses in a tombstone log file.

调试工具的使用:

utility for debugging android native application

agdbis a utility aims to ease the task of debugging android native application. Its working mechanism is similar to ndk-gdb. But it's intended to assist debugging native applications in android source tree, not for application created with ndk.

It does following things for us automatically:
find the binary that contains symbol data of target processattach gdbserver to the target process on device, or start the target process under gdbserver if the process isn't already runningstart gdb client and set correct symbol file search path How to use it
prerequirements
agdb must know the root directory of android source code. We can tell it by passing --android-src-rootargument or setting ANDROID_SRC_ROOTenvironment variable.
agdb interacts with target device through adb, so the device must be accessible through adb.
gdb client communicates gdbserver through tcp protocol (tcp port 7890 by default). If using emulator, we need to forward or redir tcp portsin advance.

usage
After all prequirements are met, we can run "agdb.py process_name" to debug desired application. For example, if we want to debug mediaserver application, simply run agdb.py mediaserver.
If we want to debug code in native part of a dalvik (java) application, we can use:
agdb.py --dalvik [package_name (for example, com.android.launcher)]


Limitation
It doesn't work on Windows.
It starts gdbserver in network communication mode, serial port isn't supported.
It doesn't support dalvik application.

Reference
http://source.android.com/porting/debugging_gdb.html
文章来源: http://rxwen.blogspot.com/2011/01/resolve-stack-trace-of-crashed.html http://rxwen.blogspot.com/2011/01/utility-for-debugging-android-native.html

转自:http://hi.baidu.com/runsheng2005/blog/item/10022ecd2da035450eb34552.html

更多相关文章

  1. Android启动后遇到错误
  2. Android(安卓)R
  3. Android(安卓)定时到服务器取数据并刷新
  4. Android(安卓)基于4G模块 GPS定位
  5. Android(安卓)Native Crash的log分析和定位
  6. android使用ksoap2-android调用webservice时报java.io.EOFExcept
  7. Android(安卓)邮箱验证
  8. android gps开发必备资料(含测试demo下载)
  9. Android获取不到ID

随机推荐

  1. cocos2dx在Android下如何接入91SDK
  2. Android自动隐藏键盘
  3. Android(安卓)Gradle 学习 一
  4. Android输入法框架系统(下)
  5. Android(安卓)ClassLoader
  6. [Android] 关于系统工具栏和全屏沉浸模式
  7. 【Android(安卓)内存优化】Bitmap 长图加
  8. Android之VideoView 进行播放视频
  9. Android程序架构基本内容概述
  10. Android(安卓)底层开发概述(四)