blob: f0879fa10ff42b433206b4de160bd3882d5e222a [file] [log] [blame]
# android_gdb_app: Pushes gdbserver, launches sampleApp, and connects
# the debugging environment.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $SCRIPT_DIR/ "$@"
source $SCRIPT_DIR/utils/
# Forward local to remote socket connection.
$ADB $DEVICE_SERIAL forward "tcp:$PORT" "tcp:$PORT"
# We kill all previous instances of gdbserver to rid all port overriding errors.
if [ $(uname) == "Linux" ]; then
$ADB $DEVICE_SERIAL shell ps | grep gdbserver | awk '{print $2}' | xargs -r $ADB $DEVICE_SERIAL shell kill
elif [ $(uname) == "Darwin" ]; then
$ADB $DEVICE_SERIAL shell ps | grep gdbserver | awk '{print $2}' | xargs $ADB $DEVICE_SERIAL shell kill
echo "Could not automatically determine OS!"
exit 1;
# We need the debug symbols from these files
mkdir -p $GDB_TMP_DIR
echo "Copying symbol files"
adb_pull_if_needed /system/bin/app_process $GDB_TMP_DIR
adb_pull_if_needed /system/lib/ $GDB_TMP_DIR
adb_pull_if_needed /data/data/com.skia.sample_app/lib/ $GDB_TMP_DIR
adb_pull_if_needed /data/data/com.skia.sample_app/lib/ $GDB_TMP_DIR
echo "Pushing gdbserver..."
adb_push_if_needed $ANDROID_TOOLCHAIN/../gdbserver /data/local/tmp
# Launch the app
echo "Launching the app..."
$ADB $DEVICE_SERIAL shell am start -n com.skia.sample_app/com.skia.SkiaSampleActivity
# Wait for app process to initialize
sleep 2
# Attach gdbserver to the app process
PID=$($ADB shell ps | grep com.skia.sample_app | awk '{print $2}')
echo "Attaching to pid: $PID"
$ADB $DEVICE_SERIAL shell /data/local/tmp/gdbserver :$PORT --attach $PID &
# Wait for gdbserver
sleep 2
# Set up gdb commands
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"
GDB_COMMAND=$(command ls "$ANDROID_TOOLCHAIN"/*-gdb | head -n1)
# Clean up:
# We could 'rm -rf $GDB_TMP_DIR', but doing so would cause subsequent debugging
# sessions to take longer than necessary. The tradeoff is to now force the user
# to remove the directory when they are done debugging.