| OLD | NEW |
| 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 | 10 # wrapper scripts like adb_gdb_content_shell |
| 11 # | 11 # |
| 12 # Use --help to print full usage instructions. | 12 # Use --help to print full usage instructions. |
| 13 # | 13 # |
| 14 | 14 |
| 15 PROGNAME=$(basename "$0") | 15 PROGNAME=$(basename "$0") |
| 16 PROGDIR=$(dirname "$0") | 16 PROGDIR=$(dirname "$0") |
| 17 | 17 |
| 18 # Force locale to C to allow recognizing output from subprocesses. | 18 # Force locale to C to allow recognizing output from subprocesses. |
| 19 LC_ALL=C | 19 LC_ALL=C |
| 20 | 20 |
| 21 # Location of Chromium-top-level sources. | 21 # Location of Chromium-top-level sources. |
| 22 CHROMIUM_SRC=$(cd "$PROGDIR"/../.. >/dev/null && pwd 2>/dev/null) | 22 CHROMIUM_SRC=$(cd "$PROGDIR"/../.. >/dev/null && pwd 2>/dev/null) |
| 23 | 23 |
| 24 # Location of Chromium out/ directory. | |
| 25 if [ -z "$CHROMIUM_OUT_DIR" ]; then | |
| 26 CHROMIUM_OUT_DIR=out | |
| 27 fi | |
| 28 | |
| 29 TMPDIR= | 24 TMPDIR= |
| 30 GDBSERVER_PIDFILE= | 25 GDBSERVER_PIDFILE= |
| 31 TARGET_GDBSERVER= | 26 TARGET_GDBSERVER= |
| 32 COMMAND_PREFIX= | 27 COMMAND_PREFIX= |
| 33 | 28 |
| 34 clean_exit () { | 29 clean_exit () { |
| 35 if [ "$TMPDIR" ]; then | 30 if [ "$TMPDIR" ]; then |
| 36 GDBSERVER_PID=$(cat $GDBSERVER_PIDFILE 2>/dev/null) | 31 GDBSERVER_PID=$(cat $GDBSERVER_PIDFILE 2>/dev/null) |
| 37 if [ "$GDBSERVER_PID" ]; then | 32 if [ "$GDBSERVER_PID" ]; then |
| 38 log "Killing background gdbserver process: $GDBSERVER_PID" | 33 log "Killing background gdbserver process: $GDBSERVER_PID" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 ;; | 177 ;; |
| 183 --start) | 178 --start) |
| 184 START=true | 179 START=true |
| 185 ;; | 180 ;; |
| 186 --su-prefix=*) | 181 --su-prefix=*) |
| 187 SU_PREFIX=$optarg | 182 SU_PREFIX=$optarg |
| 188 ;; | 183 ;; |
| 189 --symbol-dir=*) | 184 --symbol-dir=*) |
| 190 SYMBOL_DIR=$optarg | 185 SYMBOL_DIR=$optarg |
| 191 ;; | 186 ;; |
| 187 --output-dir=*) |
| 188 CHROMIUM_OUTPUT_DIR=$optarg |
| 189 ;; |
| 192 --out-dir=*) | 190 --out-dir=*) |
| 193 CHROMIUM_OUT_DIR=$optarg | 191 CHROMIUM_OUT_DIR=$optarg |
| 194 ;; | 192 ;; |
| 195 --target-arch=*) | 193 --target-arch=*) |
| 196 TARGET_ARCH=$optarg | 194 TARGET_ARCH=$optarg |
| 197 ;; | 195 ;; |
| 198 --toolchain=*) | 196 --toolchain=*) |
| 199 TOOLCHAIN=$optarg | 197 TOOLCHAIN=$optarg |
| 200 ;; | 198 ;; |
| 201 --ui) | 199 --ui) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 216 *) | 214 *) |
| 217 if [ "$PACKAGE_NAME" ]; then | 215 if [ "$PACKAGE_NAME" ]; then |
| 218 panic "You can only provide a single package name as argument!\ | 216 panic "You can only provide a single package name as argument!\ |
| 219 See --help." | 217 See --help." |
| 220 fi | 218 fi |
| 221 PACKAGE_NAME=$opt | 219 PACKAGE_NAME=$opt |
| 222 ;; | 220 ;; |
| 223 esac | 221 esac |
| 224 done | 222 done |
| 225 | 223 |
| 226 print_help_options () { | |
| 227 cat <<EOF | |
| 228 EOF | |
| 229 } | |
| 230 | |
| 231 if [ "$HELP" ]; then | 224 if [ "$HELP" ]; then |
| 232 if [ "$ADB_GDB_PROGNAME" ]; then | 225 if [ "$ADB_GDB_PROGNAME" ]; then |
| 233 # Assume wrapper scripts all provide a default package name. | 226 # Assume wrapper scripts all provide a default package name. |
| 234 cat <<EOF | 227 cat <<EOF |
| 235 Usage: $PROGNAME [options] | 228 Usage: $PROGNAME [options] |
| 236 | 229 |
| 237 Attach gdb to a running Android $PROGRAM_NAME process. | 230 Attach gdb to a running Android $PROGRAM_NAME process. |
| 238 EOF | 231 EOF |
| 239 else | 232 else |
| 240 # Assume this is a direct call to adb_gdb | 233 # Assume this is a direct call to adb_gdb |
| (...skipping 21 matching lines...) Expand all Loading... |
| 262 - target gdbserver binary | 255 - target gdbserver binary |
| 263 - host gdb client (e.g. arm-linux-androideabi-gdb) | 256 - host gdb client (e.g. arm-linux-androideabi-gdb) |
| 264 - directory with symbolic version of $PROGRAM_NAME's shared libraries. | 257 - directory with symbolic version of $PROGRAM_NAME's shared libraries. |
| 265 | 258 |
| 266 You can also use --ndk-dir=<path> to specify an alternative NDK installation | 259 You can also use --ndk-dir=<path> to specify an alternative NDK installation |
| 267 directory. | 260 directory. |
| 268 | 261 |
| 269 The script tries to find the most recent version of the debug version of | 262 The script tries to find the most recent version of the debug version of |
| 270 shared libraries under one of the following directories: | 263 shared libraries under one of the following directories: |
| 271 | 264 |
| 272 \$CHROMIUM_SRC/<out>/Release/lib/ (used by GYP builds) | 265 \$CHROMIUM_SRC/<out>/lib/ (used by GYP builds) |
| 273 \$CHROMIUM_SRC/<out>/Debug/lib/ (used by GYP builds) | 266 \$CHROMIUM_SRC/<out>/lib.unstripped/ (used by GN builds) |
| 274 \$CHROMIUM_SRC/<out>/Release/lib.unstripped/ (used by GN builds) | |
| 275 \$CHROMIUM_SRC/<out>/Debug/lib.unstripped/ (used by GN builds) | |
| 276 | 267 |
| 277 Where <out> is 'out' by default, unless the --out=<name> option is used or | 268 Where <out> is 'out' is determined by CHROMIUM_OUT_DIR, CHROMIUM_OUTPUT_DIR, or |
| 278 the CHROMIUM_OUT_DIR environment variable is defined. | 269 the --out-dir, --output-dir flags. |
| 279 | 270 |
| 280 You can restrict this search by using --release or --debug to specify the | 271 You can restrict this search by using --release or --debug to specify the |
| 281 build type, or simply use --symbol-dir=<path> to specify the file manually. | 272 build type, or simply use --symbol-dir=<path> to specify the file manually. |
| 282 | 273 |
| 283 The script tries to extract the target architecture from your target device, | 274 The script tries to extract the target architecture from your target device, |
| 284 but if this fails, will default to 'arm'. Use --target-arch=<name> to force | 275 but if this fails, will default to 'arm'. Use --target-arch=<name> to force |
| 285 its value. | 276 its value. |
| 286 | 277 |
| 287 Otherwise, the script will complain, but you can use the --gdbserver, | 278 Otherwise, the script will complain, but you can use the --gdbserver, |
| 288 --gdb and --symbol-lib options to specify everything manually. | 279 --gdb and --symbol-lib options to specify everything manually. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 312 will be passed to gdb after the remote connection and library symbol | 303 will be passed to gdb after the remote connection and library symbol |
| 313 loading have completed. | 304 loading have completed. |
| 314 | 305 |
| 315 Valid options: | 306 Valid options: |
| 316 --help|-h|-? Print this message. | 307 --help|-h|-? Print this message. |
| 317 --verbose Increase verbosity. | 308 --verbose Increase verbosity. |
| 318 | 309 |
| 319 --sandboxed Debug first sandboxed process we find. | 310 --sandboxed Debug first sandboxed process we find. |
| 320 --sandboxed=<num> Debug specific sandboxed process. | 311 --sandboxed=<num> Debug specific sandboxed process. |
| 321 --symbol-dir=<path> Specify directory with symbol shared libraries. | 312 --symbol-dir=<path> Specify directory with symbol shared libraries. |
| 322 --out-dir=<path> Specify the out directory. | 313 --out-dir=<path> Specify the out directory (e.g. "out"). |
| 314 --output-dir=<path> Specify the output directory (e.g. "out/Debug"). |
| 323 --package-name=<name> Specify package name (alternative to 1st argument). | 315 --package-name=<name> Specify package name (alternative to 1st argument). |
| 324 --privileged Debug first privileged process we find. | 316 --privileged Debug first privileged process we find. |
| 325 --privileged=<num> Debug specific privileged process. | 317 --privileged=<num> Debug specific privileged process. |
| 326 --program-name=<name> Specify program name (cosmetic only). | 318 --program-name=<name> Specify program name (cosmetic only). |
| 327 --pid=<pid> Specify application process pid. | 319 --pid=<pid> Specify application process pid. |
| 328 --force Kill any previous debugging session, if any. | 320 --force Kill any previous debugging session, if any. |
| 329 --start Start package's activity on device. | 321 --start Start package's activity on device. |
| 330 --ui Use gdbtui instead of gdb | 322 --ui Use gdbtui instead of gdb |
| 331 --activity=<name> Activity name for --start [$DEFAULT_ACTIVITY]. | 323 --activity=<name> Activity name for --start [$DEFAULT_ACTIVITY]. |
| 332 --annotate=<num> Enable gdb annotation. | 324 --annotate=<num> Enable gdb annotation. |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 | 688 |
| 697 # Return the timestamp of a given file, as number of seconds since epoch. | 689 # Return the timestamp of a given file, as number of seconds since epoch. |
| 698 # $1: file path | 690 # $1: file path |
| 699 # Out: file timestamp | 691 # Out: file timestamp |
| 700 get_file_timestamp () { | 692 get_file_timestamp () { |
| 701 stat -c %Y "$1" 2>/dev/null | 693 stat -c %Y "$1" 2>/dev/null |
| 702 } | 694 } |
| 703 | 695 |
| 704 # Detect the build type and symbol directory. This is done by finding | 696 # Detect the build type and symbol directory. This is done by finding |
| 705 # the most recent sub-directory containing debug shared libraries under | 697 # the most recent sub-directory containing debug shared libraries under |
| 706 # $CHROMIUM_SRC/$CHROMIUM_OUT_DIR/ | 698 # (in order of priority): |
| 699 # 1. $CHROMIUM_OUTPUT_DIR |
| 700 # 2. $CHROMIUM_SRC/$CHROMIUM_OUT_DIR/$BUILDTYPE (if $BUILDTYPE is set) |
| 701 # 3. $CHROMIUM_SRC/$CHROMIUM_OUT_DIR/{Debug,Release} |
| 707 # | 702 # |
| 708 # $1: $BUILDTYPE value, can be empty | |
| 709 # Out: nothing, but this sets SYMBOL_DIR | 703 # Out: nothing, but this sets SYMBOL_DIR |
| 710 # | 704 # |
| 711 detect_symbol_dir () { | 705 detect_symbol_dir () { |
| 712 local SUBDIRS SUBDIR LIST DIR DIR_LIBS TSTAMP | 706 local PARENT_DIR SUBDIRS SUBDIR LIST DIR DIR_LIBS TSTAMP |
| 713 # GYP places unstripped libraries under out/$BUILDTYPE/lib | 707 # GYP places unstripped libraries under out/$BUILDTYPE/lib |
| 714 # GN places them under out/$BUILDTYPE/lib.unstripped | 708 # GN places them under out/$BUILDTYPE/lib.unstripped |
| 715 if [ "$1" ]; then | 709 if [[ -n "$CHROMIUM_OUTPUT_DIR" ]]; then |
| 716 SUBDIRS="$1/lib $1/lib.unstripped" | 710 PARENT_DIR="$CHROMIUM_OUTPUT_DIR" |
| 711 SUBDIRS="lib.unstripped lib" |
| 717 else | 712 else |
| 718 SUBDIRS="Release/lib Debug/lib" | 713 PARENT_DIR="$CHROMIUM_OUT_DIR" |
| 719 SUBDIRS+=" Release/lib.unstripped Debug/lib.unstripped" | 714 if [[ -n "$BUILDTYPE" ]]; then |
| 715 PARENT_DIR="$PARENT_DIR/$BUILDTYPE" |
| 716 SUBDIRS="lib.unstripped lib" |
| 717 else |
| 718 SUBDIRS="Release/lib.unstripped Debug/lib.unstripped " |
| 719 SUBDIRS+="Release/lib Debug/lib" |
| 720 fi |
| 721 fi |
| 722 if [[ ! -e "$PARENT_DIR" ]]; then |
| 723 PARENT_DIR="$CHROMIUM_SRC/$PARENT_DIR" |
| 720 fi | 724 fi |
| 721 LIST=$TMPDIR/scan-subdirs-$$.txt | 725 LIST=$TMPDIR/scan-subdirs-$$.txt |
| 722 printf "" > "$LIST" | 726 printf "" > "$LIST" |
| 723 for SUBDIR in $SUBDIRS; do | 727 for SUBDIR in $SUBDIRS; do |
| 724 DIR=$CHROMIUM_SRC/$CHROMIUM_OUT_DIR/$SUBDIR | 728 DIR="$PARENT_DIR/$SUBDIR" |
| 725 if [ -d "$DIR" ]; then | 729 if [ -d "$DIR" ]; then |
| 726 # Ignore build directories that don't contain symbol versions | 730 # Ignore build directories that don't contain symbol versions |
| 727 # of the shared libraries. | 731 # of the shared libraries. |
| 728 DIR_LIBS=$(ls "$DIR"/lib*.so 2>/dev/null) | 732 DIR_LIBS=$(ls "$DIR"/lib*.so 2>/dev/null) |
| 729 if [ -z "$DIR_LIBS" ]; then | 733 if [ -z "$DIR_LIBS" ]; then |
| 730 echo "No shared libs: $DIR" | 734 echo "No shared libs: $DIR" |
| 731 continue | 735 continue |
| 732 fi | 736 fi |
| 733 TSTAMP=$(get_file_timestamp "$DIR") | 737 TSTAMP=$(get_file_timestamp "$DIR") |
| 734 printf "%s %s\n" "$TSTAMP" "$SUBDIR" >> "$LIST" | 738 printf "%s %s\n" "$TSTAMP" "$SUBDIR" >> "$LIST" |
| 735 fi | 739 fi |
| 736 done | 740 done |
| 737 SUBDIR=$(cat $LIST | sort -r | head -1 | cut -d" " -f2) | 741 SUBDIR=$(cat $LIST | sort -r | head -1 | cut -d" " -f2) |
| 738 rm -f "$LIST" | 742 rm -f "$LIST" |
| 739 | 743 |
| 740 if [ -z "$SUBDIR" ]; then | 744 if [[ -z "$SUBDIR" ]]; then |
| 741 if [ -z "$1" ]; then | 745 panic "Could not find any build directory under \ |
| 742 panic "Could not find any build directory under \ | 746 $PARENT_DIR/{${SUBDIRS// /,}}. Please build the program first!" |
| 743 $CHROMIUM_SRC/$CHROMIUM_OUT_DIR. Please build the program first!" | |
| 744 else | |
| 745 panic "Could not find any $1 directory under \ | |
| 746 $CHROMIUM_SRC/$CHROMIUM_OUT_DIR. Check your build type!" | |
| 747 fi | |
| 748 fi | 747 fi |
| 749 | 748 |
| 750 SYMBOL_DIR=$CHROMIUM_SRC/$CHROMIUM_OUT_DIR/$SUBDIR | 749 SYMBOL_DIR=$PARENT_DIR/$SUBDIR |
| 751 log "Auto-config: --symbol-dir=$SYMBOL_DIR" | 750 log "Auto-config: --symbol-dir=$SYMBOL_DIR" |
| 752 } | 751 } |
| 753 | 752 |
| 754 if [ -z "$SYMBOL_DIR" ]; then | 753 if [ -z "$SYMBOL_DIR" ]; then |
| 755 detect_symbol_dir "$BUILDTYPE" | 754 detect_symbol_dir |
| 756 fi | 755 fi |
| 757 | 756 |
| 758 # Allow several concurrent debugging sessions | 757 # Allow several concurrent debugging sessions |
| 759 TARGET_GDBSERVER=/data/data/$PACKAGE_NAME/gdbserver-adb-gdb-$TMP_ID | 758 TARGET_GDBSERVER=/data/data/$PACKAGE_NAME/gdbserver-adb-gdb-$TMP_ID |
| 760 TMP_TARGET_GDBSERVER=/data/local/tmp/gdbserver-adb-gdb-$TMP_ID | 759 TMP_TARGET_GDBSERVER=/data/local/tmp/gdbserver-adb-gdb-$TMP_ID |
| 761 | 760 |
| 762 # Return the build fingerprint contained in a build.prop file. | 761 # Return the build fingerprint contained in a build.prop file. |
| 763 # $1: path to build.prop file | 762 # $1: path to build.prop file |
| 764 get_build_fingerprint_from () { | 763 get_build_fingerprint_from () { |
| 765 cat "$1" | grep -e '^ro.build.fingerprint=' | cut -d= -f2 | 764 cat "$1" | grep -e '^ro.build.fingerprint=' | cut -d= -f2 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 | 1048 |
| 1050 if [ "$VERBOSE" -gt 0 ]; then | 1049 if [ "$VERBOSE" -gt 0 ]; then |
| 1051 echo "### START $COMMANDS" | 1050 echo "### START $COMMANDS" |
| 1052 cat $COMMANDS | 1051 cat $COMMANDS |
| 1053 echo "### END $COMMANDS" | 1052 echo "### END $COMMANDS" |
| 1054 fi | 1053 fi |
| 1055 | 1054 |
| 1056 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS" | 1055 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS" |
| 1057 $GDB $GDB_ARGS -x $COMMANDS && | 1056 $GDB $GDB_ARGS -x $COMMANDS && |
| 1058 rm -f "$GDBSERVER_PIDFILE" | 1057 rm -f "$GDBSERVER_PIDFILE" |
| OLD | NEW |