2.47 NDK基础与调试

1 minute read

调试

  • addr2line, 定位异常堆栈代码行
    1. 获取异常堆栈中的汇编地址信息, 这里的目标地址是000a4f3c
    2019-12-26 16:27:10.584 1856-1856/com.vencial.mediaplayer A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x1800c4 in tid 1856 (ial.mediaplayer)
    2019-12-26 16:27:10.652 1897-1897/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    2019-12-26 16:27:10.653 1897-1897/? A/DEBUG: Build fingerprint: 'Xiaomi/jason/jason:7.1.1/NMF26X/8.2.1:user/release-keys'
    2019-12-26 16:27:10.653 1897-1897/? A/DEBUG: Revision: '0'
    2019-12-26 16:27:10.653 1897-1897/? A/DEBUG: ABI: 'arm'
    2019-12-26 16:27:10.653 1897-1897/? A/DEBUG: pid: 1856, tid: 1856, name: ial.mediaplayer  >>> com.vencial.mediaplayer <<<
    2019-12-26 16:27:10.653 1897-1897/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1800c4
    2019-12-26 16:27:10.653 1897-1897/? A/DEBUG:     r0 00180090  r1 00000024  r2 000271fa  r3 00000000
    2019-12-26 16:27:10.653 1897-1897/? A/DEBUG:     r4 f2603000  r5 001a71fa  r6 f2617008  r7 00000000
    2019-12-26 16:27:10.653 1897-1897/? A/DEBUG:     r8 f2617008  r9 ff9f21b0  sl e8e6e2d0  fp 001a71fa
    2019-12-26 16:27:10.653 1897-1897/? A/DEBUG:     ip f4a2c954  sp ff9f20d0  lr f4a0b0a7  pc f4a0ac48  cpsr 200f0030
    2019-12-26 16:27:10.655 1897-1897/? A/DEBUG: backtrace:
    2019-12-26 16:27:10.655 1897-1897/? A/DEBUG:     #00 pc 00066c48  /system/lib/libc.so (ifree+51)
    2019-12-26 16:27:10.655 1897-1897/? A/DEBUG:     #01 pc 000670a3  /system/lib/libc.so (je_free+74)
    2019-12-26 16:27:10.655 1897-1897/? A/DEBUG:     #02 pc 000a4f3c  /data/app/com.vencial.mediaplayer-1/lib/arm/libsongstudio.so (_ZN16AccompanyDecoder7destroyEv+84)
    2019-12-26 16:27:10.655 1897-1897/? A/DEBUG:     #03 pc 000a4930  /data/app/com.vencial.mediaplayer-1/lib/arm/libsongstudio.so (_ZN16AccompanyDecoder12getMusicMetaEPKcPi+104)
    2019-12-26 16:27:10.655 1897-1897/? A/DEBUG:     #04 pc 000a4248  /data/app/com.vencial.mediaplayer-1/lib/arm/libsongstudio.so (_ZN26AccompanyDecoderController4InitEPKcS1_+72)
    2019-12-26 16:27:10.655 1897-1897/? A/DEBUG:     #05 pc 000a4179  /data/app/com.vencial.mediaplayer-1/lib/arm/libsongstudio.so (Java_com_vencial_mediaplayer_helper_Mp3Decoder_init+72)
    2019-12-26 16:27:10.655 1897-1897/? A/DEBUG:     #06 pc 00253451  /data/app/com.vencial.mediaplayer-1/oat/arm/base.odex (offset 0x23b000)
    
    1. 运行addr2line -e /Users/vencial/Documents/workspace/Mediaplayer/app/src/main/obj/local/armeabi-v7a/libsongstudio.so 000a4f3c, 【注意】这里的libsongstudio.so为编译后obj文件夹中的so
  • objdump定位异常函数信息

    1. 运行objdump -S -D /Users/vencial/Documents/workspace/Mediaplayer/app/src/main/obj/local/armeabi-v7a/libsongstudio.so > /Users/vencial/dump.log, 【注意】这里的libsongstudio.so为编译后obj文件夹中的so, 另外, 该命令把so库所有函数信息都dump下来, 时间特别长以及文本内容非常大, 接下来看下怎么找到指定函数的函数信息
  • ndk-stack实时分析堆栈

    1. adb logcat | ndk-stack -sym /Users/vencial/Documents/workspace/Mediaplayer/app/src/main/obj/local/armeabi-v7a/libsongstudio.so, 【注意】这里的libsongstudio.so为编译后obj文件夹中的so

参考

Tags:

Categories:

Updated: