1

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

arm-eabi-gdb,没有断点成功运行我的helloworld,但是当我设置一些断点并通过'ni'或'si'运行它时,它说“程序收到信号SIGSEGV,分段错误”。实在看不懂。。。

这是我的步骤:
1 testmain.c & Android.mk(in 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 推和跑

  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.
4

1 回答 1

0

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

请查看调试 Android 原生应用文章。它讨论了本机调试的一些问题以及它们的解决方法。

您可能想查看Linaro 站点以获取最新的 gdb/gdbserver二进制文件。

于 2014-07-15T03:59:53.080 回答