aboutsummaryrefslogtreecommitdiffstats
path: root/java/debug.sh
diff options
context:
space:
mode:
Diffstat (limited to 'java/debug.sh')
-rwxr-xr-xjava/debug.sh45
1 files changed, 26 insertions, 19 deletions
diff --git a/java/debug.sh b/java/debug.sh
index dd710dc31af..3e3e3d9c281 100755
--- a/java/debug.sh
+++ b/java/debug.sh
@@ -30,6 +30,7 @@ activity=org.gnu.emacs.EmacsActivity
30gdb_port=5039 30gdb_port=5039
31jdb_port=64013 31jdb_port=64013
32jdb=no 32jdb=no
33attach_existing=no
33 34
34while [ $# -gt 0 ]; do 35while [ $# -gt 0 ]; do
35 case "$1" in 36 case "$1" in
@@ -48,6 +49,7 @@ while [ $# -gt 0 ]; do
48 echo " --port PORT run the GDB server on a specific port" 49 echo " --port PORT run the GDB server on a specific port"
49 echo " --jdb-port PORT run the JDB server on a specific port" 50 echo " --jdb-port PORT run the JDB server on a specific port"
50 echo " --jdb run JDB instead of GDB" 51 echo " --jdb run JDB instead of GDB"
52 echo " --attach-existing attach to an existing process"
51 echo " --help print this message" 53 echo " --help print this message"
52 echo "" 54 echo ""
53 echo "Available devices:" 55 echo "Available devices:"
@@ -63,6 +65,9 @@ while [ $# -gt 0 ]; do
63 "--port" ) 65 "--port" )
64 gdb_port=$1 66 gdb_port=$1
65 ;; 67 ;;
68 "--attach-existing" )
69 attach_existing=yes
70 ;;
66 "--" ) 71 "--" )
67 shift 72 shift
68 gdbargs=$@ 73 gdbargs=$@
@@ -120,30 +125,32 @@ package_pids=`awk -- '{
120 print $1 125 print $1
121}' <<< $package_pids` 126}' <<< $package_pids`
122 127
123# Finally, kill each existing process. 128if [ "$attach_existing" != "yes" ]; then
124for pid in $package_pids; do 129 # Finally, kill each existing process.
125 echo "Killing existing process $pid..." 130 for pid in $package_pids; do
126 adb -s $device shell run-as $package kill -9 $pid &> /dev/null 131 echo "Killing existing process $pid..."
127done 132 adb -s $device shell run-as $package kill -9 $pid &> /dev/null
128 133 done
129# Now run the main activity. This must be done as the adb user and 134
130# not as the package user. 135 # Now run the main activity. This must be done as the adb user and
131echo "Starting activity $activity and attaching debugger" 136 # not as the package user.
132 137 echo "Starting activity $activity and attaching debugger"
133# Exit if the activity could not be started. 138
134adb -s $device shell am start -D "$package/$activity" 139 # Exit if the activity could not be started.
135if [ ! $? ]; then 140 adb -s $device shell am start -D "$package/$activity"
136 exit 1; 141 if [ ! $? ]; then
137fi 142 exit 1;
143 fi
138 144
139# Now look for processes matching the package again. 145 # Now look for processes matching the package again.
140package_pids=`adb -s $device shell run-as $package ps -u $package_uid -o PID,CMD` 146 package_pids=`adb -s $device shell run-as $package ps -u $package_uid -o PID,CMD`
141 147
142# Next, remove lines matching "ps" itself. 148 # Next, remove lines matching "ps" itself.
143package_pids=`awk -- '{ 149 package_pids=`awk -- '{
144 if (!match ($0, /(PID|ps)/)) 150 if (!match ($0, /(PID|ps)/))
145 print $1 151 print $1
146}' <<< $package_pids` 152}' <<< $package_pids`
153fi
147 154
148pid=$package_pids 155pid=$package_pids
149num_pids=`wc -w <<< "$package_pids"` 156num_pids=`wc -w <<< "$package_pids"`