Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2428)

Unified Diff: build/android/adb_gdb

Issue 17103007: adb_gdb: Minor improvements (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Re-enable --su-prefix check. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/adb_gdb
diff --git a/build/android/adb_gdb b/build/android/adb_gdb
index 961e3f7d933fbe61fa39fe2132dffbd48ad820c5..53e30ac6a854c6c34ef703d9713f233feaaa97b4 100755
--- a/build/android/adb_gdb
+++ b/build/android/adb_gdb
@@ -36,15 +36,17 @@ clean_exit () {
log "Cleaning up: $TMPDIR"
rm -rf "$TMPDIR"
fi
+ trap "" EXIT
exit $1
}
-# Ensure clean exit on Ctrl-C.
-trap "clean_exit 1" INT
+# Ensure clean exit on Ctrl-C or normal exit.
+trap "clean_exit 1" INT HUP QUIT TERM
+trap "clean_exit \$?" EXIT
panic () {
echo "ERROR: $@" >&2
- clean_exit 1
+ exit 1
}
fail_panic () {
@@ -95,6 +97,7 @@ PULL_LIBS_DIR=
SANDBOXED=
SANDBOXED_INDEX=
START=
+SU_PREFIX=
SYMBOL_DIR=
TARGET_ARCH=
TOOLCHAIN=
@@ -155,6 +158,9 @@ for opt; do
--start)
START=true
;;
+ --su-prefix=*)
+ SU_PREFIX=$optarg
+ ;;
--symbol-dir=*)
SYMBOL_DIR=$optarg
;;
@@ -301,6 +307,10 @@ Valid options:
--target-arch=<name> Specify NDK target arch.
--adb=<program> Specify host ADB binary.
+ --su-prefix=<prefix> Prepend <prefix> to 'adb shell' commands that are
+ run by this script. This can be useful to use
+ the 'su' program on rooted production devices.
+
--pull-libs Force system libraries extraction.
--no-pull-libs Do not extract any system library.
--libs-dir=<path> Specify system libraries extraction directory.
@@ -813,22 +823,46 @@ fi
# If so, we can launch gdbserver directly, otherwise, we have to
# use run-as $PACKAGE_NAME ..., which requires the package to be debuggable.
#
-SHELL_UID=$(adb shell cat /proc/self/status | \
- awk '$1 == "Uid:" { print $2; }')
-log "Shell UID: $SHELL_UID"
-COMMAND_PREFIX=
-if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then
- log "Using run-as $PACKAGE_NAME to run without root."
- COMMAND_PREFIX="run-as $PACKAGE_NAME"
+if [ "$SU_PREFIX" ]; then
+ # Need to check that this works properly.
+ SU_PREFIX_TEST_LOG=$TMPDIR/su-prefix.log
+ adb_shell $SU_PREFIX echo "foo" > $SU_PREFIX_TEST_LOG 2>&1
+ if [ $? != 0 -o "$(cat $SU_PREFIX_TEST_LOG)" != "foo" ]; then
+ echo "ERROR: Cannot use '$SU_PREFIX' as a valid su prefix:"
+ echo "$ adb shell $SU_PREFIX echo foo"
+ cat $SU_PREFIX_TEST_LOG
+ exit 1
+ fi
+ COMMAND_PREFIX=$SU_PREFIX
+else
+ SHELL_UID=$(adb shell cat /proc/self/status | \
+ awk '$1 == "Uid:" { print $2; }')
+ log "Shell UID: $SHELL_UID"
+ if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then
+ COMMAND_PREFIX="run-as $PACKAGE_NAME"
+ else
+ COMMAND_PREFIX=
+ fi
fi
+log "Command prefix: '$COMMAND_PREFIX'"
# Pull device's system libraries that are mapped by our process.
# Pulling all system libraries is too long, so determine which ones
# we need by looking at /proc/$PID/maps instead
if [ "$PULL_LIBS" -a -z "$NO_PULL_LIBS" ]; then
echo "Extracting system libraries into: $PULL_LIBS_DIR"
- SYSTEM_LIBS=$(adb_shell $COMMAND_PREFIX cat /proc/$PID/maps | \
- awk '$6 ~ /\/system\/.*\.so$/ { print $6; }' | sort -u)
+ rm -f $PULL_LIBS_DIR/build.prop
+ MAPPINGS=$(adb_shell $COMMAND_PREFIX cat /proc/$PID/maps)
+ if [ $? != 0 ]; then
+ echo "ERROR: Could not list process's memory mappings."
+ if [ "$SU_PREFIX" ]; then
+ panic "Are you sure your --su-prefix is correct?"
+ else
+ panic "Use --su-prefix if the application is not debuggable."
+ fi
+ fi
+ SYSTEM_LIBS=$(echo "$MAPPINGS" | \
+ awk '$6 ~ /\/system\/.*\.so$/ { print $6; }' | sort -u)
for SYSLIB in /system/bin/linker $SYSTEM_LIBS; do
echo "Pulling from device: $SYSLIB"
DST_FILE=$PULL_LIBS_DIR$SYSLIB
@@ -927,5 +961,3 @@ fi
log "Launching gdb client: $GDB $GDBARGS -x $COMMANDS"
$GDB $GDBARGS -x $COMMANDS &&
rm -f "$GDBSERVER_PIDFILE"
-
-clean_exit $?
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698