This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathxa-lldb
executable file
·150 lines (120 loc) · 3.73 KB
/
xa-lldb
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
show_usage()
{
echo "Usage: xa-lldb [-d <DEVICE>] <csproj file> <xbuild arguments>."
}
shell()
{
adb -s "$DEVICE" shell "$@"
}
while getopts "d:" option ; do
case "$option" in
d)
DEVICE=$OPTARG
shift 2
;;
esac
done
if [ "$1" == "" ]; then
show_usage
exit 1
fi
# Directory with lldb binaries/debug servers
LLDB_MONO_DIR=`dirname $0`
NOW=`date +%s`
CFGFILE=/tmp/lldb-config.$NOW
# Collect information from the csproj
echo "Running: xabuild /t:_lldb /p:_LldbConfigFile=$CFGFILE /p:AndroidSdkPlatform=24 $*"
xabuild /t:_lldb /p:_LldbConfigFile=$CFGFILE /p:_AndroidApiLevel=24 $* > dbuild.log 2>&1;
if [ $? != 0 ]; then
cat dbuild.log
exit 1
fi
rm -f dbuild.log
. $CFGFILE
rm -f $CFGFILE
if [ ! -f $MANIFEST ]; then
echo "Manifest file $MANIFEST not found, make sure to pass the correct /p:Configuration argument."
exit 1
fi
echo "Package: $PKG"
echo "Manifest file: $MANIFEST"
# Obtain main activity class name
CLASS=`xpath $MANIFEST 'string(//activity[intent-filter/action/@android:name="android.intent.action.MAIN" and intent-filter/category/@android:name="android.intent.category.LAUNCHER"]/@android:name)' 2>/dev/null`
if [ $? != 0 ]; then
exit 1
fi
echo "MainActivity class: $CLASS"
if [ "$DEVICE" = "" ]; then
DEVICE_COUNT=`adb devices | grep 'device$' | wc -l`
if [ $DEVICE_COUNT -eq 1 ]; then
DEVICE=`adb devices | grep 'device$' | awk -F"\t+" '{print $1}'`
fi
fi
echo "Device: $DEVICE"
SOCK="platform-${NOW}.sock"
ARCH=$(shell "getprop ro.product.cpu.abi" | tr -d '\r')
LLDB_SERVER_ARCH=$ARCH
if [ "$ARCH" = "armeabi-v7a" ]; then
LLDB_SERVER_ARCH="armeabi"
fi
echo "Architecture: $ARCH"
#LLDB_DIR=$HOME/Library/Android/sdk/lldb/2.2/android
LLDB_DIR=$LLDB_MONO_DIR/android
R_TMP=/data/local/tmp
LLDB=/data/data/$PKG/lldb
LLDB_BIN=$LLDB/bin
LLDB_SERVER=$LLDB_BIN/lldb-server
START_SERVER=$LLDB_BIN/start_lldb_server.sh
LLDB_LOCAL_SERVER=$LLDB_DIR/$LLDB_SERVER_ARCH/lldb-server
if [ ! -f $LLDB_LOCAL_SERVER ]; then
echo "Unable to find llvm-server binary at $LLDB_LOCAL_SERVER."
exit 1
fi
echo "Copying lldb-server to device..."
adb -s "$DEVICE" push $LLDB_DIR/$LLDB_SERVER_ARCH/lldb-server $R_TMP
adb -s "$DEVICE" push $LLDB_DIR/start_lldb_server.sh $R_TMP
adb -s "$DEVICE" shell 'setprop debug.mono.gdb wait:`date +%s`'
adb -s "$DEVICE" shell 'setprop debug.mono.debug 1'
# FIXME: Add to it
adb -s "$DEVICE" shell 'setprop debug.mono.env MONO_LLDB=1'
echo "Starting app..."
shell "am start -S -n $PKG/$CLASS -a android.intent.action.MAIN -c android.intent.category.LAUNCHER"
shell "run-as $PKG mkdir -p $LLDB_BIN"
shell "rm -f $LLDB_SERVER"
shell "cat $R_TMP/lldb-server | run-as $PKG sh -c \"cat > $LLDB_SERVER && chmod 700 $LLDB_SERVER\""
shell "cat $R_TMP/start_lldb_server.sh | run-as $PKG sh -c \"cat > $START_SERVER && chmod 700 $START_SERVER\""
echo "Waiting for app to start..."
for i in 1 2 3 4 5; do
PID=$(shell "ps" | grep "$PKG\s*$" | awk -F' +' '{print $2}')
if [ "$PID" != "" ]; then
break
fi
sleep 1
done
if [ "$PID" == "" ]; then
echo "Can't find process pid."
exit 1
fi
echo "pid == $PID"
START_FILE=/tmp/lldb_commands.$NOW
echo "platform select remote-android
platform connect unix-abstract-connect://[$DEVICE]$LLDB/tmp/$SOCK
settings set auto-confirm true
settings set plugin.symbol-file.dwarf.comp-dir-symlink-paths /proc/self/cwd
process attach -p $PID
p (void)monodroid_clear_gdb_wait()
$COMMANDS" > $START_FILE
echo -n "Starting lldb server in the background"
shell "run-as $PKG $START_SERVER $LLDB unix-abstract $LLDB/tmp $SOCK \"lldb process:gdb-remote packets\""&
for i in {1..5}; do
echo -n ' .'
sleep 1
done
echo " done."
declare -a PIDS=( `pgrep -P $!` "$!" )
#which lldb
#lldb -- $DATA_DIR/DebugClang/lldb -s $START_FILE
$LLDB_MONO_DIR/lldb -s $START_FILE
rm $START_FILE
kill "${PIDS[@]}"