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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 # 2 #
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 # 6 #
7 7
8 # A generic script used to attach to a running Chromium process and 8 # A generic script used to attach to a running Chromium process and
9 # debug it. Most users should not use this directly, but one of the 9 # debug it. Most users should not use this directly, but one of the
10 # wrapper scripts like adb_gdb_content_shell, or adb_gdb_drt 10 # wrapper scripts like adb_gdb_content_shell, or adb_gdb_drt
(...skipping 18 matching lines...) Expand all
29 log "Killing background gdbserver process: $GDBSERVER_PID" 29 log "Killing background gdbserver process: $GDBSERVER_PID"
30 kill -9 $GDBSERVER_PID >/dev/null 2>&1 30 kill -9 $GDBSERVER_PID >/dev/null 2>&1
31 fi 31 fi
32 if [ "$TARGET_GDBSERVER" ]; then 32 if [ "$TARGET_GDBSERVER" ]; then
33 log "Removing target gdbserver binary: $TARGET_GDBSERVER." 33 log "Removing target gdbserver binary: $TARGET_GDBSERVER."
34 "$ADB" shell rm "$TARGET_GDBSERVER" >/dev/null 2>&1 34 "$ADB" shell rm "$TARGET_GDBSERVER" >/dev/null 2>&1
35 fi 35 fi
36 log "Cleaning up: $TMPDIR" 36 log "Cleaning up: $TMPDIR"
37 rm -rf "$TMPDIR" 37 rm -rf "$TMPDIR"
38 fi 38 fi
39 trap "" EXIT
39 exit $1 40 exit $1
40 } 41 }
41 42
42 # Ensure clean exit on Ctrl-C. 43 # Ensure clean exit on Ctrl-C or normal exit.
43 trap "clean_exit 1" INT 44 trap "clean_exit 1" INT HUP QUIT TERM
45 trap "clean_exit \$?" EXIT
44 46
45 panic () { 47 panic () {
46 echo "ERROR: $@" >&2 48 echo "ERROR: $@" >&2
47 clean_exit 1 49 exit 1
48 } 50 }
49 51
50 fail_panic () { 52 fail_panic () {
51 if [ $? != 0 ]; then panic "$@"; fi 53 if [ $? != 0 ]; then panic "$@"; fi
52 } 54 }
53 55
54 log () { 56 log () {
55 if [ "$VERBOSE" -gt 0 ]; then 57 if [ "$VERBOSE" -gt 0 ]; then
56 echo "$@" 58 echo "$@"
57 fi 59 fi
(...skipping 30 matching lines...) Expand all
88 NDK_DIR= 90 NDK_DIR=
89 NO_PULL_LIBS= 91 NO_PULL_LIBS=
90 PACKAGE_NAME= 92 PACKAGE_NAME=
91 PID= 93 PID=
92 PROGRAM_NAME="activity" 94 PROGRAM_NAME="activity"
93 PULL_LIBS= 95 PULL_LIBS=
94 PULL_LIBS_DIR= 96 PULL_LIBS_DIR=
95 SANDBOXED= 97 SANDBOXED=
96 SANDBOXED_INDEX= 98 SANDBOXED_INDEX=
97 START= 99 START=
100 SU_PREFIX=
98 SYMBOL_DIR= 101 SYMBOL_DIR=
99 TARGET_ARCH= 102 TARGET_ARCH=
100 TOOLCHAIN= 103 TOOLCHAIN=
101 VERBOSE=0 104 VERBOSE=0
102 105
103 for opt; do 106 for opt; do
104 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)') 107 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
105 case $opt in 108 case $opt in
106 --adb=*) 109 --adb=*)
107 ADB=$optarg 110 ADB=$optarg
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 --sandboxed=*) 151 --sandboxed=*)
149 SANDBOXED=true 152 SANDBOXED=true
150 SANDBOXED_INDEX=$optarg 153 SANDBOXED_INDEX=$optarg
151 ;; 154 ;;
152 --script=*) 155 --script=*)
153 GDBINIT=$optarg 156 GDBINIT=$optarg
154 ;; 157 ;;
155 --start) 158 --start)
156 START=true 159 START=true
157 ;; 160 ;;
161 --su-prefix=*)
162 SU_PREFIX=$optarg
163 ;;
158 --symbol-dir=*) 164 --symbol-dir=*)
159 SYMBOL_DIR=$optarg 165 SYMBOL_DIR=$optarg
160 ;; 166 ;;
161 --target-arch=*) 167 --target-arch=*)
162 TARGET_ARCH=$optarg 168 TARGET_ARCH=$optarg
163 ;; 169 ;;
164 --toolchain=*) 170 --toolchain=*)
165 TOOLCHAIN=$optarg 171 TOOLCHAIN=$optarg
166 ;; 172 ;;
167 --ui) 173 --ui)
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 --ui Use gdbtui instead of gdb 300 --ui Use gdbtui instead of gdb
295 --activity=<name> Activity name for --start [$DEFAULT_ACTIVITY]. 301 --activity=<name> Activity name for --start [$DEFAULT_ACTIVITY].
296 --annotate=<num> Enable gdb annotation. 302 --annotate=<num> Enable gdb annotation.
297 --script=<file> Specify extra GDB init script. 303 --script=<file> Specify extra GDB init script.
298 304
299 --gdbserver=<file> Specify targer gdbserver binary. 305 --gdbserver=<file> Specify targer gdbserver binary.
300 --gdb=<program> Specify host gdb client binary. 306 --gdb=<program> Specify host gdb client binary.
301 --target-arch=<name> Specify NDK target arch. 307 --target-arch=<name> Specify NDK target arch.
302 --adb=<program> Specify host ADB binary. 308 --adb=<program> Specify host ADB binary.
303 309
310 --su-prefix=<prefix> Prepend <prefix> to 'adb shell' commands that are
311 run by this script. This can be useful to use
312 the 'su' program on rooted production devices.
313
304 --pull-libs Force system libraries extraction. 314 --pull-libs Force system libraries extraction.
305 --no-pull-libs Do not extract any system library. 315 --no-pull-libs Do not extract any system library.
306 --libs-dir=<path> Specify system libraries extraction directory. 316 --libs-dir=<path> Specify system libraries extraction directory.
307 317
308 --debug Use libraries under out/Debug. 318 --debug Use libraries under out/Debug.
309 --release Use libraries under out/Release. 319 --release Use libraries under out/Release.
310 320
311 EOF 321 EOF
312 exit 0 322 exit 0
313 fi 323 fi
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 fi 816 fi
807 log "Found process PID: $PID" 817 log "Found process PID: $PID"
808 elif [ "$SANDBOXED" ]; then 818 elif [ "$SANDBOXED" ]; then
809 echo "WARNING: --sandboxed option ignored due to use of --pid." 819 echo "WARNING: --sandboxed option ignored due to use of --pid."
810 fi 820 fi
811 821
812 # Determine if 'adb shell' runs as root or not. 822 # Determine if 'adb shell' runs as root or not.
813 # If so, we can launch gdbserver directly, otherwise, we have to 823 # If so, we can launch gdbserver directly, otherwise, we have to
814 # use run-as $PACKAGE_NAME ..., which requires the package to be debuggable. 824 # use run-as $PACKAGE_NAME ..., which requires the package to be debuggable.
815 # 825 #
816 SHELL_UID=$(adb shell cat /proc/self/status | \ 826 if [ "$SU_PREFIX" ]; then
817 awk '$1 == "Uid:" { print $2; }') 827 # Need to check that this works properly.
818 log "Shell UID: $SHELL_UID" 828 SU_PREFIX_TEST_LOG=$TMPDIR/su-prefix.log
819 COMMAND_PREFIX= 829 adb_shell $SU_PREFIX echo "foo" > $SU_PREFIX_TEST_LOG 2>&1
820 if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then 830 if [ $? != 0 -o "$(cat $SU_PREFIX_TEST_LOG)" != "foo" ]; then
821 log "Using run-as $PACKAGE_NAME to run without root." 831 echo "ERROR: Cannot use '$SU_PREFIX' as a valid su prefix:"
822 COMMAND_PREFIX="run-as $PACKAGE_NAME" 832 echo "$ adb shell $SU_PREFIX echo foo"
833 cat $SU_PREFIX_TEST_LOG
834 exit 1
835 fi
836 COMMAND_PREFIX=$SU_PREFIX
837 else
838 SHELL_UID=$(adb shell cat /proc/self/status | \
839 awk '$1 == "Uid:" { print $2; }')
840 log "Shell UID: $SHELL_UID"
841 if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then
842 COMMAND_PREFIX="run-as $PACKAGE_NAME"
843 else
844 COMMAND_PREFIX=
845 fi
823 fi 846 fi
847 log "Command prefix: '$COMMAND_PREFIX'"
824 848
825 # Pull device's system libraries that are mapped by our process. 849 # Pull device's system libraries that are mapped by our process.
826 # Pulling all system libraries is too long, so determine which ones 850 # Pulling all system libraries is too long, so determine which ones
827 # we need by looking at /proc/$PID/maps instead 851 # we need by looking at /proc/$PID/maps instead
828 if [ "$PULL_LIBS" -a -z "$NO_PULL_LIBS" ]; then 852 if [ "$PULL_LIBS" -a -z "$NO_PULL_LIBS" ]; then
829 echo "Extracting system libraries into: $PULL_LIBS_DIR" 853 echo "Extracting system libraries into: $PULL_LIBS_DIR"
830 SYSTEM_LIBS=$(adb_shell $COMMAND_PREFIX cat /proc/$PID/maps | \ 854 rm -f $PULL_LIBS_DIR/build.prop
831 awk '$6 ~ /\/system\/.*\.so$/ { print $6; }' | sort -u) 855 MAPPINGS=$(adb_shell $COMMAND_PREFIX cat /proc/$PID/maps)
856 if [ $? != 0 ]; then
857 echo "ERROR: Could not list process's memory mappings."
858 if [ "$SU_PREFIX" ]; then
859 panic "Are you sure your --su-prefix is correct?"
860 else
861 panic "Use --su-prefix if the application is not debuggable."
862 fi
863 fi
864 SYSTEM_LIBS=$(echo "$MAPPINGS" | \
865 awk '$6 ~ /\/system\/.*\.so$/ { print $6; }' | sort -u)
832 for SYSLIB in /system/bin/linker $SYSTEM_LIBS; do 866 for SYSLIB in /system/bin/linker $SYSTEM_LIBS; do
833 echo "Pulling from device: $SYSLIB" 867 echo "Pulling from device: $SYSLIB"
834 DST_FILE=$PULL_LIBS_DIR$SYSLIB 868 DST_FILE=$PULL_LIBS_DIR$SYSLIB
835 DST_DIR=$(dirname "$DST_FILE") 869 DST_DIR=$(dirname "$DST_FILE")
836 mkdir -p "$DST_DIR" && adb pull $SYSLIB "$DST_FILE" 2>/dev/null 870 mkdir -p "$DST_DIR" && adb pull $SYSLIB "$DST_FILE" 2>/dev/null
837 fail_panic "Could not pull $SYSLIB from device !?" 871 fail_panic "Could not pull $SYSLIB from device !?"
838 done 872 done
839 echo "Pulling device build.prop" 873 echo "Pulling device build.prop"
840 adb pull /system/build.prop $PULL_LIBS_DIR/build.prop 874 adb pull /system/build.prop $PULL_LIBS_DIR/build.prop
841 fail_panic "Could not pull device build.prop !?" 875 fail_panic "Could not pull device build.prop !?"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 954
921 if [ "$VERBOSE" -gt 0 ]; then 955 if [ "$VERBOSE" -gt 0 ]; then
922 echo "### START $COMMANDS" 956 echo "### START $COMMANDS"
923 cat $COMMANDS 957 cat $COMMANDS
924 echo "### END $COMMANDS" 958 echo "### END $COMMANDS"
925 fi 959 fi
926 960
927 log "Launching gdb client: $GDB $GDBARGS -x $COMMANDS" 961 log "Launching gdb client: $GDB $GDBARGS -x $COMMANDS"
928 $GDB $GDBARGS -x $COMMANDS && 962 $GDB $GDBARGS -x $COMMANDS &&
929 rm -f "$GDBSERVER_PIDFILE" 963 rm -f "$GDBSERVER_PIDFILE"
930
931 clean_exit $?
OLDNEW
« 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