1 #!/bin/bash 2 # 3 # android_gdb_app: Pushes gdbserver, launches Viewer, and connects 4 # the debugging environment. 5 6 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 7 source $SCRIPT_DIR/android_setup.sh "$@" 8 source $SCRIPT_DIR/utils/setup_adb.sh 9 10 APP_ARGS=( "Viewer" ${APP_ARGS[*]} ) 11 PORT=5039 12 13 activity="org.skia.viewer/org.skia.viewer.ViewerActivity" 14 activityShort="org.skia.viewer" 15 16 # Forward local to remote socket connection. 17 $ADB $DEVICE_SERIAL forward "tcp:$PORT" "tcp:$PORT" 18 19 # We kill all previous instances of gdbserver to rid all port overriding errors. 20 if [ $(uname) == "Linux" ]; then 21 $ADB $DEVICE_SERIAL shell ps | grep gdbserver | awk '{print $2}' | xargs -r $ADB $DEVICE_SERIAL shell kill 22 elif [ $(uname) == "Darwin" ]; then 23 $ADB $DEVICE_SERIAL shell ps | grep gdbserver | awk '{print $2}' | xargs $ADB $DEVICE_SERIAL shell kill 24 else 25 echo "Could not automatically determine OS!" 26 exit 1; 27 fi 28 29 # We need the debug symbols from these files 30 GDB_TMP_DIR=$SKIA_OUT/android_gdb_tmp 31 mkdir -p $GDB_TMP_DIR 32 33 echo "Pushing gdbserver..." 34 adb_push_if_needed $ANDROID_TOOLCHAIN/gdbserver /data/local/tmp 35 36 # Launch the app 37 echo "Launching the app..." 38 $ADB $DEVICE_SERIAL shell "am start -n ${activity} --es cmdLineFlags \"${APP_ARGS[*]:1}\"" 39 40 # Wait for app process to initialize 41 sleep 2 42 43 # Attach gdbserver to the app process 44 PID=$($ADB shell ps | grep ${activityShort} | awk '{print $2}') 45 echo "Attaching to pid: $PID" 46 $ADB $DEVICE_SERIAL shell /data/local/tmp/gdbserver :$PORT --attach $PID & 47 48 # Wait for gdbserver 49 sleep 2 50 51 # Set up gdb commands 52 GDBSETUP=$GDB_TMP_DIR/gdb.setup 53 echo "target remote :$PORT" >> $GDBSETUP 54 55 56 # Launch gdb client 57 echo "Entering gdb client shell" 58 ${ANDROID_TOOLCHAIN}/host_prebuilt/bin/gdb-orig -x $GDBSETUP 59 60 # Clean up: 61 # We could 'rm -rf $GDB_TMP_DIR', but doing so would cause subsequent debugging 62 # sessions to take longer than necessary. The tradeoff is to now force the user 63 # to remove the directory when they are done debugging. 64 rm $GDBSETUP 65 66 67