use addr2line in android

來源:互聯網
上載者:User

Let's say that logcat show you the following crash log (this is from one of my projects):

 

Log代碼
 
  1. I/DEBUG   (   31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***   
  2. I/DEBUG   (   31): Build fingerprint: 'generic/sdk/generic:2.3/GRH55/79397:eng/test-keys'  
  3. I/DEBUG   (   31): pid: 378, tid: 386  >>> com.example.gltest <<<
      
  4. I/DEBUG   (   31): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000  
  5. I/DEBUG   (   31):  r0 001dbdc0  r1 00000001  r2 00000000  r3 00000000  
  6. I/DEBUG   (   31):  r4 00000000  r5 40a40000  r6 4051a480  r7 42ddbee8   
  7. I/DEBUG   (   31):  r8 43661b24  r9 42ddbed0  10 42ddbebc  fp 41e462d8   
  8. I/DEBUG   (   31):  ip 00000001  sp 436619d0  lr 83a12f5d  pc 8383deb4  cpsr 20000010  
  9. I/DEBUG   (   31):          #00  pc 0003deb4  /data/data/com.example.gltest/lib/libnativemaprender.so
      
  10. I/DEBUG   (   31):          #01  pc 00039b76  /data/data/com.example.gltest/lib/libnativemaprender.so
      
  11. I/DEBUG   (   31):          #02  pc 00017d34  /system/lib/libdvm.so  
I/DEBUG   (   31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***I/DEBUG   (   31): Build fingerprint: 'generic/sdk/generic:2.3/GRH55/79397:eng/test-keys'I/DEBUG   (   31): pid: 378, tid: 386  >>> com.example.gltest <<<I/DEBUG   (   31): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000I/DEBUG   (   31):  r0 001dbdc0  r1 00000001  r2 00000000  r3 00000000I/DEBUG   (   31):  r4 00000000  r5 40a40000  r6 4051a480  r7 42ddbee8I/DEBUG   (   31):  r8 43661b24  r9 42ddbed0  10 42ddbebc  fp 41e462d8I/DEBUG   (   31):  ip 00000001  sp 436619d0  lr 83a12f5d  pc 8383deb4  cpsr 20000010I/DEBUG   (   31):          #00  pc 0003deb4  /data/data/com.example.gltest/lib/libnativemaprender.soI/DEBUG   (   31):          #01  pc 00039b76  /data/data/com.example.gltest/lib/libnativemaprender.soI/DEBUG   (   31):          #02  pc 00017d34  /system/lib/libdvm.so

 

Look at the last 3 lines; this is your callstack. 'pc' is the program counter, and the pc for stack frame #00 gives you the address where the crash occurred. This is the number to pass to addr2line.

I'm using NDK r5, so the executable I'm using is located at $NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin ; make sure that is in your
$PATH . The command to use looks like

Cmd代碼
 
  1. arm-linux-androideabi-addr2line -C -f -e obj/local/armeabi/libXXX.so <address>  
arm-linux-androideabi-addr2line -C -f -e obj/local/armeabi/libXXX.so <address>

 Or, for the case above:

Cmd代碼
 
  1. arm-linux-androideabi-addr2line -C -f -e obj/local/armeabi/libnativemaprender.so 0003deb4  
arm-linux-androideabi-addr2line -C -f -e obj/local/armeabi/libnativemaprender.so 0003deb4

 

Which gives you the location of the crash.

Note:

  • The -C flag is to demangle C++ code
  • Use the .so file under obj/local/armeabi, since this is the non-stripped version

Also, when using NDK r5 with a 2.3 AVD, it is actually possible to debug multithreaded code.  

 

Refer to:

http://stackoverflow.com/questions/5314036/how-to-use-addr2line-in-android

http://www.codexperiments.com/android/2010/08/tips-tricks-debugging-android-ndk-stack-traces/

聯繫我們

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