aboutsummaryrefslogtreecommitdiffstats
path: root/java/debug.sh
diff options
context:
space:
mode:
authorPo Lu2023-02-15 13:39:47 +0800
committerPo Lu2023-02-15 13:39:47 +0800
commitdd7066901f67233c09f3b0409a57db7686c7ea5b (patch)
tree15062b9df3f7fa06403ecd093b36026a5f21b2da /java/debug.sh
parentb875a2eaf31d3e9db0ae70bc6a1ed4c9bcd573ff (diff)
downloademacs-dd7066901f67233c09f3b0409a57db7686c7ea5b.tar.gz
emacs-dd7066901f67233c09f3b0409a57db7686c7ea5b.zip
Make debug.sh detect adb running as root
* java/debug.sh: Run gdbserver directly if possible.
Diffstat (limited to 'java/debug.sh')
-rwxr-xr-xjava/debug.sh39
1 files changed, 32 insertions, 7 deletions
diff --git a/java/debug.sh b/java/debug.sh
index 2e95f9738c7..cbef7518984 100755
--- a/java/debug.sh
+++ b/java/debug.sh
@@ -263,6 +263,8 @@ if [ -n "$jdb_command" ]; then
263fi 263fi
264 264
265# See if gdbserver has to be uploaded 265# See if gdbserver has to be uploaded
266gdbserver_cmd=
267is_root=
266if [ -z "$gdbserver" ]; then 268if [ -z "$gdbserver" ]; then
267 gdbserver_bin=/system/bin/gdbserver 269 gdbserver_bin=/system/bin/gdbserver
268else 270else
@@ -272,9 +274,26 @@ else
272 274
273 # Upload the specified gdbserver binary to the device. 275 # Upload the specified gdbserver binary to the device.
274 adb -s $device push "$gdbserver" "$gdbserver_bin" 276 adb -s $device push "$gdbserver" "$gdbserver_bin"
275 # Copy it to the user directory. 277
276 adb -s $device shell "$gdbserver_cat" 278 if (adb -s $device pull /system/bin/tee /dev/null &> /dev/null); then
277 adb -s $device shell "run-as $package chmod +x gdbserver" 279 # Copy it to the user directory.
280 adb -s $device shell "$gdbserver_cat"
281 adb -s $device shell "run-as $package chmod +x gdbserver"
282 gdbserver_cmd="./gdbserver"
283 else
284 # Hopefully this is an old version of Android which allows
285 # execution from /data/local/tmp. Its `chmod' doesn't support
286 # `+x' either.
287 adb -s $device shell "chmod 777 $gdbserver_bin"
288 gdbserver_cmd="$gdbserver_bin"
289
290 # If the user is root, then there is no need to open any kind
291 # of TCP socket.
292 if (adb -s $device shell id | grep -G root); then
293 gdbserver=
294 is_root=yes
295 fi
296 fi
278fi 297fi
279 298
280# Now start gdbserver on the device asynchronously. 299# Now start gdbserver on the device asynchronously.
@@ -284,13 +303,19 @@ exec 5<> /tmp/file-descriptor-stamp
284rm -f /tmp/file-descriptor-stamp 303rm -f /tmp/file-descriptor-stamp
285 304
286if [ -z "$gdbserver" ]; then 305if [ -z "$gdbserver" ]; then
287 adb -s $device shell run-as $package $gdbserver_bin --once \ 306 if [ "$is_root" = "yes" ]; then
288 "+debug.$package.socket" --attach $pid >&5 & 307 adb -s $device shell $gdbserver_bin --once \
289 gdb_socket="localfilesystem:$app_data_dir/debug.$package.socket" 308 "+/data/local/tmp/debug.$package.socket" --attach $pid >&5 &
309 gdb_socket="localfilesystem:/data/local/tmp/debug.$package.socket"
310 else
311 adb -s $device shell run-as $package $gdbserver_bin --once \
312 "+debug.$package.socket" --attach $pid >&5 &
313 gdb_socket="localfilesystem:$app_data_dir/debug.$package.socket"
314 fi
290else 315else
291 # Normally the program cannot access $gdbserver_bin when it is 316 # Normally the program cannot access $gdbserver_bin when it is
292 # placed in /data/local/tmp. 317 # placed in /data/local/tmp.
293 adb -s $device shell run-as $package "./gdbserver" --once \ 318 adb -s $device shell run-as $package $gdbserver_cmd --once \
294 "0.0.0.0:7654" --attach $pid >&5 & 319 "0.0.0.0:7654" --attach $pid >&5 &
295 gdb_socket="tcp:7654" 320 gdb_socket="tcp:7654"
296fi 321fi