Skip to content

Instantly share code, notes, and snippets.

@quarnster
Created October 15, 2012 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quarnster/3892923 to your computer and use it in GitHub Desktop.
Save quarnster/3892923 to your computer and use it in GitHub Desktop.
Android debugging. Put debug.sh in your path somewhere for easy access
#!/bin/bash
startdir=`dirname $0`
if [ $# -lt 1 ]
then
echo "usage: $0 /path/to/your/library.so packagename.of.your.activity"
echo " or"
echo "usage: $0 /path/to/your/executable"
exit
fi
if [ ! -f $1 ]
then
echo "ERROR: That file doesn't exist"
exit
fi
device=`adb shell getprop | grep ro.product.device | awk '{print $2}' | sed 's/\[\([a-zA-Z0-9_]*\).*/\1/'`
buildid=`adb shell getprop | grep ro.build.id | awk '{print $2}' | sed 's/\[\([a-zA-Z0-9_]*\).*/\1/'`
FINGERPRINT=$device-$buildid
LIBDIR=$startdir/lib/$FINGERPRINT
if [ ! -d $LIBDIR ]
then
echo "fingerprint mismatch detected, updating host shared object cache"
mkdir -p $LIBDIR
adb pull /system/lib/ $LIBDIR
adb pull /system/bin/app_process $LIBDIR
adb pull /system/bin/linker $LIBDIR
fi
cp $1 $LIBDIR
if [[ $? -ne 0 ]]
then
echo "library file copy failed"
exit
fi
if [ $# == 2 ]
then
DATA_DIR=`adb shell run-as $2 /system/bin/sh -c pwd | sed -e 's![[:cntrl:]]!!g'`
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
fi
echo "set solib-search-path $LIBDIR" > cmd.txt
echo "set target-async 1" >> cmd.txt
echo "set pagination off" >> cmd.txt
if [ $# == 2 ]
then
echo "file $LIBDIR/app_process" >> cmd.txt
else
echo "file $1" >> cmd.txt
fi
echo "target remote :12345" >> cmd.txt
if [ $# == 2 ]
then
adb shell run-as $2 lib/gdbserver +debug-socket --attach $p &
adb forward tcp:12345 localfilesystem:$DATA_DIR/debug-socket
else
adb push $1 /data/local
adb shell /data/local/gdbserver :12345 /data/local/$1 &
adb forward tcp:12345 tcp:12345
fi
if [ $? != 0 ] ; then
echo "ERROR: Could not launch gdbserver on the device?"
exit 1
fi
if [ $? != 0 ] ; then
echo "ERROR: Could not setup network redirection to gdbserver?"
exit 1
fi
"sublimegdb_commandline":
[
"/Users/quarnster/android/android-ndk-r7-crystax-4/toolchains/arm-linux-androideabi-4.6.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-gdb",
"-x",
"cmd.txt",
"--interpreter=mi"
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment