• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# android_gdb_native: Pushes gdbserver, connects to specified Skia app,
4#                     and enters command line debugging environment.
5
6SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7source $SCRIPT_DIR/utils/android_setup.sh
8
9# setup the gdbserver
10$SCRIPT_DIR/android_gdbserver -C ${SKIA_OUT} ${APP_ARGS[@]}
11
12# quit if gdbserver setup failed
13if [[ "$?" != "0" ]]; then
14  echo "ERROR: gdbserver failed to setup properly."
15  exit 1
16fi
17
18# Wait for gdbserver
19sleep 2
20
21# variables that must match those in gdb_server
22GDB_TMP_DIR=$SKIA_OUT/android_gdb_tmp
23APP_NAME=${APP_ARGS[0]}
24PORT=5039
25
26# Set up gdb commands
27GDBSETUP=$GDB_TMP_DIR/gdb.setup
28{
29    echo "file ${GDB_TMP_DIR}/${APP_NAME}"
30    echo "target remote :${PORT}"
31    echo "set solib-absolute-prefix ${GDB_TMP_DIR}"
32    echo "set solib-search-path ${GDB_TMP_DIR}"
33
34    echo "break main"
35    echo "continue"
36} > $GDBSETUP
37
38
39# Launch gdb client
40HOST=`uname | tr '[A-Z]' '[a-z]'`
41if [ $HOST == "darwin" ]; then
42    GDB_HOST=$ANDROID_NDK_ROOT/prebuilt/darwin-x86_64/bin/gdb
43elif [ $HOST == "linux" ]; then
44     GDB_HOST=$ANDROID_NDK_ROOT/prebuilt/linux-x86_64/bin/gdb
45else
46    echo "Could not automatically determine OS!"
47    exit 1;
48fi
49
50echo "Entering gdb client shell"
51$GDB_HOST -x $GDBSETUP
52
53# Clean up:
54# We could 'rm -rf $GDB_TMP_DIR', but doing so would cause subsequent debugging
55# sessions to take longer than necessary. The tradeoff is to now force the user
56# to remove the directory when they are done debugging.
57rm $GDBSETUP
58