| 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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 *) | 565 *) |
| 566 echo "$ARCH-linux-android" | 566 echo "$ARCH-linux-android" |
| 567 ;; | 567 ;; |
| 568 esac | 568 esac |
| 569 } | 569 } |
| 570 | 570 |
| 571 # Convert an NDK architecture name into a toolchain name prefix | 571 # Convert an NDK architecture name into a toolchain name prefix |
| 572 # $1: NDK architecture name (e.g. 'arm') | 572 # $1: NDK architecture name (e.g. 'arm') |
| 573 # Out: NDK toolchain name prefix (e.g. 'arm-linux-androideabi') | 573 # Out: NDK toolchain name prefix (e.g. 'arm-linux-androideabi') |
| 574 get_arch_toolchain_prefix () { | 574 get_arch_toolchain_prefix () { |
| 575 # Return the configure triplet, except for x86! | 575 # Return the configure triplet, except for x86 and x86_64! |
| 576 if [ "$1" = "x86" ]; then | 576 if [ "$1" = "x86" -o "$1" = "x86_64" ]; then |
| 577 echo "$1" | 577 echo "$1" |
| 578 else | 578 else |
| 579 get_arch_gnu_config $1 | 579 get_arch_gnu_config $1 |
| 580 fi | 580 fi |
| 581 } | 581 } |
| 582 | 582 |
| 583 # Find a NDK toolchain prebuilt file or sub-directory. | 583 # Find a NDK toolchain prebuilt file or sub-directory. |
| 584 # This will probe the various arch-specific toolchain directories | 584 # This will probe the various arch-specific toolchain directories |
| 585 # in the NDK for the needed file. | 585 # in the NDK for the needed file. |
| 586 # $1: NDK install path | 586 # $1: NDK install path |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 adb_shell $SU_PREFIX \"echo "foo"\" > $SU_PREFIX_TEST_LOG 2>&1 | 868 adb_shell $SU_PREFIX \"echo "foo"\" > $SU_PREFIX_TEST_LOG 2>&1 |
| 869 if [ $? != 0 -o "$(cat $SU_PREFIX_TEST_LOG)" != "foo" ]; then | 869 if [ $? != 0 -o "$(cat $SU_PREFIX_TEST_LOG)" != "foo" ]; then |
| 870 echo "ERROR: Cannot use '$SU_PREFIX' as a valid su prefix:" | 870 echo "ERROR: Cannot use '$SU_PREFIX' as a valid su prefix:" |
| 871 echo "$ adb shell $SU_PREFIX \"echo foo\"" | 871 echo "$ adb shell $SU_PREFIX \"echo foo\"" |
| 872 cat $SU_PREFIX_TEST_LOG | 872 cat $SU_PREFIX_TEST_LOG |
| 873 exit 1 | 873 exit 1 |
| 874 fi | 874 fi |
| 875 COMMAND_PREFIX="$SU_PREFIX \"" | 875 COMMAND_PREFIX="$SU_PREFIX \"" |
| 876 COMMAND_SUFFIX="\"" | 876 COMMAND_SUFFIX="\"" |
| 877 else | 877 else |
| 878 SHELL_UID=$(adb shell cat /proc/self/status | \ | 878 SHELL_UID=$("$ADB" shell cat /proc/self/status | \ |
| 879 awk '$1 == "Uid:" { print $2; }') | 879 awk '$1 == "Uid:" { print $2; }') |
| 880 log "Shell UID: $SHELL_UID" | 880 log "Shell UID: $SHELL_UID" |
| 881 if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then | 881 if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then |
| 882 COMMAND_PREFIX="run-as $PACKAGE_NAME" | 882 COMMAND_PREFIX="run-as $PACKAGE_NAME" |
| 883 COMMAND_SUFFIX= | 883 COMMAND_SUFFIX= |
| 884 else | 884 else |
| 885 COMMAND_PREFIX= | 885 COMMAND_PREFIX= |
| 886 COMMAND_SUFFIX= | 886 COMMAND_SUFFIX= |
| 887 fi | 887 fi |
| 888 fi | 888 fi |
| (...skipping 15 matching lines...) Expand all Loading... |
| 904 fi | 904 fi |
| 905 fi | 905 fi |
| 906 # Remove the fingerprint file in case pulling one of the libs fails. | 906 # Remove the fingerprint file in case pulling one of the libs fails. |
| 907 rm -f "$PULL_LIBS_DIR/build.fingerprint" | 907 rm -f "$PULL_LIBS_DIR/build.fingerprint" |
| 908 SYSTEM_LIBS=$(echo "$MAPPINGS" | \ | 908 SYSTEM_LIBS=$(echo "$MAPPINGS" | \ |
| 909 awk '$6 ~ /\/system\/.*\.so$/ { print $6; }' | sort -u) | 909 awk '$6 ~ /\/system\/.*\.so$/ { print $6; }' | sort -u) |
| 910 for SYSLIB in /system/bin/linker $SYSTEM_LIBS; do | 910 for SYSLIB in /system/bin/linker $SYSTEM_LIBS; do |
| 911 echo "Pulling from device: $SYSLIB" | 911 echo "Pulling from device: $SYSLIB" |
| 912 DST_FILE=$PULL_LIBS_DIR$SYSLIB | 912 DST_FILE=$PULL_LIBS_DIR$SYSLIB |
| 913 DST_DIR=$(dirname "$DST_FILE") | 913 DST_DIR=$(dirname "$DST_FILE") |
| 914 mkdir -p "$DST_DIR" && adb pull $SYSLIB "$DST_FILE" 2>/dev/null | 914 mkdir -p "$DST_DIR" && "$ADB" pull $SYSLIB "$DST_FILE" 2>/dev/null |
| 915 fail_panic "Could not pull $SYSLIB from device !?" | 915 fail_panic "Could not pull $SYSLIB from device !?" |
| 916 done | 916 done |
| 917 echo "Writing the device fingerprint" | 917 echo "Writing the device fingerprint" |
| 918 echo "$DEVICE_FINGERPRINT" > "$PULL_LIBS_DIR/build.fingerprint" | 918 echo "$DEVICE_FINGERPRINT" > "$PULL_LIBS_DIR/build.fingerprint" |
| 919 fi | 919 fi |
| 920 | 920 |
| 921 # Find all the sub-directories of $PULL_LIBS_DIR, up to depth 4 | 921 # Find all the sub-directories of $PULL_LIBS_DIR, up to depth 4 |
| 922 # so we can add them to solib-search-path later. | 922 # so we can add them to solib-search-path later. |
| 923 SOLIB_DIRS=$(find $PULL_LIBS_DIR -mindepth 1 -maxdepth 4 -type d | \ | 923 SOLIB_DIRS=$(find $PULL_LIBS_DIR -mindepth 1 -maxdepth 4 -type d | \ |
| 924 grep -v "^$" | tr '\n' ':') | 924 grep -v "^$" | tr '\n' ':') |
| 925 | 925 |
| 926 # This is a re-implementation of gdbclient, where we use compatible | 926 # This is a re-implementation of gdbclient, where we use compatible |
| 927 # versions of gdbserver and $GDBNAME to ensure that everything works | 927 # versions of gdbserver and $GDBNAME to ensure that everything works |
| 928 # properly. | 928 # properly. |
| 929 # | 929 # |
| 930 | 930 |
| 931 # Push gdbserver to the device | 931 # Push gdbserver to the device |
| 932 log "Pushing gdbserver $GDBSERVER to $TARGET_GDBSERVER" | 932 log "Pushing gdbserver $GDBSERVER to $TARGET_GDBSERVER" |
| 933 adb push $GDBSERVER $TMP_TARGET_GDBSERVER &>/dev/null | 933 "$ADB" push $GDBSERVER $TMP_TARGET_GDBSERVER &>/dev/null |
| 934 adb shell $COMMAND_PREFIX cp $TMP_TARGET_GDBSERVER $TARGET_GDBSERVER $COMMAND_SU
FFIX | 934 "$ADB" shell $COMMAND_PREFIX cp $TMP_TARGET_GDBSERVER $TARGET_GDBSERVER $COMMAND
_SUFFIX |
| 935 adb shell rm $TMP_TARGET_GDBSERVER | 935 "$ADB" shell rm $TMP_TARGET_GDBSERVER |
| 936 fail_panic "Could not copy gdbserver to the device!" | 936 fail_panic "Could not copy gdbserver to the device!" |
| 937 | 937 |
| 938 if [ -z "$PORT" ]; then | 938 if [ -z "$PORT" ]; then |
| 939 PORT=5039 | 939 PORT=5039 |
| 940 fi | 940 fi |
| 941 HOST_PORT=$PORT | 941 HOST_PORT=$PORT |
| 942 TARGET_PORT=$PORT | 942 TARGET_PORT=$PORT |
| 943 | 943 |
| 944 # Select correct app_process for architecture. | 944 # Select correct app_process for architecture. |
| 945 case $TARGET_ARCH in | 945 case $TARGET_ARCH in |
| (...skipping 11 matching lines...) Expand all Loading... |
| 957 # Detect AddressSanitizer setup on the device. In that case app_process is a | 957 # Detect AddressSanitizer setup on the device. In that case app_process is a |
| 958 # script, and the real executable is app_process.real. | 958 # script, and the real executable is app_process.real. |
| 959 GDBEXEC_ASAN=app_process.real | 959 GDBEXEC_ASAN=app_process.real |
| 960 adb_shell ls /system/bin/$GDBEXEC_ASAN | 960 adb_shell ls /system/bin/$GDBEXEC_ASAN |
| 961 if [ $? == 0 ]; then | 961 if [ $? == 0 ]; then |
| 962 GDBEXEC=$GDBEXEC_ASAN | 962 GDBEXEC=$GDBEXEC_ASAN |
| 963 fi | 963 fi |
| 964 | 964 |
| 965 # Pull the app_process binary from the device. | 965 # Pull the app_process binary from the device. |
| 966 log "Pulling $GDBEXEC from device" | 966 log "Pulling $GDBEXEC from device" |
| 967 adb pull /system/bin/$GDBEXEC "$TMPDIR"/$GDBEXEC &>/dev/null | 967 "$ADB" pull /system/bin/$GDBEXEC "$TMPDIR"/$GDBEXEC &>/dev/null |
| 968 fail_panic "Could not retrieve $GDBEXEC from the device!" | 968 fail_panic "Could not retrieve $GDBEXEC from the device!" |
| 969 | 969 |
| 970 # Setup network redirection | 970 # Setup network redirection |
| 971 log "Setting network redirection (host:$HOST_PORT -> device:$TARGET_PORT)" | 971 log "Setting network redirection (host:$HOST_PORT -> device:$TARGET_PORT)" |
| 972 adb forward tcp:$HOST_PORT tcp:$TARGET_PORT | 972 "$ADB" forward tcp:$HOST_PORT tcp:$TARGET_PORT |
| 973 fail_panic "Could not setup network redirection from \ | 973 fail_panic "Could not setup network redirection from \ |
| 974 host:localhost:$HOST_PORT to device:localhost:$TARGET_PORT!" | 974 host:localhost:$HOST_PORT to device:localhost:$TARGET_PORT!" |
| 975 | 975 |
| 976 # Start gdbserver in the background | 976 # Start gdbserver in the background |
| 977 # Note that using run-as requires the package to be debuggable. | 977 # Note that using run-as requires the package to be debuggable. |
| 978 # | 978 # |
| 979 # If not, this will fail horribly. The alternative is to run the | 979 # If not, this will fail horribly. The alternative is to run the |
| 980 # program as root, which requires of course root privileges. | 980 # program as root, which requires of course root privileges. |
| 981 # Maybe we should add a --root option to enable this? | 981 # Maybe we should add a --root option to enable this? |
| 982 # | 982 # |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 | 1042 |
| 1043 if [ "$VERBOSE" -gt 0 ]; then | 1043 if [ "$VERBOSE" -gt 0 ]; then |
| 1044 echo "### START $COMMANDS" | 1044 echo "### START $COMMANDS" |
| 1045 cat $COMMANDS | 1045 cat $COMMANDS |
| 1046 echo "### END $COMMANDS" | 1046 echo "### END $COMMANDS" |
| 1047 fi | 1047 fi |
| 1048 | 1048 |
| 1049 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS" | 1049 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS" |
| 1050 $GDB $GDB_ARGS -x $COMMANDS && | 1050 $GDB $GDB_ARGS -x $COMMANDS && |
| 1051 rm -f "$GDBSERVER_PIDFILE" | 1051 rm -f "$GDBSERVER_PIDFILE" |
| OLD | NEW |