OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # | 2 # |
3 # android_gdb: Pushes parameter binary and gdbserver. Connects | 3 # android_gdb_app: Pushes gdbserver, launches sampleApp, and connects |
4 # and enters debugging environment. | 4 # the debugging environment. |
5 | 5 |
6 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | 6 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
7 source $SCRIPT_DIR/android_setup.sh | 7 source $SCRIPT_DIR/android_setup.sh |
8 | 8 |
9 APP_NAME=${APP_ARGS[0]} | 9 APP_NAME=${APP_ARGS[0]} |
10 PORT=5039 | 10 PORT=5039 |
11 | 11 |
12 source $SCRIPT_DIR/utils/setup_adb.sh | 12 source $SCRIPT_DIR/utils/setup_adb.sh |
13 | 13 |
14 | 14 |
15 # Forward local to remote socket connection. | 15 # Forward local to remote socket connection. |
16 $ADB forward "tcp:$PORT" "tcp:$PORT" | 16 $ADB $DEVICE_SERIAL forward "tcp:$PORT" "tcp:$PORT" |
17 | 17 |
18 # We kill all previous instances of gdbserver to rid all port overriding errors. | 18 # We kill all previous instances of gdbserver to rid all port overriding errors. |
19 $ADB shell ps | grep gdbserver | awk '{print $2}' | xargs -r $ADB shell kill | 19 if [ $(uname) == "Linux" ]; then |
| 20 $ADB $DEVICE_SERIAL shell ps | grep gdbserver | awk '{print $2}' | xargs -r
$ADB $DEVICE_SERIAL shell kill |
| 21 elif [ $(uname) == "Darwin" ]; then |
| 22 $ADB $DEVICE_SERIAL shell ps | grep gdbserver | awk '{print $2}' | xargs $AD
B $DEVICE_SERIAL shell kill |
| 23 else |
| 24 echo "Could not automatically determine OS!" |
| 25 exit 1; |
| 26 fi |
20 | 27 |
21 # We need the debug symbols from these files | 28 # We need the debug symbols from these files |
22 GDB_TMP_DIR=$(pwd)/android_gdb_tmp | 29 GDB_TMP_DIR=$(pwd)/android_gdb_tmp |
23 mkdir -p $GDB_TMP_DIR | 30 mkdir -p $GDB_TMP_DIR |
24 echo "Copying symbol files" | 31 echo "Copying symbol files" |
25 adb_pull_if_needed /system/bin/app_process $GDB_TMP_DIR | 32 adb_pull_if_needed /system/bin/app_process $GDB_TMP_DIR |
26 adb_pull_if_needed /system/lib/libc.so $GDB_TMP_DIR | 33 adb_pull_if_needed /system/lib/libc.so $GDB_TMP_DIR |
27 adb_pull_if_needed /data/data/com.skia/lib/libskia_android.so $GDB_TMP_DIR | 34 adb_pull_if_needed /data/data/com.skia/lib/libskia_android.so $GDB_TMP_DIR |
28 adb_pull_if_needed /data/data/com.skia/lib/libSampleApp.so $GDB_TMP_DIR | 35 adb_pull_if_needed /data/data/com.skia/lib/libSampleApp.so $GDB_TMP_DIR |
29 | 36 |
30 echo "Pushing gdbserver..." | 37 echo "Pushing gdbserver..." |
31 adb_push_if_needed $ANDROID_TOOLCHAIN/../gdbserver /data/local/tmp | 38 adb_push_if_needed $ANDROID_TOOLCHAIN/../gdbserver /data/local/tmp |
32 | 39 |
33 # Launch the app | 40 # Launch the app |
34 SK_COMMAND="$APP_ARGS" | 41 echo "Launching the app..." |
35 echo "Running command $SK_COMMAND" | 42 $ADB $DEVICE_SERIAL shell am start -n com.skia/com.skia.SkiaSampleActivity |
36 adb shell am start -n com.skia/com.skia.SkiaSampleActivity | 43 |
| 44 # Wait for app process to initialize |
| 45 sleep 2 |
37 | 46 |
38 # Attach gdbserver to the app process | 47 # Attach gdbserver to the app process |
39 PID=$($ADB shell ps | grep com.skia | awk '{print $2}') | 48 PID=$($ADB shell ps | grep com.skia | awk '{print $2}') |
40 echo "Attaching to pid: $PID" | 49 echo "Attaching to pid: $PID" |
41 $ADB shell /data/local/tmp/gdbserver :$PORT --attach $PID & | 50 $ADB $DEVICE_SERIAL shell /data/local/tmp/gdbserver :$PORT --attach $PID & |
42 | 51 |
43 # Wait for gdbserver | 52 # Wait for gdbserver |
44 sleep 2 | 53 sleep 2 |
45 | 54 |
46 # Set up gdb commands | 55 # Set up gdb commands |
47 GDBSETUP=$GDB_TMP_DIR/gdb.setup | 56 GDBSETUP=$GDB_TMP_DIR/gdb.setup |
48 echo "file $GDB_TMP_DIR/app_process" >> $GDBSETUP | 57 echo "file $GDB_TMP_DIR/app_process" >> $GDBSETUP |
49 echo "target remote :$PORT" >> $GDBSETUP | 58 echo "target remote :$PORT" >> $GDBSETUP |
50 echo "set solib-absolute-prefix $GDB_TMP_DIR" >> $GDBSETUP | 59 echo "set solib-absolute-prefix $GDB_TMP_DIR" >> $GDBSETUP |
51 echo "set solib-search-path $GDB_TMP_DIR" >> $GDBSETUP | 60 echo "set solib-search-path $GDB_TMP_DIR" >> $GDBSETUP |
52 | 61 |
53 # Launch gdb client | 62 # Launch gdb client |
54 echo "Entering gdb client shell" | 63 echo "Entering gdb client shell" |
55 GDB_COMMAND=$(command ls "$ANDROID_TOOLCHAIN"/*-gdb | head -n1) | 64 GDB_COMMAND=$(command ls "$ANDROID_TOOLCHAIN"/*-gdb | head -n1) |
56 "$GDB_COMMAND" -x $GDBSETUP | 65 "$GDB_COMMAND" -x $GDBSETUP |
57 | 66 |
58 # Clean up | 67 # Clean up: |
59 rm -rf $GDB_TMP_DIR | 68 # We could 'rm -rf $GDB_TMP_DIR', but doing so would cause subsequent debugging |
| 69 # sessions to take longer than necessary. The tradeoff is to now force the user |
| 70 # to remove the directory when they are done debugging. |
| 71 rm $GDBSETUP |
60 | 72 |
| 73 |
OLD | NEW |