从调用堆栈中获取函数名称

时间:2010-02-22 21:17:24

标签: c++ c gdb android-ndk

我正在开发一个调用本机代码的Android程序。该本机代码是segfaulting,因为通过android NDK进行调试并不是真的可行,所以我留下了一个如下所示的callstack(从ddms中捕获)。我的问题是,在将callstack中的内存地址转换为函数名之后是否可以手动运行,以便我可以看到这是segfaulting。

由于

02-22 14:47:39.231: DEBUG/dalvikvm(504): Trying to load lib /data/data/android.TestApp/lib/libDM.so 0x43b7c938
02-22 14:47:39.301: DEBUG/dalvikvm(504): Added shared lib /data/data/android.TestApp/lib/libDM.so 0x43b7c938
02-22 14:47:39.310: DEBUG/dalvikvm(504): No JNI_OnLoad found in /data/data/android.TestApp/lib/libDM.so 0x43b7c938
02-22 14:47:39.406: DEBUG/dalvikvm(504): +++ not scanning '/system/lib/libwebcore.so' for 'onLoadModel' (wrong CL)
02-22 14:47:39.410: DEBUG/dalvikvm(504): +++ not scanning '/system/lib/libmedia_jni.so' for 'onLoadModel' (wrong CL)
02-22 14:47:39.410: DEBUG/dalvikvm(504): +++ not scanning '/system/lib/libexif.so' for 'onLoadModel' (wrong CL)
02-22 14:47:39.410: DEBUG/dalvikvm(504): +++ not scanning '/system/lib/libsrec_jni.so' for 'onLoadModel' (wrong CL)
02-22 14:47:39.569: INFO/DEBUG(28): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-22 14:47:39.569: INFO/DEBUG(28): Build fingerprint: 'generic/sdk/generic/:2.1/ERD79/22607:eng/test-keys'
02-22 14:47:39.569: INFO/DEBUG(28): pid: 504, tid: 504  >>> android.TestApp <<<
02-22 14:47:39.569: INFO/DEBUG(28): signal 11 (SIGSEGV), fault addr 00000008
02-22 14:47:39.581: INFO/DEBUG(28):  r0 00000000  r1 00000068  r2 00002350  r3 80facc00
02-22 14:47:39.581: INFO/DEBUG(28):  r4 beb3c918  r5 000024b8  r6 fffacafc  r7 0000aa98
02-22 14:47:39.581: INFO/DEBUG(28):  r8 00000000  r9 000024b8  10 fffacafc  fp 00000000
02-22 14:47:39.581: INFO/DEBUG(28):  ip afbc30c8  sp beb3c858  lr 80dffdf3  pc 80dfb18a  cpsr 40000030
02-22 14:47:39.711: INFO/DEBUG(28):          #00  pc 001fb18a  /data/data/android.TestApp/lib/libDM.so
02-22 14:47:39.733: INFO/DEBUG(28):          #01  pc 001ffdee  /data/data/android.TestApp/lib/libDM.so
02-22 14:47:39.740: INFO/DEBUG(28):          #02  pc 0031cc2c  /data/data/android.TestApp/lib/libDM.so
02-22 14:47:39.754: INFO/DEBUG(28):          #03  pc 0031cd74  /data/data/android.TestApp/lib/libDM.so
02-22 14:47:39.761: INFO/DEBUG(28):          #04  pc 0000f1f4  /system/lib/libdvm.so
02-22 14:47:39.769: INFO/DEBUG(28):          #05  pc 00038018  /system/lib/libdvm.so
02-22 14:47:39.779: INFO/DEBUG(28):          #06  pc 000316a2  /system/lib/libdvm.so
02-22 14:47:39.790: INFO/DEBUG(28):          #07  pc 0003d31c  /system/lib/libdvm.so
02-22 14:47:39.810: INFO/DEBUG(28):          #08  pc 00013f58  /system/lib/libdvm.so
02-22 14:47:39.810: INFO/DEBUG(28):          #09  pc 00019888  /system/lib/libdvm.so
02-22 14:47:39.820: INFO/DEBUG(28):          #10  pc 00018d5c  /system/lib/libdvm.so
02-22 14:47:39.846: INFO/DEBUG(28):          #11  pc 0004d3bc  /system/lib/libdvm.so
02-22 14:47:39.852: INFO/DEBUG(28):          #12  pc 00054e74  /system/lib/libdvm.so
02-22 14:47:39.871: INFO/DEBUG(28):          #13  pc 00013f58  /system/lib/libdvm.so
02-22 14:47:39.871: INFO/DEBUG(28):          #14  pc 00019888  /system/lib/libdvm.so
02-22 14:47:39.889: INFO/DEBUG(28):          #15  pc 00018d5c  /system/lib/libdvm.so
02-22 14:47:39.889: INFO/DEBUG(28):          #16  pc 0004d6d0  /system/lib/libdvm.so
02-22 14:47:39.900: INFO/DEBUG(28):          #17  pc 0003a72c  /system/lib/libdvm.so
02-22 14:47:39.909: INFO/DEBUG(28):          #18  pc 0002be52  /system/lib/libdvm.so
02-22 14:47:39.921: INFO/DEBUG(28):          #19  pc 00026cf4  /system/lib/libandroid_runtime.so
02-22 14:47:39.930: INFO/DEBUG(28):          #20  pc 000279d8  /system/lib/libandroid_runtime.so
02-22 14:47:39.940: INFO/DEBUG(28):          #21  pc 00008cae  /system/bin/app_process
02-22 14:47:39.949: INFO/DEBUG(28):          #22  pc 0000c2c6  /system/lib/libc.so
02-22 14:47:39.969: INFO/DEBUG(28):          #23  pc b00018aa  /system/bin/linker
02-22 14:47:39.981: INFO/DEBUG(28): code around pc:
02-22 14:47:39.981: INFO/DEBUG(28): 80dfb178 fffaaac8 4656b570 4644464d 4680b470 
02-22 14:47:39.981: INFO/DEBUG(28): 80dfb188 6883b081 1c0d1c08 22b04798 46814442 
02-22 14:47:39.981: INFO/DEBUG(28): 80dfb198 46921c10 f73d2600 4642ea90 6c546c13 
02-22 14:47:39.981: INFO/DEBUG(28): code around lr:
02-22 14:47:39.981: INFO/DEBUG(28): 80dffde0 1c064a0b 589b447b 681c1c31 f7fb1c20 
02-22 14:47:39.981: INFO/DEBUG(28): 80dffdf0 1c05f9c5 d0062800 d0042c00 23001c32 
02-22 14:47:39.981: INFO/DEBUG(28): 80dffe00 f7fb1c20 1c28fa15 0000bd70 001a47f8 
02-22 14:47:39.981: INFO/DEBUG(28): stack:
02-22 14:47:39.981: INFO/DEBUG(28):     beb3c818  afe42ad4  
02-22 14:47:39.981: INFO/DEBUG(28):     beb3c81c  ad07ff50  /system/lib/libdvm.so
02-22 14:47:39.990: INFO/DEBUG(28):     beb3c820  0000bd00  [heap]
02-22 14:47:39.990: INFO/DEBUG(28):     beb3c824  00000000  
02-22 14:47:39.990: INFO/DEBUG(28):     beb3c828  00085920  [heap]
02-22 14:47:40.000: INFO/DEBUG(28):     beb3c82c  00000000  
02-22 14:47:40.000: INFO/DEBUG(28):     beb3c830  ffffffff  
02-22 14:47:40.000: INFO/DEBUG(28):     beb3c834  beb3c850  [stack]
02-22 14:47:40.015: INFO/DEBUG(28):     beb3c838  00000000  
02-22 14:47:40.015: INFO/DEBUG(28):     beb3c83c  00000000  
02-22 14:47:40.022: INFO/DEBUG(28):     beb3c840  ad563b21  /system/lib/libicuuc.so
02-22 14:47:40.022: INFO/DEBUG(28):     beb3c844  00085968  [heap]
02-22 14:47:40.030: INFO/DEBUG(28):     beb3c848  00000001  
02-22 14:47:40.050: INFO/DEBUG(28):     beb3c84c  00000000  
02-22 14:47:40.061: INFO/DEBUG(28):     beb3c850  df002777  
02-22 14:47:40.061: INFO/DEBUG(28):     beb3c854  e3a070ad  
02-22 14:47:40.070: INFO/DEBUG(28): #00 beb3c858  ad065714  /system/lib/libdvm.so
02-22 14:47:40.070: INFO/DEBUG(28):     beb3c85c  beb3c918  [stack]
02-22 14:47:40.070: INFO/DEBUG(28):     beb3c860  000024b8  
02-22 14:47:40.090: INFO/DEBUG(28):     beb3c864  fffacafc  
02-22 14:47:40.090: INFO/DEBUG(28):     beb3c868  00000000  
02-22 14:47:40.100: INFO/DEBUG(28):     beb3c86c  80faed2c  
02-22 14:47:40.100: INFO/DEBUG(28):     beb3c870  00000068  
02-22 14:47:40.122: INFO/DEBUG(28):     beb3c874  80dffdf3  /data/data/android.TestApp/lib/libDM.so
02-22 14:47:40.122: INFO/DEBUG(28): #01 beb3c878  80f510dc  /data/data/android.TestApp/lib/libDM.so
02-22 14:47:40.122: INFO/DEBUG(28):     beb3c87c  80faed2c  
02-22 14:47:40.122: INFO/DEBUG(28):     beb3c880  80fa45e0  /data/data/android.TestApp/lib/libDM.so
02-22 14:47:40.122: INFO/DEBUG(28):     beb3c884  80f1cc31  /data/data/android.TestApp/lib/libDM.so
02-22 14:47:41.240: DEBUG/Zygote(30): Process 504 terminated by signal (11)

3 个答案:

答案 0 :(得分:16)

您应该在NDK bin目录中提供arm-eabi-addr2line的副本。您可以使用以下命令来使用它:

arm-eabi-addr2line -f -e /path/to/lib/with/symbols.so 0x001fb18a

这将遍历共享库中的调试符号以获取文件和行号信息。为了获得最佳结果,请将一个未删除调试内容的库交给它。

答案 1 :(得分:4)

您需要生成地图文件。 map 文件包含可执行文件中的函数地址和内存位置。修改构建系统以生成映射文件。

map 文件中,您可以使用文本编辑器搜索地址。我曾经写过一个程序来找到绑定给定地址的两个符号。非常适合像你这样的环境。

答案 2 :(得分:2)

您可以使用最新的ndks中包含的ndk-stack脚本。用法很简单:ndk-stack -sym“dir to objects with symbols”-dump“location to logfile”