• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# android_gdb_app: Pushes gdbserver, launches Viewer, and connects
4# the debugging environment.
5
6SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7source $SCRIPT_DIR/android_setup.sh "$@"
8source $SCRIPT_DIR/utils/setup_adb.sh
9
10APP_ARGS=( "Viewer" ${APP_ARGS[*]} )
11PORT=5039
12
13activity="org.skia.viewer/org.skia.viewer.ViewerActivity"
14activityShort="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.
20if [ $(uname) == "Linux" ]; then
21    $ADB $DEVICE_SERIAL shell ps | grep gdbserver | awk '{print $2}' | xargs -r $ADB $DEVICE_SERIAL shell kill
22elif [ $(uname) == "Darwin" ]; then
23    $ADB $DEVICE_SERIAL shell ps | grep gdbserver | awk '{print $2}' | xargs $ADB $DEVICE_SERIAL shell kill
24else
25    echo "Could not automatically determine OS!"
26    exit 1;
27fi
28
29# We need the debug symbols from these files
30GDB_TMP_DIR=$SKIA_OUT/android_gdb_tmp
31mkdir -p $GDB_TMP_DIR
32
33echo "Pushing gdbserver..."
34adb_push_if_needed $ANDROID_TOOLCHAIN/gdbserver /data/local/tmp
35
36# Launch the app
37echo "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
41sleep 2
42
43# Attach gdbserver to the app process
44PID=$($ADB shell ps | grep ${activityShort} | awk '{print $2}')
45echo "Attaching to pid: $PID"
46$ADB $DEVICE_SERIAL shell /data/local/tmp/gdbserver :$PORT --attach $PID &
47
48# Wait for gdbserver
49sleep 2
50
51# Set up gdb commands
52GDBSETUP=$GDB_TMP_DIR/gdb.setup
53echo "target remote :$PORT" >> $GDBSETUP
54
55
56# Launch gdb client
57echo "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.
64rm $GDBSETUP
65
66
67