2013-04-29 12:09:31 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2016-07-12 16:12:39 +00:00
|
|
|
# android_gdb_app: Pushes gdbserver, launches Viewer, and connects
|
2015-02-03 23:07:30 +00:00
|
|
|
# the debugging environment.
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2015-12-10 22:14:56 +00:00
|
|
|
source $SCRIPT_DIR/android_setup.sh "$@"
|
2016-06-08 20:07:08 +00:00
|
|
|
source $SCRIPT_DIR/utils/setup_adb.sh
|
2013-04-29 12:09:31 +00:00
|
|
|
|
2016-07-12 16:12:39 +00:00
|
|
|
APP_ARGS=( "Viewer" ${APP_ARGS[*]} )
|
2013-08-06 20:32:29 +00:00
|
|
|
PORT=5039
|
2013-08-02 15:14:24 +00:00
|
|
|
|
2016-07-12 16:12:39 +00:00
|
|
|
activity="org.skia.viewer/org.skia.viewer.ViewerActivity"
|
|
|
|
activityShort="org.skia.viewer"
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
# Forward local to remote socket connection.
|
2015-02-03 23:07:30 +00:00
|
|
|
$ADB $DEVICE_SERIAL forward "tcp:$PORT" "tcp:$PORT"
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
# We kill all previous instances of gdbserver to rid all port overriding errors.
|
2015-02-03 23:07:30 +00:00
|
|
|
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
|
|
|
|
else
|
|
|
|
echo "Could not automatically determine OS!"
|
|
|
|
exit 1;
|
|
|
|
fi
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
# We need the debug symbols from these files
|
2015-07-10 18:05:10 +00:00
|
|
|
GDB_TMP_DIR=$SKIA_OUT/android_gdb_tmp
|
2013-08-06 20:32:29 +00:00
|
|
|
mkdir -p $GDB_TMP_DIR
|
2013-04-29 12:09:31 +00:00
|
|
|
|
2014-02-13 22:31:48 +00:00
|
|
|
echo "Pushing gdbserver..."
|
2016-04-18 18:01:02 +00:00
|
|
|
adb_push_if_needed $ANDROID_TOOLCHAIN/gdbserver /data/local/tmp
|
2014-02-13 22:31:48 +00:00
|
|
|
|
2013-04-29 12:09:31 +00:00
|
|
|
# Launch the app
|
2015-02-03 23:07:30 +00:00
|
|
|
echo "Launching the app..."
|
2016-06-08 20:07:08 +00:00
|
|
|
$ADB $DEVICE_SERIAL shell "am start -n ${activity} --es cmdLineFlags \"${APP_ARGS[*]:1}\""
|
2015-02-03 23:07:30 +00:00
|
|
|
|
|
|
|
# Wait for app process to initialize
|
|
|
|
sleep 2
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
# Attach gdbserver to the app process
|
2016-06-08 20:07:08 +00:00
|
|
|
PID=$($ADB shell ps | grep ${activityShort} | awk '{print $2}')
|
2013-04-29 12:09:31 +00:00
|
|
|
echo "Attaching to pid: $PID"
|
2015-02-03 23:07:30 +00:00
|
|
|
$ADB $DEVICE_SERIAL shell /data/local/tmp/gdbserver :$PORT --attach $PID &
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
# Wait for gdbserver
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
# Set up gdb commands
|
|
|
|
GDBSETUP=$GDB_TMP_DIR/gdb.setup
|
|
|
|
echo "target remote :$PORT" >> $GDBSETUP
|
2016-05-02 16:19:58 +00:00
|
|
|
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
# Launch gdb client
|
|
|
|
echo "Entering gdb client shell"
|
2016-05-02 16:19:58 +00:00
|
|
|
${ANDROID_TOOLCHAIN}/host_prebuilt/bin/gdb-orig -x $GDBSETUP
|
2013-04-29 12:09:31 +00:00
|
|
|
|
2015-02-03 23:07:30 +00:00
|
|
|
# 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.
|
|
|
|
rm $GDBSETUP
|
|
|
|
|
2013-04-29 12:09:31 +00:00
|
|
|
|