1 #!/bin/bash 2 # 3 # android_gdb_native: Pushes gdbserver, connects to specified Skia app, 4 # and enters command line debugging environment. 5 6 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 7 source $SCRIPT_DIR/utils/android_setup.sh 8 9 # setup the gdbserver 10 $SCRIPT_DIR/android_gdbserver -C ${SKIA_OUT} ${APP_ARGS[@]} 11 12 # quit if gdbserver setup failed 13 if [[ "$?" != "0" ]]; then 14 echo "ERROR: gdbserver failed to setup properly." 15 exit 1 16 fi 17 18 # Wait for gdbserver 19 sleep 2 20 21 # variables that must match those in gdb_server 22 GDB_TMP_DIR=$SKIA_OUT/android_gdb_tmp 23 APP_NAME=${APP_ARGS[0]} 24 PORT=5039 25 26 # Set up gdb commands 27 GDBSETUP=$GDB_TMP_DIR/gdb.setup 28 { 29 echo "file ${GDB_TMP_DIR}/${APP_NAME}" 30 echo "target remote :${PORT}" 31 echo "set solib-absolute-prefix ${GDB_TMP_DIR}" 32 echo "set solib-search-path ${GDB_TMP_DIR}" 33 34 echo "break main" 35 echo "continue" 36 } > $GDBSETUP 37 38 39 # Launch gdb client 40 HOST=`uname | tr '[A-Z]' '[a-z]'` 41 if [ $HOST == "darwin" ]; then 42 GDB_HOST=$ANDROID_NDK_ROOT/prebuilt/darwin-x86_64/bin/gdb 43 elif [ $HOST == "linux" ]; then 44 GDB_HOST=$ANDROID_NDK_ROOT/prebuilt/linux-x86_64/bin/gdb 45 else 46 echo "Could not automatically determine OS!" 47 exit 1; 48 fi 49 50 echo "Entering gdb client shell" 51 $GDB_HOST -x $GDBSETUP 52 53 # Clean up: 54 # We could 'rm -rf $GDB_TMP_DIR', but doing so would cause subsequent debugging 55 # sessions to take longer than necessary. The tradeoff is to now force the user 56 # to remove the directory when they are done debugging. 57 rm $GDBSETUP 58