public
Last active

Android debugging. Put debug.sh in your path somewhere for easy access

  • Download Gist
debug.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
#!/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_settings.json
JSON
1 2 3 4 5 6 7
"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"
],

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.