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