Chromium Code Reviews| 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 |
| (...skipping 230 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. | 241 find all of them automatically. This is the recommended way to use it. |
| 242 | 242 |
| 243 Otherwise, if you have ANDROID_NDK_ROOT defined in your environment, | 243 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 | 244 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 | 245 also use --ndk-dir=<path> to specify an alternative NDK installation |
| 246 directory. | 246 directory. |
| 247 | 247 |
| 248 The script tries to find the most recent version of the debug version of | 248 The script tries to find the most recent version of the debug version of |
| 249 shared libraries under one of the following directories: | 249 shared libraries under one of the following directories: |
| 250 | 250 |
| 251 \$CHROMIUM_SRC/out/Release/lib/ (used by Ninja builds) | 251 \$CHROMIUM_SRC/$CHROMIUM_OUT_DIR/Release/lib/ (used by Ninja builds) |
| 252 \$CHROMIUM_SRC/out/Debug/lib/ (used by Ninja builds) | 252 \$CHROMIUM_SRC/$CHROMIUM_OUT_DIR/Debug/lib/ (used by Ninja builds) |
| 253 \$CHROMIUM_SRC/out/Release/lib.target/ (used by Make builds) | 253 \$CHROMIUM_SRC/$CHROMIUM_OUT_DIR/Release/lib.target/ (used by Make builds) |
| 254 \$CHROMIUM_SRC/out/Debug/lib.target/ (used by Make builds) | 254 \$CHROMIUM_SRC/$CHROMIUM_OUT_DIR/Debug/lib.target/ (used by Make builds) |
|
digit1
2013/11/20 13:49:18
I believe this will get printed before detect_symb
bulach
2013/11/20 16:47:36
excellent idea! done.
| |
| 255 | 255 |
| 256 You can restrict this search by using --release or --debug to specify the | 256 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. | 257 build type, or simply use --symbol-dir=<path> to specify the file manually. |
| 258 | 258 |
| 259 The script tries to extract the target architecture from your GYP_DEFINES, | 259 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 | 260 but if this fails, will default to 'arm'. Use --target-arch=<name> to force |
| 261 its value. | 261 its value. |
| 262 | 262 |
| 263 Otherwise, the script will complain, but you can use the --gdbserver, | 263 Otherwise, the script will complain, but you can use the --gdbserver, |
| 264 --gdb and --symbol-lib options to specify everything manually. | 264 --gdb and --symbol-lib options to specify everything manually. |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 | 665 |
| 666 # Return the timestamp of a given time, as number of seconds since epoch. | 666 # Return the timestamp of a given time, as number of seconds since epoch. |
| 667 # $1: file path | 667 # $1: file path |
| 668 # Out: file timestamp | 668 # Out: file timestamp |
| 669 get_file_timestamp () { | 669 get_file_timestamp () { |
| 670 stat -c %Y "$1" 2>/dev/null | 670 stat -c %Y "$1" 2>/dev/null |
| 671 } | 671 } |
| 672 | 672 |
| 673 # Detect the build type and symbol directory. This is done by finding | 673 # Detect the build type and symbol directory. This is done by finding |
| 674 # the most recent sub-directory containing debug shared libraries under | 674 # the most recent sub-directory containing debug shared libraries under |
| 675 # $CHROMIUM_SRC/out/ | 675 # $CHROMIUM_SRC/$CHROMIUM_OUT_DIR/ |
| 676 # | 676 # |
| 677 # $1: $BUILDTYPE value, can be empty | 677 # $1: $BUILDTYPE value, can be empty |
| 678 # Out: nothing, but this sets SYMBOL_DIR | 678 # Out: nothing, but this sets SYMBOL_DIR |
| 679 # | 679 # |
| 680 detect_symbol_dir () { | 680 detect_symbol_dir () { |
| 681 local SUBDIRS SUBDIR LIST DIR DIR_LIBS TSTAMP | 681 local SUBDIRS SUBDIR LIST DIR DIR_LIBS TSTAMP OUT_DIR |
| 682 # Note: Ninja places debug libraries under out/$BUILDTYPE/lib/, while | 682 # Note: Ninja places debug libraries under out/$BUILDTYPE/lib/, while |
| 683 # Make places then under out/$BUILDTYPE/lib.target. | 683 # Make places then under out/$BUILDTYPE/lib.target. |
| 684 if [ "$1" ]; then | 684 if [ "$1" ]; then |
| 685 SUBDIRS="$1/lib $1/lib.target" | 685 SUBDIRS="$1/lib $1/lib.target" |
| 686 else | 686 else |
| 687 SUBDIRS="Release/lib Debug/lib Release/lib.target Debug/lib.target" | 687 SUBDIRS="Release/lib Debug/lib Release/lib.target Debug/lib.target" |
| 688 fi | 688 fi |
| 689 if [ "$CHROMIUM_OUT_DIR" ]; then | |
| 690 OUT_DIR="$CHROMIUM_OUT_DIR" | |
| 691 else | |
| 692 OUT_DIR="out" | |
| 693 fi | |
| 689 LIST=$TMPDIR/scan-subdirs-$$.txt | 694 LIST=$TMPDIR/scan-subdirs-$$.txt |
| 690 printf "" > "$LIST" | 695 printf "" > "$LIST" |
| 691 for SUBDIR in $SUBDIRS; do | 696 for SUBDIR in $SUBDIRS; do |
| 692 DIR=$CHROMIUM_SRC/out/$SUBDIR | 697 DIR=$CHROMIUM_SRC/$OUT_DIR/$SUBDIR |
| 693 if [ -d "$DIR" ]; then | 698 if [ -d "$DIR" ]; then |
| 694 # Ignore build directories that don't contain symbol versions | 699 # Ignore build directories that don't contain symbol versions |
| 695 # of the shared libraries. | 700 # of the shared libraries. |
| 696 DIR_LIBS=$(ls "$DIR"/lib*.so 2>/dev/null) | 701 DIR_LIBS=$(ls "$DIR"/lib*.so 2>/dev/null) |
| 697 if [ -z "$DIR_LIBS" ]; then | 702 if [ -z "$DIR_LIBS" ]; then |
| 698 echo "No shared libs: $DIR" | 703 echo "No shared libs: $DIR" |
| 699 continue | 704 continue |
| 700 fi | 705 fi |
| 701 TSTAMP=$(get_file_timestamp "$DIR") | 706 TSTAMP=$(get_file_timestamp "$DIR") |
| 702 printf "%s %s\n" "$TSTAMP" "$SUBDIR" >> "$LIST" | 707 printf "%s %s\n" "$TSTAMP" "$SUBDIR" >> "$LIST" |
| 703 fi | 708 fi |
| 704 done | 709 done |
| 705 SUBDIR=$(cat $LIST | sort -r | head -1 | cut -d" " -f2) | 710 SUBDIR=$(cat $LIST | sort -r | head -1 | cut -d" " -f2) |
| 706 rm -f "$LIST" | 711 rm -f "$LIST" |
| 707 | 712 |
| 708 if [ -z "$SUBDIR" ]; then | 713 if [ -z "$SUBDIR" ]; then |
| 709 if [ -z "$1" ]; then | 714 if [ -z "$1" ]; then |
| 710 panic "Could not find any build directory under \ | 715 panic "Could not find any build directory under \ |
| 711 $CHROMIUM_SRC/out. Please build the program first!" | 716 $CHROMIUM_SRC/$OUT_DIR. Please build the program first!" |
| 712 else | 717 else |
| 713 panic "Could not find any $1 directory under \ | 718 panic "Could not find any $1 directory under \ |
| 714 $CHROMIUM_SRC/out. Check your build type!" | 719 $CHROMIUM_SRC/$OUT_DIR. Check your build type!" |
| 715 fi | 720 fi |
| 716 fi | 721 fi |
| 717 | 722 |
| 718 SYMBOL_DIR=$CHROMIUM_SRC/out/$SUBDIR | 723 SYMBOL_DIR=$CHROMIUM_SRC/$OUT_DIR/$SUBDIR |
| 719 log "Auto-config: --symbol-dir=$SYMBOL_DIR" | 724 log "Auto-config: --symbol-dir=$SYMBOL_DIR" |
| 720 } | 725 } |
| 721 | 726 |
| 722 if [ -z "$SYMBOL_DIR" ]; then | 727 if [ -z "$SYMBOL_DIR" ]; then |
| 723 detect_symbol_dir "$BUILDTYPE" | 728 detect_symbol_dir "$BUILDTYPE" |
| 724 fi | 729 fi |
| 725 | 730 |
| 726 # Allow several concurrent debugging sessions | 731 # Allow several concurrent debugging sessions |
| 727 TARGET_GDBSERVER=/data/local/tmp/gdbserver-adb-gdb-$TMP_ID | 732 TARGET_GDBSERVER=/data/local/tmp/gdbserver-adb-gdb-$TMP_ID |
| 728 | 733 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 959 | 964 |
| 960 if [ "$VERBOSE" -gt 0 ]; then | 965 if [ "$VERBOSE" -gt 0 ]; then |
| 961 echo "### START $COMMANDS" | 966 echo "### START $COMMANDS" |
| 962 cat $COMMANDS | 967 cat $COMMANDS |
| 963 echo "### END $COMMANDS" | 968 echo "### END $COMMANDS" |
| 964 fi | 969 fi |
| 965 | 970 |
| 966 log "Launching gdb client: $GDB $GDBARGS -x $COMMANDS" | 971 log "Launching gdb client: $GDB $GDBARGS -x $COMMANDS" |
| 967 $GDB $GDBARGS -x $COMMANDS && | 972 $GDB $GDBARGS -x $COMMANDS && |
| 968 rm -f "$GDBSERVER_PIDFILE" | 973 rm -f "$GDBSERVER_PIDFILE" |
| OLD | NEW |