Search code examples
androidcandroid-ndkgdbgdbserver

Remote debugging of pure C program with GDB


I am trying to remotely debug a pure C program on an Android device. The Android device (target) is connected via USB to a host machine.

What I did was: Copied from the target the following files: /system/lib, /vendor/lib, /system/bin/app_process, and /system/bin/linker.

Target:

  • Copied gdbserver from NDK to the target device
  • Sent the exe that I want to debug
  • runned gdb server on target using ./gdbserver :5039 exec
    • this basically executes the process, and gets a pid

Host:

  • enabled the port adb forward tcp:5039 tcp:5039
  • runned: arm-eabi-gcc exec.
  • Then in gdb:
    • set solib-search-path ..., with the libraries that I pulled earlier from the target
    • target remote :5039

The arm-eabi-gcc can connect to the remote process, and even continue(c) the execution. However, I cannot set breakpoints. If I do, I get the following error: Cannot access memory at address xxx.

Am I missing something here?

Thank you.


Solution

  • So, at host, in gdb shell, before specifying the remote's target port, I should type shared. This command loads the shared symbols.

    Also, for compiling, I used -ggdb.