Mobile/Fennec/Android/GDBNoRoot
- NOTE: While they generally work, these instructions are obsoleted by Mobile/Fennec/Android/GDB, which automates most of the steps below and fixes other issues as well. That version of gdb is recommended over the ndk version as of late 2012.
debugging without rooting
with Froyo you can debug without rooting your phone. Instructions are below.
First thing, to make this work with the nvidia gdb (which I found more reliable than the android r3 gdb) you need to modify install.sh and debug.sh.
first, change the location where install.sh copies gdbserver to somewhere writable by a non-root process. I used /data/local. Be sure to update that both in the push command and the chmod command.
second, update debug.sh with the new location of gdbserver.
finally, you'll need to add run-as $2 to the adb shell command that launches gdbserver. In the end you should have: install.sh:
#!/bin/sh mkdir lib adb push prebuilt/gdbserver /data/local adb shell chmod 755 /data/local/gdbserver for file in $(adb shell ls /system/lib | tr "\n" " " | tr "\r" " "); do adb pull /system/lib/$file lib done adb pull /system/bin/app_process lib
The above will miss some vendor drivers, you can use busybox to find all shared libraries
for file in $(adb shell /data/local/busybox find / -name "*.so" | tr "\n" " " | tr "\r" " "); do adb pull /$file lib_unlock_nexus/; done
debug.sh:
#!/bin/sh if [ $# -ne 2 ] then echo "usage: $0 /path/to/your/library.so packagename.of.your.activity" echo "for example:" echo " $0 /code/mydemo/libs/armeabi/libmydemo.so com.nvidia.devtech.mydemo" exit fi if [ ! -f $1 ] then echo "ERROR: That library file doesn't exist" exit fi cp $1 lib p=`adb shell ps | grep $2 | awk '{print $2}'` if [ "$p" = "" ]; then echo "ERROR: That doesn't seem to be a running process. Please make sure your" echo "application has been started and that you are using the correct" echo "namespace argument." exit fi adb forward tcp:12345 tcp:12345 adb shell run-as $2 /data/local/gdbserver --attach :12345 $p
Attaching GDB
Assuming you have the nvidia gdb at the top of your home directory and the app_process binary in the current working directory.
~/nvidia-gdb/prebuilt/linux-x86/arm-eabi-gdb ./app_process
GDB on Android without Root
It is possible to use gdb without root on Android 2.3+ devices!
- Go to your Android NDK directory and enter /build
- Run this:
mkdir lib
adb push prebuilt/linux-x86/arm-eabi-4.4.0/bin/gdbserver /data/local
adb shell chmod 755 /data/local/gdbserver
for file in $(adb shell ls /system/lib | tr "\n" " " | tr "\r" " "); do
adb pull /system/lib/$file lib
done
adb pull /system/bin/app_process lib
- Forward a port, by doing
adb forward tcp:12345 tcp:12345
- Find your pid with
adb shell ps | grep fennec
- Connect to the process on the devices with
adb shell run-as org.mozilla.fennec_unofficial /data/local/gdbserver :12345 --attach THE_PID_YOU_JUST_FOUND
- Run gdb with
./prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-gdb ./lib/app_process
- In gdb, run this or just place it in a .gdbinit (then run just android_attach)
def android_attach
set solib-absolute-prefix /builds/android_tools/tegra-gdb-20100902/lib/
set solib-search-path
/builds/android_tools/tegra-gdb-20100902/lib/:/builds/android_tools/tegra-gdb-20100902/lib/system/lib:/builds/mozilla-central/obj-android/dist/bin/
target remote localhost:12345
end