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 )"
|
2013-08-06 20:32:29 +00:00
|
|
|
source $SCRIPT_DIR/android_setup.sh
|
2013-04-29 12:09:31 +00:00
|
|
|
|
2013-08-06 20:32:29 +00:00
|
|
|
APP_NAME=${APP_ARGS[0]}
|
|
|
|
PORT=5039
|
2013-08-02 15:14:24 +00:00
|
|
|
|
2013-04-29 12:09:31 +00:00
|
|
|
source $SCRIPT_DIR/utils/setup_adb.sh
|
|
|
|
|
|
|
|
|
|
|
|
# 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
|
2013-08-06 20:32:29 +00:00
|
|
|
mkdir -p $GDB_TMP_DIR
|
2013-04-29 12:09:31 +00:00
|
|
|
echo "Copying symbol files"
|
2013-08-12 12:30:04 +00:00
|
|
|
adb_pull_if_needed /system/bin/app_process $GDB_TMP_DIR
|
|
|
|
adb_pull_if_needed /system/lib/libc.so $GDB_TMP_DIR
|
|
|
|
adb_pull_if_needed /data/data/com.skia/lib/libskia_android.so $GDB_TMP_DIR
|
|
|
|
adb_pull_if_needed /data/data/com.skia/lib/libSampleApp.so $GDB_TMP_DIR
|
2013-04-29 12:09:31 +00:00
|
|
|
|
2014-02-13 22:31:48 +00:00
|
|
|
echo "Pushing gdbserver..."
|
|
|
|
adb_push_if_needed $ANDROID_TOOLCHAIN/../gdbserver /data/local/tmp
|
|
|
|
|
2013-04-29 12:09:31 +00:00
|
|
|
# Launch the app
|
2013-08-06 20:32:29 +00:00
|
|
|
SK_COMMAND="$APP_ARGS"
|
2013-04-29 12:09:31 +00:00
|
|
|
echo "Running command $SK_COMMAND"
|
2013-08-12 12:30:04 +00:00
|
|
|
adb shell am start -n com.skia/com.skia.SkiaSampleActivity
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
# Attach gdbserver to the app process
|
2013-08-12 12:30:04 +00:00
|
|
|
PID=$($ADB shell ps | grep com.skia | awk '{print $2}')
|
2013-04-29 12:09:31 +00:00
|
|
|
echo "Attaching to pid: $PID"
|
2014-02-13 22:31:48 +00:00
|
|
|
$ADB shell /data/local/tmp/gdbserver :$PORT --attach $PID &
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|