3 # android_gdb_app: Pushes gdbserver, launches Viewer, and connects
4 # the debugging environment.
6 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7 source $SCRIPT_DIR/android_setup.sh "$@"
8 source $SCRIPT_DIR/utils/setup_adb.sh
10 APP_ARGS=( "Viewer" ${APP_ARGS[*]} )
13 activity="org.skia.viewer/org.skia.viewer.ViewerActivity"
14 activityShort="org.skia.viewer"
16 # Forward local to remote socket connection.
17 $ADB $DEVICE_SERIAL forward "tcp:$PORT" "tcp:$PORT"
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
25 echo "Could not automatically determine OS!"
29 # We need the debug symbols from these files
30 GDB_TMP_DIR=$SKIA_OUT/android_gdb_tmp
33 echo "Pushing gdbserver..."
34 adb_push_if_needed $ANDROID_TOOLCHAIN/gdbserver /data/local/tmp
37 echo "Launching the app..."
38 $ADB $DEVICE_SERIAL shell "am start -n ${activity} --es cmdLineFlags \"${APP_ARGS[*]:1}\""
40 # Wait for app process to initialize
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 &
52 GDBSETUP=$GDB_TMP_DIR/gdb.setup
53 echo "target remote :$PORT" >> $GDBSETUP
57 echo "Entering gdb client shell"
58 ${ANDROID_TOOLCHAIN}/host_prebuilt/bin/gdb-orig -x $GDBSETUP
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.