• I just encountered a crash of Androids debuggerd on my pandaboard and wondered how to find the root cause of this issue. For the native parts of an app there is the ndk-gdb but what do we do in case of a non-app system component? Here is what I came up with.

Prerequisites

  • This howto assumes you have an Android build environment including the toolchain, Android sources and adb set up already.

Create a debugable version of the ELF binary

  • Edit the makefile of the compoent to be debugged and add -g (and -O0 if you like):
    vim system/core/debuggerd/Android.mk
    # insert something like this: 
    LOCAL_CFLAGS += -g -O0
    Rebuild the binary
    rm -r out/target/product/pandaboard/obj/EXECUTABLES/debuggerd_intermediates
    make TARGET_PRODUCT=pandaboard TARGET_TOOLS_PREFIX=/path/to/crosstoolchain/bin/arm-eabi- debuggerd showcommands
    Install the new binary on the device
    adb remount
    adb shell mv /system/bin/debuggerd /system/bin/debuggerd_orig
    adb push out/target/product/pandaboard/symbols/system/bin/debuggerd /system/bin/debuggerd
    Now restart the process (or reboot the device) to get your binary executed
    adb reboot

debugging

  • Find the PID of the remote process you want to debug:
    adb shell ps | grep debuggerd
    Start the gdbserver on the android device and attach to the process to be debugged:
    adb shell
    /system/bin/gdbserver +debug-socket --attach <PID>
    Switch to another console on your development host and setup the ADB port forwarding:
    adb forward tcp:5039 localfilesystem:debug-socket
    Start the GDB (client)
    gdb-multiarch out/target/product/pandaboard/symbols/system/bin/debuggerd
    and connect to the gdbserver:
    (gdb) target remote :5039
    Now you may set breakpoints, dump backtraces, inspect variables, and the like.

    That's all - happy debugging! :)


CategoryAndroidTips

Platform/Android/DebugAndroidSystemComponents (last modified 2013-08-29 07:29:44)