1#!/bin/bash 2# 3# android_gdb_native: Pushes gdbserver, connects to specified Skia app, 4# and enters command line debugging environment. 5 6SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 7source $SCRIPT_DIR/android_setup.sh 8 9# setup the gdbserver 10export BUILDTYPE # from android_setup.sh 11$SCRIPT_DIR/android_gdbserver -d ${DEVICE_ID} ${APP_ARGS[@]} 12 13# quit if gdbserver setup failed 14if [[ "$?" != "0" ]]; then 15 echo "ERROR: gdbserver failed to setup properly." 16 exit 1 17fi 18 19# Wait for gdbserver 20sleep 2 21 22# variables that must match those in gdb_server 23GDB_TMP_DIR=$(pwd)/android_gdb_tmp 24APP_NAME=${APP_ARGS[0]} 25PORT=5039 26 27# Set up gdb commands 28GDBSETUP=$GDB_TMP_DIR/gdb.setup 29{ 30 echo "file ${GDB_TMP_DIR}/skia_launcher" 31 echo "target remote :${PORT}" 32 echo "set solib-absolute-prefix ${GDB_TMP_DIR}" 33 echo "set solib-search-path ${GDB_TMP_DIR}" 34 35 # The apps shared library symbols are not loaded by default so we 36 # load them here. 37 echo "break launch_app" 38 echo "continue" 39 echo "sharedLibrary ${APP_NAME}" 40 41 # Load libskia_android.so here. 42 echo "sharedLibrary skia_android" 43} > $GDBSETUP 44 45 46# Launch gdb client 47echo "Entering gdb client shell" 48GDB_COMMAND=$(command ls "$ANDROID_TOOLCHAIN"/*-gdb | head -n1) 49"$GDB_COMMAND" -x $GDBSETUP 50 51# Clean up: 52# We could 'rm -rf $GDB_TMP_DIR', but doing so would cause subsequent debugging 53# sessions to take longer than necessary. The tradeoff is to now force the user 54# to remove the directory when they are done debugging. 55rm $GDBSETUP 56