2014-07-29

Remote debugging C/C++ program via gdbserver running inside the A device

Precondition
Upload gdbserver from build folder to your device to make sure no version issue.
$adb push ./out/target/product/msm8625/system/bin/gdbserver /data/bin/gdbserver

1. On device, getting PID of the program you want to debug,let's say debuggerd;
$ ps | grep debuggerd
system 143 1 50356 9188 ffffffff 401d8bd4 S /system/bin/debuggerd


2. On device, attaching gdbserver to the C/C++ program we want to debug;
$ gdbserver :123456 --attach 143
Or
$ gdbserver :123456 /system/bin/debuggerd

3. On PC, setting up TCP port forwarding(TCP<->USB);
$ adb forward tcp:123456 tcp:123456

4. On PC, downloading all the ARM-based libraries from the phone to somewhere;
$ adb pull /system/lib ./device/system_lib

5. On PC, downloading ARM-based C/C++ program you want to debug from the phone to PC;
$ adb pull /system/bin/debuggerd ./device/

6. On PC, starting gdb;
$ ./prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gdb ./device/debuggerd
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-elf-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /westdata/android/out/target/product/msm8625/symbols/system/bin/surfaceflinger...done.
(gdb) set auto-solib-add on
(gdb) set solib-absolute-prefix out/target/product/msm8625/symbols/
(gdb) set solib-search-path ./device/system_lib
(gdb) target remote :123456
Remote debugging using :123456
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0x4014c660 in ?? ()


NOTE:'set auto-solib-add on' is to forbiten other scheduler during your debugging.

NOTE 2: If you are debugging a JNI program's native part, the binary of the program is /system/bin/app_process (not the process name like com.android.email).

TODO: Add a real case here...

 

No comments: