1#!/bin/bash 2# 3# android_gdbserver: Pushes gdbserver. Starts debugging environment. 4 5SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 6source $SCRIPT_DIR/utils/android_setup.sh 7source $SCRIPT_DIR/utils/setup_adb.sh 8 9APP_NAME=${APP_ARGS[0]} 10 11TARGET_EXE="${SKIA_OUT}/${APP_NAME}" 12if [ ! -f "$TARGET_EXE" ] 13then 14 echo "Unable to find ${TARGET_EXE}." 15 exit 1 16fi 17 18IS_64_BIT="false" 19GN_TARGET_CPU=$(gn args --list=target_cpu $SKIA_OUT \ 20 | grep "Current value = " \ 21 | sed -e s/"Current value = "// -e s/\"//g -e s/" "//g) 22if [[ $GN_TARGET_CPU == *64* ]]; then 23 IS_64_BIT="true" 24fi 25 26# We need the debug symbols from these files 27GDB_TMP_DIR=$SKIA_OUT/android_gdb_tmp 28mkdir -p $GDB_TMP_DIR 29 30echo "Copying symbol files" 31if [[ $IS_64_BIT == "true" ]]; then 32 SYSTEM_LIBRARY_PATH=/system/lib64 33 echo "64 bit!" 34else 35 SYSTEM_LIBRARY_PATH=/system/lib 36fi 37for library_file in \ 38 libc.so \ 39 libc++.so \ 40 libstdc++.so \ 41 libm.so \ 42 liblog.so \ 43 libz.so \ 44 libsigchain.so \ 45 libcutils.so \ 46 libunwind.so \ 47 libbacktrace.so \ 48 libutils.so \ 49 libEGL.so \ 50 libGLESv2.so \ 51 ; do 52 ANDROID_LS=`$ADB $DEVICE_SERIAL shell -x ls -ld ${SYSTEM_LIBRARY_PATH}/${library_file}` 53 if [ "${ANDROID_LS:0:1}" == "-" ]; then 54 adb_pull_if_needed "${SYSTEM_LIBRARY_PATH}/${library_file}" $GDB_TMP_DIR 55 fi 56done 57 58if [[ $IS_64_BIT == "true" ]]; then 59 adb_pull_if_needed /system/bin/linker64 $GDB_TMP_DIR 60else 61 adb_pull_if_needed /system/bin/linker $GDB_TMP_DIR 62fi 63 64echo "Pushing app..." 65cp "$TARGET_EXE" $GDB_TMP_DIR 66adb_push_if_needed "${TARGET_EXE}" /data/local/tmp 67 68echo "Pushing gdbserver..." 69adb_push_if_needed $SKIA_OUT/gdbserver /data/local/tmp 70 71echo "Setting up port forward" 72$ADB forward "tcp:5039" "tcp:5039" 73 74# Kill all previous instances of gdbserver and the app to rid all port overriding errors. 75echo "Killing any running Skia processes." 76set +e 77$ADB shell ps | grep gdbserver | awk '{print $2}' | xargs $ADB shell kill 2> /dev/null 78$ADB shell ps | grep ${APP_NAME} | awk '{print $2}' | xargs $ADB shell kill 2> /dev/null 79set -e 80 81# Starting up gdbserver in android shell 82echo "Starting gdbserver with command: ${APP_ARGS[@]}" 83$ADB shell /data/local/tmp/gdbserver :5039 /data/local/tmp/${APP_ARGS[@]} & 84