2013-04-29 12:09:31 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# android_gdb: Pushes parameter binary and gdbserver. Connects
|
|
|
|
# and enters debugging environment.
|
|
|
|
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
APP_NAME=$(basename $1)
|
|
|
|
PORT=5039
|
|
|
|
|
|
|
|
# Collect extra arguments to be passed to the Skia binary
|
|
|
|
shift
|
2013-08-02 15:14:24 +00:00
|
|
|
deviceID=""
|
2013-04-29 12:09:31 +00:00
|
|
|
while (( "$#" )); do
|
2013-08-02 15:14:24 +00:00
|
|
|
|
|
|
|
if [[ $(echo "$1" | grep "^-d$") != "" ]];
|
|
|
|
then
|
|
|
|
deviceID=$2
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
APP_ARGS="$APP_ARGS $1"
|
|
|
|
fi
|
|
|
|
|
2013-04-29 12:09:31 +00:00
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2013-08-02 15:14:24 +00:00
|
|
|
# hack for x86 support in android_setup.sh
|
|
|
|
if [ "$deviceID" == "x86" ] || [ "$deviceID" == "razr_i" ]
|
|
|
|
then
|
|
|
|
ANDROID_ARCH=x86
|
|
|
|
fi
|
|
|
|
|
2013-04-29 12:09:31 +00:00
|
|
|
source $SCRIPT_DIR/android_setup.sh
|
|
|
|
source $SCRIPT_DIR/utils/setup_adb.sh
|
|
|
|
|
|
|
|
echo "Installing Skia Android app"
|
|
|
|
$SCRIPT_DIR/android_install_skia -f
|
|
|
|
|
|
|
|
# Forward local to remote socket connection.
|
|
|
|
$ADB forward "tcp:$PORT" "tcp:$PORT"
|
|
|
|
|
|
|
|
# We kill all previous instances of gdbserver to rid all port overriding errors.
|
|
|
|
$ADB shell ps | grep gdbserver | awk '{print $2}' | xargs -r $ADB shell kill
|
|
|
|
|
|
|
|
# We need the debug symbols from these files
|
|
|
|
GDB_TMP_DIR=$(pwd)/android_gdb_tmp
|
|
|
|
mkdir $GDB_TMP_DIR
|
|
|
|
echo "Copying symbol files"
|
|
|
|
$ADB pull /system/bin/app_process $GDB_TMP_DIR
|
|
|
|
$ADB pull /system/lib/libc.so $GDB_TMP_DIR
|
|
|
|
$ADB pull /data/data/com.skia/lib/lib$APP_NAME.so $GDB_TMP_DIR
|
|
|
|
|
|
|
|
# Launch the app
|
|
|
|
SK_COMMAND="$APP_NAME$APP_ARGS"
|
|
|
|
echo "Running command $SK_COMMAND"
|
|
|
|
$ADB shell am broadcast -a com.skia.intent.action.LAUNCH_SKIA -n com.skia/.SkiaReceiver -e args "$SK_COMMAND"
|
|
|
|
|
|
|
|
# Attach gdbserver to the app process
|
|
|
|
PID=$($ADB shell ps | grep skia_native | awk '{print $2}')
|
|
|
|
echo "Attaching to pid: $PID"
|
|
|
|
$ADB shell /data/data/com.skia/lib/gdbserver :$PORT --attach $PID &
|
|
|
|
|
|
|
|
# Wait for gdbserver
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
# Set up gdb commands
|
|
|
|
GDBSETUP=$GDB_TMP_DIR/gdb.setup
|
|
|
|
echo "file $GDB_TMP_DIR/app_process" >> $GDBSETUP
|
|
|
|
echo "target remote :$PORT" >> $GDBSETUP
|
|
|
|
echo "set solib-absolute-prefix $GDB_TMP_DIR" >> $GDBSETUP
|
|
|
|
echo "set solib-search-path $GDB_TMP_DIR" >> $GDBSETUP
|
|
|
|
|
|
|
|
# Launch gdb client
|
|
|
|
echo "Entering gdb client shell"
|
2013-08-02 15:14:24 +00:00
|
|
|
if [ "$ANDROID_ARCH" == "x86" ]
|
|
|
|
then
|
|
|
|
$ANDROID_TOOLCHAIN/i686-linux-android-gdb -x $GDBSETUP
|
|
|
|
else
|
|
|
|
$ANDROID_TOOLCHAIN/arm-linux-androideabi-gdb -x $GDBSETUP
|
|
|
|
fi
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
# Clean up
|
|
|
|
rm -rf $GDB_TMP_DIR
|
|
|
|
|