aboutsummaryrefslogtreecommitdiffhomepage
path: root/platform_tools/android/bin/android_gdb_app
blob: 046fee3dea4b3f1361e19490e7e927d5e90f6cf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
#
# android_gdb_app: Pushes gdbserver, launches sampleApp, and connects
# the debugging environment.

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $SCRIPT_DIR/android_setup.sh "$@"

APP_NAME=${APP_ARGS[0]}
PORT=5039

source $SCRIPT_DIR/utils/setup_adb.sh


# Forward local to remote socket connection.
$ADB $DEVICE_SERIAL forward "tcp:$PORT" "tcp:$PORT"

# We kill all previous instances of gdbserver to rid all port overriding errors.
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

# We need the debug symbols from these files
GDB_TMP_DIR=$SKIA_OUT/android_gdb_tmp
mkdir -p $GDB_TMP_DIR

echo "Pushing gdbserver..."
adb_push_if_needed $ANDROID_TOOLCHAIN/gdbserver /data/local/tmp

# Launch the app
echo "Launching the app..."
$ADB $DEVICE_SERIAL shell am start -n com.skia.sample_app/com.skia.SkiaSampleActivity

# Wait for app process to initialize
sleep 2

# Attach gdbserver to the app process
PID=$($ADB shell ps | grep com.skia.sample_app | awk '{print $2}')
echo "Attaching to pid: $PID"
$ADB $DEVICE_SERIAL shell /data/local/tmp/gdbserver :$PORT --attach $PID &

# Wait for gdbserver
sleep 2

# Set up gdb commands
GDBSETUP=$GDB_TMP_DIR/gdb.setup
echo "target remote :$PORT" >> $GDBSETUP


# Launch gdb client
echo "Entering gdb client shell"
${ANDROID_TOOLCHAIN}/host_prebuilt/bin/gdb-orig -x $GDBSETUP

# 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