android_gdb_exe revision dcdd57faf02fb4fd23bb8265392b9c22e068907e
1#!/bin/bash
2#
3# android_gdb: Pushes gdbserver. Connects and enters debugging environment.
4
5SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6APP_NAME=$(basename $1)
7PORT=5039
8
9# Collect extra arguments to be passed to the Skia binary
10shift
11while (( "$#" )); do
12  APP_ARGS="$APP_ARGS $1"
13  shift
14done
15
16source $SCRIPT_DIR/android_setup.sh
17source $SCRIPT_DIR/utils/setup_adb.sh
18
19# We need the debug symbols from these files
20GDB_TMP_DIR=$(pwd)/android_gdb_tmp
21mkdir $GDB_TMP_DIR
22echo "Copying symbol files"
23$ADB pull /system/bin/skia_launcher $GDB_TMP_DIR
24$ADB pull /system/lib/libc.so $GDB_TMP_DIR
25$ADB pull /data/data/com.skia/lib/lib$APP_NAME.so $GDB_TMP_DIR
26
27echo "Checking for skia_launcher app..."
28if [ ! -f $GDB_TMP_DIR/skia_launcher ]
29then
30    echo "Unable for find the skia_launcher on the device"
31    rm -rf $GDB_TMP_DIR
32    exit 1;
33fi
34
35echo "Checking for $APP_NAME library..."
36if [ ! -f $GDB_TMP_DIR/lib$APP_NAME.so ]
37then
38    echo "Unable for find the app's shared library on the device"
39    rm -rf $GDB_TMP_DIR
40    exit 1;
41fi
42
43echo "Pushing gdbserver..."
44$ADB remount
45$ADB push $ANDROID_TOOLCHAIN/../gdbserver /system/bin/gdbserver
46
47echo "Setting up port forward"
48$ADB forward "tcp:5039" "tcp:5039"
49
50# Kill all previous instances of gdbserver and skia_launcher to rid all port overriding errors.
51echo "Killing any running Skia processes."
52$ADB shell ps | grep gdbserver | awk '{print $2}' | xargs $ADB shell kill
53$ADB shell ps | grep skia_launcher | awk '{print $2}' | xargs $ADB shell kill
54
55# Starting up gdbserver in android shell
56echo "Starting gdbserver with command: skia_launcher $APP_NAME$APP_ARGS"
57$ADB shell gdbserver :5039 /system/bin/skia_launcher $APP_NAME$APP_ARGS &
58
59# Wait for gdbserver
60sleep 2
61
62# Set up gdb commands
63GDBSETUP=$GDB_TMP_DIR/gdb.setup
64echo "file $GDB_TMP_DIR/skia_launcher" >> $GDBSETUP
65echo "target remote :$PORT" >> $GDBSETUP
66echo "set solib-absolute-prefix $GDB_TMP_DIR" >> $GDBSETUP
67echo "set solib-search-path $GDB_TMP_DIR" >> $GDBSETUP
68
69# The apps shared library symbols are not loaded by default so we load them here
70echo "break skia_launcher.cpp:launch_app" >> $GDBSETUP
71echo "continue" >> $GDBSETUP
72echo "sharedLibrary $APP_NAME" >> $GDBSETUP
73
74
75# Launch gdb client
76echo "Entering gdb client shell"
77$ANDROID_TOOLCHAIN/arm-linux-androideabi-gdb -x $GDBSETUP
78
79# Clean up
80rm -rf $GDB_TMP_DIR