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 # Location of Chromium-top-level sources. | 18 # Location of Chromium-top-level sources. |
19 CHROMIUM_SRC=$(cd "$PROGDIR"/../.. && pwd 2>/dev/null) | 19 CHROMIUM_SRC=$(cd "$PROGDIR"/../.. && pwd 2>/dev/null) |
20 | 20 |
| 21 # Location of Chromium out/ directory. |
| 22 if [ -z "$CHROMIUM_OUT_DIR" ]; then |
| 23 CHROMIUM_OUT_DIR=out |
| 24 fi |
| 25 |
21 TMPDIR= | 26 TMPDIR= |
22 GDBSERVER_PIDFILE= | 27 GDBSERVER_PIDFILE= |
23 TARGET_GDBSERVER= | 28 TARGET_GDBSERVER= |
24 | 29 |
25 clean_exit () { | 30 clean_exit () { |
26 if [ "$TMPDIR" ]; then | 31 if [ "$TMPDIR" ]; then |
27 GDBSERVER_PID=$(cat $GDBSERVER_PIDFILE 2>/dev/null) | 32 GDBSERVER_PID=$(cat $GDBSERVER_PIDFILE 2>/dev/null) |
28 if [ "$GDBSERVER_PID" ]; then | 33 if [ "$GDBSERVER_PID" ]; then |
29 log "Killing background gdbserver process: $GDBSERVER_PID" | 34 log "Killing background gdbserver process: $GDBSERVER_PID" |
30 kill -9 $GDBSERVER_PID >/dev/null 2>&1 | 35 kill -9 $GDBSERVER_PID >/dev/null 2>&1 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 ;; | 165 ;; |
161 --start) | 166 --start) |
162 START=true | 167 START=true |
163 ;; | 168 ;; |
164 --su-prefix=*) | 169 --su-prefix=*) |
165 SU_PREFIX=$optarg | 170 SU_PREFIX=$optarg |
166 ;; | 171 ;; |
167 --symbol-dir=*) | 172 --symbol-dir=*) |
168 SYMBOL_DIR=$optarg | 173 SYMBOL_DIR=$optarg |
169 ;; | 174 ;; |
| 175 --out-dir=*) |
| 176 CHROMIUM_OUT_DIR=$optarg |
| 177 ;; |
170 --target-arch=*) | 178 --target-arch=*) |
171 TARGET_ARCH=$optarg | 179 TARGET_ARCH=$optarg |
172 ;; | 180 ;; |
173 --toolchain=*) | 181 --toolchain=*) |
174 TOOLCHAIN=$optarg | 182 TOOLCHAIN=$optarg |
175 ;; | 183 ;; |
176 --ui) | 184 --ui) |
177 GDBEXEPOSTFIX=gdbtui | 185 GDBEXEPOSTFIX=gdbtui |
178 ;; | 186 ;; |
179 --verbose) | 187 --verbose) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 find all of them automatically. This is the recommended way to use it. | 249 find all of them automatically. This is the recommended way to use it. |
242 | 250 |
243 Otherwise, if you have ANDROID_NDK_ROOT defined in your environment, | 251 Otherwise, if you have ANDROID_NDK_ROOT defined in your environment, |
244 the script will use it to find the gdb and gdbserver binaries. You can | 252 the script will use it to find the gdb and gdbserver binaries. You can |
245 also use --ndk-dir=<path> to specify an alternative NDK installation | 253 also use --ndk-dir=<path> to specify an alternative NDK installation |
246 directory. | 254 directory. |
247 | 255 |
248 The script tries to find the most recent version of the debug version of | 256 The script tries to find the most recent version of the debug version of |
249 shared libraries under one of the following directories: | 257 shared libraries under one of the following directories: |
250 | 258 |
251 \$CHROMIUM_SRC/out/Release/lib/ (used by Ninja builds) | 259 \$CHROMIUM_SRC/<out>/Release/lib/ (used by Ninja builds) |
252 \$CHROMIUM_SRC/out/Debug/lib/ (used by Ninja builds) | 260 \$CHROMIUM_SRC/<out>/Debug/lib/ (used by Ninja builds) |
253 \$CHROMIUM_SRC/out/Release/lib.target/ (used by Make builds) | 261 \$CHROMIUM_SRC/<out>/Release/lib.target/ (used by Make builds) |
254 \$CHROMIUM_SRC/out/Debug/lib.target/ (used by Make builds) | 262 \$CHROMIUM_SRC/<out>/Debug/lib.target/ (used by Make builds) |
| 263 |
| 264 Where <out> is 'out' by default, unless the --out=<name> option is used or |
| 265 the CHROMIUM_OUT_DIR environment variable is defined. |
255 | 266 |
256 You can restrict this search by using --release or --debug to specify the | 267 You can restrict this search by using --release or --debug to specify the |
257 build type, or simply use --symbol-dir=<path> to specify the file manually. | 268 build type, or simply use --symbol-dir=<path> to specify the file manually. |
258 | 269 |
259 The script tries to extract the target architecture from your GYP_DEFINES, | 270 The script tries to extract the target architecture from your GYP_DEFINES, |
260 but if this fails, will default to 'arm'. Use --target-arch=<name> to force | 271 but if this fails, will default to 'arm'. Use --target-arch=<name> to force |
261 its value. | 272 its value. |
262 | 273 |
263 Otherwise, the script will complain, but you can use the --gdbserver, | 274 Otherwise, the script will complain, but you can use the --gdbserver, |
264 --gdb and --symbol-lib options to specify everything manually. | 275 --gdb and --symbol-lib options to specify everything manually. |
(...skipping 23 matching lines...) Expand all Loading... |
288 will be passed to gdb after the remote connection and library symbol | 299 will be passed to gdb after the remote connection and library symbol |
289 loading have completed. | 300 loading have completed. |
290 | 301 |
291 Valid options: | 302 Valid options: |
292 --help|-h|-? Print this message. | 303 --help|-h|-? Print this message. |
293 --verbose Increase verbosity. | 304 --verbose Increase verbosity. |
294 | 305 |
295 --sandboxed Debug first sandboxed process we find. | 306 --sandboxed Debug first sandboxed process we find. |
296 --sandboxed=<num> Debug specific sandboxed process. | 307 --sandboxed=<num> Debug specific sandboxed process. |
297 --symbol-dir=<path> Specify directory with symbol shared libraries. | 308 --symbol-dir=<path> Specify directory with symbol shared libraries. |
| 309 --out-dir=<path> Specify the out directory. |
298 --package-name=<name> Specify package name (alternative to 1st argument). | 310 --package-name=<name> Specify package name (alternative to 1st argument). |
299 --program-name=<name> Specify program name (cosmetic only). | 311 --program-name=<name> Specify program name (cosmetic only). |
300 --pid=<pid> Specify application process pid. | 312 --pid=<pid> Specify application process pid. |
301 --force Kill any previous debugging session, if any. | 313 --force Kill any previous debugging session, if any. |
302 --start Start package's activity on device. | 314 --start Start package's activity on device. |
303 --ui Use gdbtui instead of gdb | 315 --ui Use gdbtui instead of gdb |
304 --activity=<name> Activity name for --start [$DEFAULT_ACTIVITY]. | 316 --activity=<name> Activity name for --start [$DEFAULT_ACTIVITY]. |
305 --annotate=<num> Enable gdb annotation. | 317 --annotate=<num> Enable gdb annotation. |
306 --script=<file> Specify extra GDB init script. | 318 --script=<file> Specify extra GDB init script. |
307 | 319 |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 | 677 |
666 # Return the timestamp of a given time, as number of seconds since epoch. | 678 # Return the timestamp of a given time, as number of seconds since epoch. |
667 # $1: file path | 679 # $1: file path |
668 # Out: file timestamp | 680 # Out: file timestamp |
669 get_file_timestamp () { | 681 get_file_timestamp () { |
670 stat -c %Y "$1" 2>/dev/null | 682 stat -c %Y "$1" 2>/dev/null |
671 } | 683 } |
672 | 684 |
673 # Detect the build type and symbol directory. This is done by finding | 685 # Detect the build type and symbol directory. This is done by finding |
674 # the most recent sub-directory containing debug shared libraries under | 686 # the most recent sub-directory containing debug shared libraries under |
675 # $CHROMIUM_SRC/out/ | 687 # $CHROMIUM_SRC/$CHROMIUM_OUT_DIR/ |
676 # | 688 # |
677 # $1: $BUILDTYPE value, can be empty | 689 # $1: $BUILDTYPE value, can be empty |
678 # Out: nothing, but this sets SYMBOL_DIR | 690 # Out: nothing, but this sets SYMBOL_DIR |
679 # | 691 # |
680 detect_symbol_dir () { | 692 detect_symbol_dir () { |
681 local SUBDIRS SUBDIR LIST DIR DIR_LIBS TSTAMP | 693 local SUBDIRS SUBDIR LIST DIR DIR_LIBS TSTAMP |
682 # Note: Ninja places debug libraries under out/$BUILDTYPE/lib/, while | 694 # Note: Ninja places debug libraries under out/$BUILDTYPE/lib/, while |
683 # Make places then under out/$BUILDTYPE/lib.target. | 695 # Make places then under out/$BUILDTYPE/lib.target. |
684 if [ "$1" ]; then | 696 if [ "$1" ]; then |
685 SUBDIRS="$1/lib $1/lib.target" | 697 SUBDIRS="$1/lib $1/lib.target" |
686 else | 698 else |
687 SUBDIRS="Release/lib Debug/lib Release/lib.target Debug/lib.target" | 699 SUBDIRS="Release/lib Debug/lib Release/lib.target Debug/lib.target" |
688 fi | 700 fi |
689 LIST=$TMPDIR/scan-subdirs-$$.txt | 701 LIST=$TMPDIR/scan-subdirs-$$.txt |
690 printf "" > "$LIST" | 702 printf "" > "$LIST" |
691 for SUBDIR in $SUBDIRS; do | 703 for SUBDIR in $SUBDIRS; do |
692 DIR=$CHROMIUM_SRC/out/$SUBDIR | 704 DIR=$CHROMIUM_SRC/$CHROMIUM_OUT_DIR/$SUBDIR |
693 if [ -d "$DIR" ]; then | 705 if [ -d "$DIR" ]; then |
694 # Ignore build directories that don't contain symbol versions | 706 # Ignore build directories that don't contain symbol versions |
695 # of the shared libraries. | 707 # of the shared libraries. |
696 DIR_LIBS=$(ls "$DIR"/lib*.so 2>/dev/null) | 708 DIR_LIBS=$(ls "$DIR"/lib*.so 2>/dev/null) |
697 if [ -z "$DIR_LIBS" ]; then | 709 if [ -z "$DIR_LIBS" ]; then |
698 echo "No shared libs: $DIR" | 710 echo "No shared libs: $DIR" |
699 continue | 711 continue |
700 fi | 712 fi |
701 TSTAMP=$(get_file_timestamp "$DIR") | 713 TSTAMP=$(get_file_timestamp "$DIR") |
702 printf "%s %s\n" "$TSTAMP" "$SUBDIR" >> "$LIST" | 714 printf "%s %s\n" "$TSTAMP" "$SUBDIR" >> "$LIST" |
703 fi | 715 fi |
704 done | 716 done |
705 SUBDIR=$(cat $LIST | sort -r | head -1 | cut -d" " -f2) | 717 SUBDIR=$(cat $LIST | sort -r | head -1 | cut -d" " -f2) |
706 rm -f "$LIST" | 718 rm -f "$LIST" |
707 | 719 |
708 if [ -z "$SUBDIR" ]; then | 720 if [ -z "$SUBDIR" ]; then |
709 if [ -z "$1" ]; then | 721 if [ -z "$1" ]; then |
710 panic "Could not find any build directory under \ | 722 panic "Could not find any build directory under \ |
711 $CHROMIUM_SRC/out. Please build the program first!" | 723 $CHROMIUM_SRC/$CHROMIUM_OUT_DIR. Please build the program first!" |
712 else | 724 else |
713 panic "Could not find any $1 directory under \ | 725 panic "Could not find any $1 directory under \ |
714 $CHROMIUM_SRC/out. Check your build type!" | 726 $CHROMIUM_SRC/$CHROMIUM_OUT_DIR. Check your build type!" |
715 fi | 727 fi |
716 fi | 728 fi |
717 | 729 |
718 SYMBOL_DIR=$CHROMIUM_SRC/out/$SUBDIR | 730 SYMBOL_DIR=$CHROMIUM_SRC/$CHROMIUM_OUT_DIR/$SUBDIR |
719 log "Auto-config: --symbol-dir=$SYMBOL_DIR" | 731 log "Auto-config: --symbol-dir=$SYMBOL_DIR" |
720 } | 732 } |
721 | 733 |
722 if [ -z "$SYMBOL_DIR" ]; then | 734 if [ -z "$SYMBOL_DIR" ]; then |
723 detect_symbol_dir "$BUILDTYPE" | 735 detect_symbol_dir "$BUILDTYPE" |
724 fi | 736 fi |
725 | 737 |
726 # Allow several concurrent debugging sessions | 738 # Allow several concurrent debugging sessions |
727 TARGET_GDBSERVER=/data/local/tmp/gdbserver-adb-gdb-$TMP_ID | 739 TARGET_GDBSERVER=/data/local/tmp/gdbserver-adb-gdb-$TMP_ID |
728 | 740 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 | 971 |
960 if [ "$VERBOSE" -gt 0 ]; then | 972 if [ "$VERBOSE" -gt 0 ]; then |
961 echo "### START $COMMANDS" | 973 echo "### START $COMMANDS" |
962 cat $COMMANDS | 974 cat $COMMANDS |
963 echo "### END $COMMANDS" | 975 echo "### END $COMMANDS" |
964 fi | 976 fi |
965 | 977 |
966 log "Launching gdb client: $GDB $GDBARGS -x $COMMANDS" | 978 log "Launching gdb client: $GDB $GDBARGS -x $COMMANDS" |
967 $GDB $GDBARGS -x $COMMANDS && | 979 $GDB $GDBARGS -x $COMMANDS && |
968 rm -f "$GDBSERVER_PIDFILE" | 980 rm -f "$GDBSERVER_PIDFILE" |
OLD | NEW |