This patch improves the Android-specific adb_gdb debugging scripts
in several minor ways:

- It ensures that the temporary directory is always removed when
  the script exits, even whe it is interrupted with Ctrl-C.

- It ensures that if --pull-libs is interrupted by a Ctrl-C,
  the build.prop in /tmp/$USER-adb-gdb-libs/ is erased, forcing
  a --pull-libs operation in the next invokation, instead of keeping
  a portion of the libraries in a bad state.

- It adds a --su-prefix=<prefix> option, to be able to use tools
  like 'su' on rooted production devices. This is useful when the
  installed app is not debuggable (e.g. a release build), and there
  is no way to run ADB as root.

BUG=NONE

Review URL: https://chromiumcodereview.appspot.com/17103007

git-svn-id: http://src.chromium.org/svn/trunk/src/build@206990 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
digit@chromium.org 2013-06-18 14:24:42 +00:00
Родитель 95c61febc4
Коммит eacb40c9e0
1 изменённых файлов: 46 добавлений и 14 удалений

Просмотреть файл

@ -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 $?