利用addr2line命令翻译二进制的线性地址到源代码文件的行号
今天遇到libskia.so抛栈的问题,log如下:
01-01 08:05:28.828 2060 2685 D SystemClock: Setting time of day to sec=946742725
01-01 08:05:29.000 1822 2897 F libc : Fatal signal 11 (SIGSEGV) at0x00001eef (code=1), thread 2897 (Binder_6)
01-01 08:05:29.193 2060 2685 D SystemClock: Setting time of day to sec=946742726
01-01 08:05:29.287 763 763 I DEBUG : *** *** *** *** *** *** *** *** ****** *** *** *** *** *** ***
01-01 08:05:29.287 763 763 I DEBUG : Build fingerprint: 'unknown'
01-01 08:05:29.287 763 763 I DEBUG : Revision: '0'
01-01 08:05:29.288 763 763 I DEBUG : pid: 1822, tid: 2897, name:Binder_6 >>> system_server <<<
01-01 08:05:29.288 763 763 I DEBUG : signal 11 (SIGSEGV), code 1(SEGV_MAPERR), fault addr 00001eef
01-01 08:05:29.387 763 763 I DEBUG : r0 419aa4c0 r1 00001eef r2 40391384 r3 00ff00ff
01-01 08:05:29.387 763 763 I DEBUG : r400001eef r5 419aa4c0 r6 000000b3 r7 0010ba60
01-01 08:05:29.387 763 763 I DEBUG : r8ff00ff00 r9 402aff9c sl 00000132 fp 000023b7
01-01 08:05:29.387 763 763 I DEBUG : ip4f679468 sp 5120b530 lr 402f0ab8 pc 402affcc cpsr80000010
01-01 08:05:29.387 763 763 I DEBUG : d0 7149f2ca7149f2ca d1 c0b000007149f2ca
01-01 08:05:29.387 763 763 I DEBUG : d2 3f00000042000000 d3 3f00000000000000
01-01 08:05:29.387 763 763 I DEBUG : d4 fffffffa00000000 d5 c0b00000c0c00000
01-01 08:05:29.387 763 763 I DEBUG : d6 3f000000c0c00000 d7 0000000000000000
01-01 08:05:29.387 763 763 I DEBUG : d8 0000014a3f000000 d9 000000b3fffffffa
01-01 08:05:29.387 763 763 I DEBUG : d100000000000000000 d11 0000000000000000
01-01 08:05:29.388 763 763 I DEBUG : d120000000000000000 d13 0000000000000000
01-01 08:05:29.388 763 763 I DEBUG : d140000000000000000 d15 0000000000000000
01-01 08:05:29.388 763 763 I DEBUG : scr 20000010
01-01 08:05:29.395 763 763 I DEBUG :
01-01 08:05:29.395 763 763 I DEBUG : backtrace:
01-01 08:05:29.395 763 763 I DEBUG : #00 pc00055fcc /system/lib/libskia.so------------>SkBlitRow_D32.cpp:70(addr2line命令命令得到)
01-01 08:05:29.395 763 763 I DEBUG : #01 pc00096ab4 /system/lib/libskia.so------------>SkSpriteBlitter_ARGB32.cpp:48(addr2line命令命令得到)
01-01 08:05:29.395 763 763 I DEBUG : #02 pc00091578 /system/lib/libskia.so (SkScan::FillIRect(SkIRect const&, SkRegionconst*, SkBlitter*)+356)
01-01 08:05:29.395 763 763 I DEBUG : #03 pc00091714 /system/lib/libskia.so (SkScan::FillIRect(SkIRect const&,SkRasterClip const&, SkBlitter*)+148)
01-01 08:05:29.395 763 763 I DEBUG : #04 pc00070b40 /system/lib/libskia.so (SkDraw::drawBitmap(SkBitmap const&,SkMatrix const&, SkPaint const&) const+780)
01-01 08:05:29.395 763 763 I DEBUG : #05 pc0006b180 /system/lib/libskia.so (SkDevice::drawBitmap(SkDraw const&,SkBitmap const&, SkIRect const*, SkMatrix const&, SkPaintconst&)+76)
01-01 08:05:29.395 763 763 I DEBUG : #06 pc00062120 /system/lib/libskia.so (SkCanvas::commonDrawBitmap(SkBitmapconst&, SkIRect const*, SkMatrix const&, SkPaint const&)+456)
01-01 08:05:29.395 763 763 I DEBUG : #07 pc 0006286c /system/lib/libskia.so (SkCanvas::internalDrawBitmap(SkBitmap const&,SkIRect const*, SkMatrix const&, SkPaint const*)+176)
01-01 08:05:29.395 763 763 I DEBUG : #08 pc000628a4 /system/lib/libskia.so (SkCanvas::drawBitmapMatrix(SkBitmapconst&, SkMatrix const&, SkPaint const*)+24)
01-01 08:05:29.395 763 763 I DEBUG : #09 pc0006c4a3 /system/lib/libandroid_runtime.so
01-01 08:05:29.395 763 763 I DEBUG : #10 pc0001e290 /system/lib/libdvm.so (dvmPlatformInvoke+112)
01-01 08:05:29.395 763 763 I DEBUG : #11 pc0004d479 /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*,JValue*, Method const*, Thread*)+396)
01-01 08:05:29.395 763 763 I DEBUG : #12 pc000276a0 /system/lib/libdvm.so
01-01 08:05:29.396 763 763 I DEBUG : #13 pc0002b574 /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*,JValue*)+184)
01-01 08:05:29.396 763 763 I DEBUG : #14 pc0005fc85 /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*,Object*, bool, JValue*, std::__va_list)+272)
01-01 08:05:29.396 763 763 I DEBUG : #15 pc0004cb1d /system/lib/libdvm.so
01-01 08:05:29.396 763 763 I DEBUG : #16 pc00049b0d /system/lib/libandroid_runtime.so
01-01 08:05:29.396 763 763 I DEBUG : #17 pc 0006700b /system/lib/libandroid_runtime.so
01-01 08:05:29.396 763 763 I DEBUG : #18 pc00014361 /system/lib/libbinder.so (android::BBinder::transact(unsignedint, android::Parcel const&, android::Parcel*, unsigned int)+60)
01-01 08:05:29.396 763 763 I DEBUG : #19 pc00016f5d /system/lib/libbinder.so(android::IPCThreadState::executeCommand(int)+516)
01-01 08:05:29.396 763 763 I DEBUG : #20 pc00017381 /system/lib/libbinder.so(android::IPCThreadState::joinThreadPool(bool)+184)
01-01 08:05:29.396 763 763 I DEBUG : #21 pc0001b169 /system/lib/libbinder.so
01-01 08:05:29.396 763 763 I DEBUG : #22 pc00011287 /system/lib/libutils.so (android::Thread::_threadLoop(void*)+114)
01-01 08:05:29.396 763 763 I DEBUG : #23 pc000470d7 /system/lib/libandroid_runtime.so(android::AndroidRuntime::javaThreadShell(void*)+66)
01-01 08:05:29.396 763 763 I DEBUG : #24 pc00010ded /system/lib/libutils.so
01-01 08:05:29.396 763 763 I DEBUG : #25 pc0000e6c8 /system/lib/libc.so (__thread_entry+72)
01-01 08:05:29.396 763 763 I DEBUG : #26 pc0000dcd4 /system/lib/libc.so (pthread_create+160)
从上述log中可以大致看出抛栈了,但是最后是哪一行代码出错了呢?log中说fault addr 00001eef 究竟是什么意思呢?下面就来一看究竟!
首先,命令介绍addr2line命令,该命令作用是: 翻译二进制的线性地址到源代码文件的行号
该命令在Android的平台中的使用方法如下:(下面用红色标记的是要敲入的命令)
vm_linux/android/jb-4.x/out/target/product/mt5880/
ls symbols/system/lib/
drm libframeworks_coretests_jni.so librsjni.so
egl libfuse.so libRS.so
hw libgabi++.so libRSSupport.so
invoke_mock_media_player.so libgccdemangle.so librtp_jni.so
libandroidfw.so libgl2jni.so librtspplayer.so
libandroid_runtime.so libgldualjni.so libsampleplugin.so
libandroid_servers.so libGLES_trace.so libselinux.so
libandroid.so libGLESv1_CM.so libsensorservice.so
libapk_security.so libGLESv2.so libsimplejni.so
libasan_preload.so libglib.so libskia.so
libaudience_voicefx.so libgljni.so libsonivox.so
libaudioeffect_jni.so libglperf.so libsoundpool.so
libaudioflinger.so libgui.so libsparse.so
libaudio-resampler.so libhardware_legacy.so libspeexresampler.so
libaudioutils.so libhardware.so libsqlite_jni.so
libbcc.sha1.so libharfbuzz.so libsqlite.so
libbcc.so libhdcp2x.so libSR_AudioIn.so
libbcinfo.so libhellojni_jni.so libsrec_jni.so
libbinder.so libhttplive.so libssh.so
libbluedroid.so libhwui.so libssl.so
libbluetooth_jni.so libicui18n.so libstagefright_amrnb_common.so
libbordeaux.so libicuuc.so libstagefright_avc_common.so
libbt-hci.so libinput.so libstagefright_chromium_http.so
libbt-utils.so libinvensense_hal.so libstagefright_enc_common.so
libbubblelevel.so libion.so libstagefright_foundation.so
libcameraanalyzer.so libiprouteutil.so libstagefright_omx.so
libcamera_client.so libjavacore.so libstagefright.so
libcamera_metadata.so libjni_eglfence.so libstagefright_soft_aacdec.so
libcameraservice.so libjni_filtershow_filters.so libstagefright_soft_aacenc.so
libcap-ng.so libjnigraphics.so libstagefright_soft_amrdec.so
libcapture.so libjni_latinime.so libstagefright_soft_amrnbenc.so
libchromium_net.so libjni_legacymosaic.so libstagefright_soft_amrwbenc.so
libc_malloc_debug_leak.so libjni_mosaic.so libstagefright_soft_flacenc.so
libc_malloc_debug_qemu.so libjni_pinyinime.so libstagefright_soft_g711dec.so
libcom_mediatek_tv_jni.so libjnitest.so libstagefright_soft_h264dec.so
libcommon_time_client.so libjpeg.so libstagefright_soft_h264enc.so
libcorkscrew.so libkeystore_client.so libstagefright_soft_mp3dec.so
libcrypto.so libliveMedia.so libstagefright_soft_mpeg4dec.so
libc.so liblog.so libstagefright_soft_mpeg4enc.so
libctest.so libmdnssd.so libstagefright_soft_rawdec.so
libcts_jni.so libmedia_jni.so libstagefright_soft_vorbisdec.so
libctsmediastress_jni.so libmedia_native.so libstagefright_soft_vpxdec.so
libctspermission_jni.so libmediaplayer_mtk.so libstagefright_wfd.so
libctsverifier_jni.so libmediaplayerservice.so libstagefright_yuv.so
libcurl.so libmedia.so libstdc++.so
libcutils.so libmllite.so libstlport.so
libdbus.so libmlplatform.so libsurfaceflinger_ddmconnection.so
libdefcontainer_jni.so libmms.so libsurfaceflinger.so
libdevice_manager.so libmock_ril.so libsuspend.so
libdiskconfig.so libm.so libsync.so
libdlnadmp.so libmtkcapture.so libsystem_server.so
libdl.so libmtkcmpb.so libsysutils.so
libdrm1_jni.so libmtkmediaplayer.so libtestplugin.so
libdrm1.so libMtkPhotoPlayer.so libthread_db.so
libdrmframework_jni.so libmtp.so libtinyalsa.so
libdrmframework.so libnativehelper.so libttscompat.so
libdrmpassthruplugin.so libnative-media-jni.so libttspico.so
libdtv_getline.so libnbaio.so libublock.so
libdvm_assert.so libnetlink.so libui.so
libdvm_interp.so libnetmagic.so libuploadservice.so
libdvm.so libnetutils.so libusbhost.so
libdvm_sv.so libnfc_jni.so libutils.so
libdynamic_annotations.so libnfc_nci_jni.so libvariablespeed.so
libeffects.so libnfc-nci.so libvideoeditor_core.so
libEGL.so libnfc_ndef.so libvideoeditor_jni.so
libembunit.so libnfc.so libvideoeditor_osal.so
libemoji.so libnl_2.so libvideoeditorplayer.so
libETC1.so libntfs-3g.so libvideoeditor_videofilters.so
libexif_jni.so libopengltest_jni.so libvorbisidec.so
libexif.so libOpenMAXAL.so libvospplayer.so
libexpat.so libOpenSLES.so libvsstexch.so
libext2_blkid.so libpagemap.so libwebcore.so
libext2_com_err.so libpixelflinger.so libwebrtc_audio_preprocessing.so
libext2_e2p.so libplatform_library_jni.so libwilhelm.so
libext2fs.so libportable.so libwnndict.so
libext2_profile.so libpowermanager.so libWnnEngDic.so
libext2_uuid.so libpower.so libWnnJpnDic.so
libext4_utils.so libquake.so libwpa_client.so
libFFTEm.so libreference-ril.so libz.so
libfilterfw.so libril.so soundfx
libfilterpack_imageproc.so libRSDriver.so ssl
libfmradio.so librs_jni.so valgrind
$pwd
/vm_linux/android/jb-4.x/out/target/product/mt5880
$ls
android-info.txt clean_steps.mk previous_build_config.mk recovery.img system.img
boot.img data ramdisk.img root test
cache installed-files.txt ramdisk-recovery.img symbols userdata.img
cache.img obj recovery system
$cd obj/
$cd SHARED_LIBRARIES/
$cd libs
libsampleplugin_intermediates/ libstagefright_soft_amrdec_intermediates/
libselinux_intermediates/ libstagefright_soft_amrnbenc_intermediates/
libsensorservice_intermediates/ libstagefright_soft_amrwbenc_intermediates/
libsimplejni_intermediates/ libstagefright_soft_flacenc_intermediates/
libskia_intermediates/ libstagefright_soft_g711dec_intermediates/
libsonivox_intermediates/ libstagefright_soft_h264dec_intermediates/
libsoundpool_intermediates/ libstagefright_soft_h264enc_intermediates/
libsparse_intermediates/ libstagefright_soft_mp3dec_intermediates/
libspeexresampler_intermediates/ libstagefright_soft_mpeg4dec_intermediates/
libsqlite_intermediates/ libstagefright_soft_mpeg4enc_intermediates/
libsqlite_jni_intermediates/ libstagefright_soft_rawdec_intermediates/
libsrec_jni_intermediates/ libstagefright_soft_vorbisdec_intermediates/
libssh_intermediates/ libstagefright_soft_vpxdec_intermediates/
libssl_intermediates/ libstagefright_wfd_intermediates/
libstagefright_amrnb_common_intermediates/ libstagefright_yuv_intermediates/
libstagefright_avc_common_intermediates/ libstdc++_intermediates/
libstagefright_chromium_http_intermediates/ libstlport_intermediates/
libstagefright_enc_common_intermediates/ libsurfaceflinger_ddmconnection_intermediates/
libstagefright_foundation_intermediates/ libsurfaceflinger_intermediates/
libstagefright_intermediates/ libsuspend_intermediates/
libstagefright_omx_intermediates/ libsync_intermediates/
libstagefright_soft_aacdec_intermediates/ libsystem_server_intermediates/
libstagefright_soft_aacenc_intermediates/ libsysutils_intermediates/
$cd libskia_intermediates/LINKED/
$ls
libskia.so
$/mtkoss/android_ndk/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-addr2line -e libskia.so0x96ab4
/proj/mtk40058/workspace/android/DTV/PROD_BR/DTV_X_IDTV0801/vm_linux/android/jb-4.x/external/skia/src/core/SkSpriteBlitter_ARGB32.cpp:48
$/mtkoss/android_ndk/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-addr2line -e libskia.so0x55fcc
/proj/mtk40058/workspace/android/DTV/PROD_BR/DTV_X_IDTV0801/vm_linux/android/jb-4.x/external/skia/src/core/SkBlitRow_D32.cpp:70
/mtkoss/android_ndk/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-addr2line -e libskia.so0x91578
/proj/mtk40058/workspace/android/DTV/PROD_BR/DTV_X_IDTV0801/vm_linux/android/jb-4.x/external/skia/src/core/SkScan.cpp:15
至此,我们已经通过地址找到了相应的源代码文件的行号啦。
另外,objdump 命令有点象那个快速查看之类的工具,就是以一种可阅读的格式让你更多地了解二进制文件可能带有的附加信息。
-d 反汇编那些应该还有指令机器码的section,利用下述命令把libskia.so反汇编成编译语言。
/mtkoss/android_ndk/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-objdump -d libskia.so > asm
$vi asm
libskia.so: file format elf32-littlearm
Disassembly of section .plt:
000406f0 <__cxa_finalize@plt-0x14>:
406f0: e52de004 .word 0xe52de004
406f4: e59fe004 .word 0xe59fe004
406f8: e08fe00e .word 0xe08fe00e
406fc: e5bef008 .word 0xe5bef008
40700: 0012165c .word 0x0012165c
00040704 <__cxa_finalize@plt>:
40704: e28fc601 .word 0xe28fc601
40708: e28cca21 .word 0xe28cca21
4070c: e5bcf65c .word 0xe5bcf65c
00040710 <__cxa_atexit@plt>:
40710: e28fc601 .word 0xe28fc601
40714: e28cca21 .word 0xe28cca21
40718: e5bcf654 .word 0xe5bcf654
/55fcc
55f88: e0864004 add r4, r6, r4
55f8c: e4804004 str r4, [r0], #4
55f90: eaffffab b 55e44 <_ZL19S32_Blend_BlitRow32PjPKjij+0x20>
55f94: 0010bbc8 .word 0x0010bbc8
55f98: 0010bae0 .word 0x0010bae0
00055f9c <_ZL21S32A_Opaque_BlitRow32PjPKjij>:
55f9c: e3520000 cmp r2, #0
55fa0: e92d0ff0 push {r4, r5, r6, r7, r8, r9, sl, fp}
55fa4: da000026 ble 56044 <_ZL21S32A_Opaque_BlitRow32PjPKjij+0xa8>
55fa8: e3120001 tst r2, #1
55fac: 1a000026 bne 5604c <_ZL21S32A_Opaque_BlitRow32PjPKjij+0xb0>
55fb0: e081b102 add fp, r1, r2, lsl #2
55fb4: e151000b cmp r1, fp
55fb8: 0a000021 beq 56044 <_ZL21S32A_Opaque_BlitRow32PjPKjij+0xa8>
55fbc: e59f70d0 ldr r7, [pc, #208] ; 56094 <_ZL21S32A_Opaque_BlitRow32PjPKjij+0xf8>
55fc0: e79f2007 ldr r2, [pc, r7]
55fc4: e5923000 ldr r3, [r2]
55fc8: e1e08003 mvn r8, r3
55fcc: e591c000 ldr ip, [r1]
55fd0: e5912004 ldr r2, [r1, #4]
55fd4: e2811008 add r1, r1, #8
55fd8: e5907000 ldr r7, [r0]
55fdc: e15b0001 cmp fp, r1
55fe0: e5906004 ldr r6, [r0, #4]
55fe4: e1a05c2c lsr r5, ip, #24
55fe8: e1a04c22 lsr r4, r2, #24
55fec: e2655c01 rsb r5, r5, #256 ; 0x100
55ff0: e2644c01 rsb r4, r4, #256 ; 0x100
55ff4: e0079003 and r9, r7, r3
55ff8: e006a003 and sl, r6, r3
55ffc: e0037427 and r7, r3, r7, lsr #8
56000: e0090599 mul r9, r9, r5
56004: e0036426 and r6, r3, r6, lsr #8
56008: e00a049a mul sl, sl, r4
5600c: e0070795 mul r7, r5, r7
56010: e0060694 mul r6, r4, r6
56014: e0039429 and r9, r3, r9, lsr #8
56018: e0077008 and r7, r7, r8
5601c: e003a42a and sl, r3, sl, lsr #8
56020: e1897007 orr r7, r9, r7
56024: e0066008 and r6, r6, r8
56028: e087c00c add ip, r7, ip
5602c: e18aa006 orr sl, sl, r6
56030: e580c000 str ip, [r0]
56034: e08ac002 add ip, sl, r2
56038: e580c004 str ip, [r0, #4]
5603c: e2800008 add r0, r0, #8
56040: 1affffe1 bne 55fcc <_ZL21S32A_Opaque_BlitRow32PjPKjij+0x30>
56044: e8bd0ff0 pop {r4, r5, r6, r7, r8, r9, sl, fp}
56048: e12fff1e bx lr
5604c: e59f4044 ldr r4, [pc, #68] ; 56098 <_ZL21S32A_Opaque_BlitRow32PjPKjij+0xfc>
56050: e2422001 sub r2, r2, #1
56054: e491b004 ldr fp, [r1], #4
56058: e79f3004 ldr r3, [pc, r4]
5605c: e5905000 ldr r5, [r0]
56060: e5933000 ldr r3, [r3]
56064: e1a06c2b lsr r6, fp, #24
55fac: 1a000026 bne 5604c <_ZL21S32A_Opaque_BlitRow32PjPKjij+0xb0>
55fb0: e081b102 add fp, r1, r2, lsl #2
55fb4: e151000b cmp r1, fp
55fb8: 0a000021 beq 56044 <_ZL21S32A_Opaque_BlitRow32PjPKjij+0xa8>
55fbc: e59f70d0 ldr r7, [pc, #208] ; 56094 <_ZL21S32A_Opaque_BlitRow32PjPKjij+0xf8>
55fc0: e79f2007 ldr r2, [pc, r7]
55fc4: e5923000 ldr r3, [r2]
55fc8: e1e08003 mvn r8, r3
55fcc: e591c000 ldr ip, [r1]
55fd0: e5912004 ldr r2, [r1, #4]
55fd4: e2811008 add r1, r1, #8
55fd8: e5907000 ldr r7, [r0]
55fdc: e15b0001 cmp fp, r1
55fe0: e5906004 ldr r6, [r0, #4]
55fe4: e1a05c2c lsr r5, ip, #24
55fe8: e1a04c22 lsr r4, r2, #24
55fec: e2655c01 rsb r5, r5, #256 ; 0x100
55ff0: e2644c01 rsb r4, r4, #256 ; 0x100
55ff4: e0079003 and r9, r7, r3
55ff8: e006a003 and sl, r6, r3
55ffc: e0037427 and r7, r3, r7, lsr #8
56000: e0090599 mul r9, r9, r5
23038,4 8%