[eglib] Don't define _FORTIFY_SOURCE on Cygwin builds (#18308)
[mono-project.git] / sdks / android / xa-lldb
blob77b4371a9893faf584413e9df957f3f0cdf69354
1 #!/bin/bash
3 set -xi
5 PLATFORM_TOOLS_DIR=$HOME/android-toolchain/sdk/platform-tools
7 shell()
9 $PLATFORM_TOOLS_DIR/adb -s "$DEVICE" shell "$@"
12 while getopts "d:" option ; do
13 case "$option" in
15 DEVICE=$OPTARG
16 shift 2
18 esac
19 done
21 # Directory with lldb binaries/debug servers
22 LLDB_MONO_DIR=`dirname $0`
23 NOW=`date +%s`
25 if [ "$DEVICE" = "" ]; then
26 DEVICE_COUNT=`$PLATFORM_TOOLS_DIR/adb devices | grep 'device$' | wc -l`
27 if [ $DEVICE_COUNT -eq 1 ]; then
28 DEVICE=`$PLATFORM_TOOLS_DIR/adb devices | grep 'device$' | awk -F"\t+" '{print $1}'`
31 echo "Device: $DEVICE"
33 SOCK="platform-${NOW}.sock"
34 ARCH=$(shell "getprop ro.product.cpu.abi" | tr -d '\r')
36 LLDB_SERVER_ARCH=$ARCH
37 if [ "$ARCH" = "armeabi-v7a" ]; then
38 LLDB_SERVER_ARCH="armeabi"
41 echo "Architecture: $ARCH"
43 #LLDB_DIR=$HOME/Library/Android/sdk/lldb/2.2/android
44 LLDB_DIR=$LLDB_MONO_DIR/android
46 R_TMP=/data/local/tmp
47 LLDB=/data/data/org.mono.android.AndroidTestRunner/lldb
48 LLDB_BIN=$LLDB/bin
49 LLDB_SERVER=$LLDB_BIN/lldb-server
50 START_SERVER=$LLDB_BIN/start_lldb_server.sh
51 LLDB_LOCAL_SERVER=$LLDB_DIR/$LLDB_SERVER_ARCH/lldb-server
53 if [ ! -f $LLDB_LOCAL_SERVER ]; then
54 echo "Unable to find llvm-server binary at $LLDB_LOCAL_SERVER."
55 exit 1
58 echo "Copying lldb-server to device..."
59 $PLATFORM_TOOLS_DIR/adb -s "$DEVICE" push $LLDB_DIR/$LLDB_SERVER_ARCH/lldb-server $R_TMP
60 $PLATFORM_TOOLS_DIR/adb -s "$DEVICE" push $LLDB_DIR/start_lldb_server.sh $R_TMP
62 $PLATFORM_TOOLS_DIR/adb -s "$DEVICE" shell 'setprop debug.mono.lldb wait:`date +%s`'
63 $PLATFORM_TOOLS_DIR/adb -s "$DEVICE" shell 'setprop debug.mono.debug 1'
64 # FIXME: Add to it
65 $PLATFORM_TOOLS_DIR/adb -s "$DEVICE" shell 'setprop debug.mono.env MONO_LLDB=1'
67 echo "Starting app..."
68 shell "am instrument org.mono.android.AndroidTestRunner/org.mono.android.AndroidRunner "
69 shell "run-as org.mono.android.AndroidTestRunner mkdir -p $LLDB_BIN"
70 shell "rm -f $LLDB_SERVER"
71 shell "cat $R_TMP/lldb-server | run-as org.mono.android.AndroidTestRunner sh -c \"cat > $LLDB_SERVER && chmod 700 $LLDB_SERVER\""
72 shell "cat $R_TMP/start_lldb_server.sh | run-as org.mono.android.AndroidTestRunner sh -c \"cat > $START_SERVER && chmod 700 $START_SERVER\""
74 echo "Waiting for app to start..."
76 for i in 1 2 3 4 5; do
77 PID=$(shell "ps" | grep "org.mono.android.AndroidTestRunner\s*$" | awk -F' +' '{print $2}')
79 if [ "$PID" != "" ]; then
80 break
82 sleep 1
83 done
85 if [ "$PID" == "" ]; then
86 echo "Can't find process pid."
87 exit 1
89 echo "pid == $PID"
91 START_FILE=/tmp/lldb_commands.$NOW
92 echo "platform select remote-android
93 platform connect unix-abstract-connect://[$DEVICE]$LLDB/tmp/$SOCK
94 settings set auto-confirm true
95 settings set plugin.symbol-file.dwarf.comp-dir-symlink-paths /proc/self/cwd
96 process attach -p $PID
97 p (void)monodroid_clear_lldb_wait()
98 $COMMANDS" > $START_FILE
100 echo -n "Starting lldb server in the background"
101 shell "run-as org.mono.android.AndroidTestRunner $START_SERVER $LLDB unix-abstract $LLDB/tmp $SOCK \"lldb process:gdb-remote packets\""&
102 for i in {1..5}; do
103 echo -n ' .'
104 sleep 1
105 done
106 echo " done."
108 declare -a PIDS=( `pgrep -P $!` "$!" )
110 $LLDB_MONO_DIR/lldb -s $START_FILE
112 rm $START_FILE
113 kill "${PIDS[@]}"