forked from servalproject/batphone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
servald-gdb
executable file
·66 lines (58 loc) · 2.43 KB
/
servald-gdb
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
#!/bin/sh
device="${1:?}"
shift
PACKAGE_NAME=org.servalproject
# Check that there is no other instance of gdbserver running
GDBSERVER_PS=`adb -s $device shell ps | grep lib/gdbserver`
if [ -n "$GDBSERVER_PS" ] ; then
echo "A debug session is already running."
else
# Setup network redirection
echo "Setup network redirection"
echo $ADB_CMD forward tcp:5123 localfilesystem:ndk-gdb-socket
adb -s $device forward tcp:5123 tcp:5123
if [ $? != 0 ] ; then
echo "ERROR: Could not setup network redirection to gdbserver?"
exit 1
fi
adb -s $device pull /system/lib/libstdc++.so libstdc++.so
adb -s $device pull /system/lib/liblog.so liblog.so
adb -s $device pull /system/lib/libc.so libc.so
adb -s $device pull /system/lib/libm.so libm.so
adb -s $device pull /system/bin/linker linker
echo "Pulled libc.so from device/emulator."
echo "Copying non-stripped simple executable into place"
cp ./obj/local/armeabi/servaldsimple servald
adb -s $device pull /data/data/org.servalproject/bin/servald servald
adb -s $device push gdbserver /data/data/org.servalproject/lib/gdbserver
adb -s $device shell chmod 755 /data/data/org.servalproject/lib/gdbserver
# Launch gdbserver now
DEBUG_SOCKET=debug-socket
PID=`adb -s $device shell ps | grep bin/servald | awk '{ print $2;}'`
echo $PID
echo adb -s $device shell "/data/data/org.servalproject/lib/gdbserver :5123 --attach $PID"
adb -s $device shell "echo /data/data/org.servalproject/lib/gdbserver :5123 --attach $PID | su" &
if [ $? != 0 ] ; then
echo "ERROR: Could not launch gdbserver on the device?"
exit 1
fi
echo "Launched gdbserver succesfully."
fi
# Now launch the appropriate gdb client with the right init commands
#
sleep 1
if [ -n "$NDK_ROOT" ]; then
GDBCLIENT=$NDK_ROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/*-x86/bin/arm-linux-androideabi-gdb
else
GDBCLIENT=/Users/gardners/Dropbox/ServalSoftwareDevelopment/android/sdk/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-gdb
fi
GDBSETUP=gdb.setup
echo "" >$GDBSETUP
#uncomment the following to debug the remote connection only
#echo "set debug remote 1" >> $GDBSETUP
echo "set solib-search-path ." >> $GDBSETUP
echo "file servald" >> $GDBSETUP
echo "target remote 127.0.0.1:5123" >> $GDBSETUP
echo "" >>$GDBSETUP
$GDBCLIENT -x $GDBSETUP "$@"
#adb -s $device shell /data/data/org.servalproject/bin/servald stop