GDB无法在asm中调试android-native-c-program?

时间:2013-07-02 08:38:42

标签: android assembly gdb arm

我想通过本教程使用gdb在android中调试helloworld c程序:
http://www.kandroid.org/online-pdk/guide/debugging_gdb.html

arm-eabi-gdb,在没有断点的情况下成功运行我的helloworld,但是当我放置一些断点并通过'ni'或'si'运行它时,据说“程序收到信号SIGSEGV,Segmentation fault”。我真的无法理解......

这是我的步骤:
1 testmain.c& Android.mk(在cm_gingerbread / development / test2 /中)

// testmain.c
#include <stdio.h>
void myfn() {
  printf("okkkkkkkkkkkkkkkk...\n");
}
int main() {
  myfn();
  return 0;
}

// Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := testmain
LOCAL_SRC_FILES := testmain.c
LOCAL_MODULE_TAGS := optional
LOCAL_PRELINK_MODULE := false
include $(BUILD_EXECUTABLE)

2编译

  neil@vm64:~/dev/cm_gingerbread/development/test2$ mm  
  target thumb C: testmain <= development/test2/testmain.c  
  target Executable: testmain  (out/target/product/bravo/obj/EXECUTABLES/testmain_intermediates/LINKED/testmain)  
  target Non-prelinked: testmain (out/target/product/bravo/symbols/system/bin/testmain)  
  target Strip: testmain   (out/target/product/bravo/obj/EXECUTABLES/testmain_intermediates/testmain)
  Install: out/target/product/bravo/system/bin/testmain  

3推&amp;运行

  neil@vm64:~$ adb push ~/dev/cm_gingerbread/out/target/product/bravo/system/bin/testmain /system/bin  
  neil@vm64:~$ adb shell  
  # cd system/bin  
  # chmod a+x testmain  
  # ./testmain  
  okkkkkkkkkkkkkkkk...

4运行gdbserver

  neil@vm64:~$ adb shell  
  # gdbserver :5039 /system/bin/testmain  
  Process /system/bin/testmain created; pid = 2862  
  Listening on port 5039 

5运行gdbclient

  neil@vm64:~/dev/cm_gingerbread$ adb forward tcp:5039 tcp:5039  
  neil@vm64:~/dev/cm_gingerbread$ prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gdb ~/dev/cm_gingerbread/out/target/product/bravo/symbols/system/bin/testmain  
  (gdb) set solib-absolute-prefix   /home/neil/dev/cm_gingerbread/out/target/product/bravo/symbols  
  (gdb) set solib-search-path /home/neil/dev/cm_gingerbread/out/target/product/bravo/symbols/system/lib  
  (gdb) target remote :5039  
  (gdb) x/10i 0x8430  
     0x8430 <myfn>:       ldr     r0, [pc, #8]    ; (0x843c <myfn+12>)  
     0x8432 <myfn+2>:     push    {r4, lr}  
     0x8434 <myfn+4>:     add     r0, pc  
     0x8436 <myfn+6>:     blx     0x83f0  
     0x843a <myfn+10>:    pop     {r4, pc}  
     ...  
  (gdb) b *0x8436  
     Breakpoint 1 at 0x8436: file development/test2/testmain.c, line 4.  
  (gdb) b *0x83f0  
     Breakpoint 2 at 0x83f0  
  (gdb) c  
     Continuing.  
     Breakpoint 1, 0x00008436 in myfn () at development/test2/testmain.c:4  
  (gdb) ni  
     Program received signal SIGSEGV, Segmentation fault.  
     0x000083f8 in ?? ()  

当我只是通过'c'命令运行它而没有任何断点时,没关系:

(gdb) target remote :5039
  Remote debugging using :5039
  warning: Unable to find dynamic linker breakpoint function.
  GDB will be unable to debug shared library initializers
  and track explicitly loaded dynamic code.
  0xb0001000 in ?? ()
(gdb) c
  Continuing.
  Cannot access memory at address 0x0
  Error while mapping shared library sections:
  /system/bin/linker: No such file or directory.
  Error while mapping shared library sections:
  libc.so: No such file or directory.
  ...

  Program exited normally.

1 个答案:

答案 0 :(得分:0)

看起来你使用了错误的gdb / gdbserver组合。我在AOSP 4.0.3上工作。我们最终使用7.3版本的gdb源代码而不是预先构建的gdb来构建我们自己的gdb。

请查看Debugging Android native apps文章。它讨论了本机调试和解决方法的一些问题。

您可能想要检查Linaro site for latest gdb/gdbserver二进制文件。