aboutsummaryrefslogtreecommitdiffhomepage
path: root/platform_tools/android/bin/android_gdbserver
blob: a7b20bff9794cd315b945f5bebbc71ea8081b28a (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
#
# android_gdbserver: Pushes gdbserver. Starts debugging environment.

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

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

BUILD_DIR="${SKIA_OUT}/${BUILDTYPE}"
TARGET_LIBRARY="${BUILD_DIR}/lib/lib${APP_NAME}.so"
if [ ! -f "$TARGET_LIBRARY" ]
then
  echo "Unable to find the ${APP_NAME} library at ${TARGET_LIBRARY}."
  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 "Copying symbol files"
if [[ $ANDROID_ARCH == *64* ]]; then
  SYSTEM_LIBRARY_PATH=/system/lib64
else
  SYSTEM_LIBRARY_PATH=/system/lib
fi
for library_file in \
    libc.so \
    libc++.so \
    libstdc++.so \
    libm.so \
    liblog.so \
    libz.so \
    libgccdemangle.so \
    libsigchain.so \
    libcutils.so \
    libunwind.so \
    libunwind-ptrace.so \
    libbacktrace.so \
    libutils.so \
    libstlport.so \
    libGLES_trace.so \
    libEGL.so \
    libGLESv2.so \
    ; do
    ANDROID_LS=`$ADB $DEVICE_SERIAL shell ls -ld ${SYSTEM_LIBRARY_PATH}/${library_file}`
    if [ "${ANDROID_LS:0:1}" == "-" ]; then
      adb_pull_if_needed "${SYSTEM_LIBRARY_PATH}/${library_file}" $GDB_TMP_DIR
    fi
done

if [[ $ANDROID_ARCH == *64* ]]; then
  adb_pull_if_needed /system/bin/linker64 $GDB_TMP_DIR
else
  adb_pull_if_needed /system/bin/linker $GDB_TMP_DIR
fi

echo "Pushing app..."
for file in \
    "${BUILD_DIR}/skia_launcher" \
    "${BUILD_DIR}/lib/libskia_android.so" \
    "${BUILD_DIR}/lib/lib${APP_NAME}.so" \
    ; do
    cp "$file" $GDB_TMP_DIR
    adb_push_if_needed "$file" /data/local/tmp
done

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

echo "Setting up port forward"
$ADB forward "tcp:5039" "tcp:5039"

# Kill all previous instances of gdbserver and the app to rid all port overriding errors.
echo "Killing any running Skia processes."
$ADB shell ps | grep gdbserver | awk '{print $2}' | xargs $ADB shell kill
$ADB shell ps | grep ${APP_NAME} | awk '{print $2}' | xargs $ADB shell kill

# Starting up gdbserver in android shell
echo "Starting gdbserver with command: ${APP_ARGS[@]}"
$ADB shell LD_LIBRARY_PATH=/data/local/tmp:\$LD_LIBRARY_PATH /data/local/tmp/gdbserver :5039 /data/local/tmp/skia_launcher ${APP_ARGS[@]} &