| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 clean_exit () { | 30 clean_exit () { |
| 31 if [ "$TMPDIR" ]; then | 31 if [ "$TMPDIR" ]; then |
| 32 GDBSERVER_PID=$(cat $GDBSERVER_PIDFILE 2>/dev/null) | 32 GDBSERVER_PID=$(cat $GDBSERVER_PIDFILE 2>/dev/null) |
| 33 if [ "$GDBSERVER_PID" ]; then | 33 if [ "$GDBSERVER_PID" ]; then |
| 34 log "Killing background gdbserver process: $GDBSERVER_PID" | 34 log "Killing background gdbserver process: $GDBSERVER_PID" |
| 35 kill -9 $GDBSERVER_PID >/dev/null 2>&1 | 35 kill -9 $GDBSERVER_PID >/dev/null 2>&1 |
| 36 fi | 36 fi |
| 37 if [ "$TARGET_GDBSERVER" ]; then | 37 if [ "$TARGET_GDBSERVER" ]; then |
| 38 log "Removing target gdbserver binary: $TARGET_GDBSERVER." | 38 log "Removing target gdbserver binary: $TARGET_GDBSERVER." |
| 39 "$ADB" shell rm "$TARGET_GDBSERVER" >/dev/null 2>&1 | 39 "$ADB" shell run-as "$PACKAGE_NAME" rm "$TARGET_GDBSERVER" >/dev/null 2>&1 |
| 40 fi | 40 fi |
| 41 log "Cleaning up: $TMPDIR" | 41 log "Cleaning up: $TMPDIR" |
| 42 rm -rf "$TMPDIR" | 42 rm -rf "$TMPDIR" |
| 43 fi | 43 fi |
| 44 trap "" EXIT | 44 trap "" EXIT |
| 45 exit $1 | 45 exit $1 |
| 46 } | 46 } |
| 47 | 47 |
| 48 # Ensure clean exit on Ctrl-C or normal exit. | 48 # Ensure clean exit on Ctrl-C or normal exit. |
| 49 trap "clean_exit 1" INT HUP QUIT TERM | 49 trap "clean_exit 1" INT HUP QUIT TERM |
| (...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 | 727 |
| 728 SYMBOL_DIR=$CHROMIUM_SRC/$CHROMIUM_OUT_DIR/$SUBDIR | 728 SYMBOL_DIR=$CHROMIUM_SRC/$CHROMIUM_OUT_DIR/$SUBDIR |
| 729 log "Auto-config: --symbol-dir=$SYMBOL_DIR" | 729 log "Auto-config: --symbol-dir=$SYMBOL_DIR" |
| 730 } | 730 } |
| 731 | 731 |
| 732 if [ -z "$SYMBOL_DIR" ]; then | 732 if [ -z "$SYMBOL_DIR" ]; then |
| 733 detect_symbol_dir "$BUILDTYPE" | 733 detect_symbol_dir "$BUILDTYPE" |
| 734 fi | 734 fi |
| 735 | 735 |
| 736 # Allow several concurrent debugging sessions | 736 # Allow several concurrent debugging sessions |
| 737 TARGET_GDBSERVER=/data/local/tmp/gdbserver-adb-gdb-$TMP_ID | 737 TARGET_GDBSERVER=/data/data/$PACKAGE_NAME/gdbserver-adb-gdb-$TMP_ID |
| 738 TMP_TARGET_GDBSERVER=/data/local/tmp/gdbserver-adb-gdb-$TMP_ID |
| 738 | 739 |
| 739 # Return the build fingerprint contained in a build.prop file. | 740 # Return the build fingerprint contained in a build.prop file. |
| 740 # $1: path to build.prop file | 741 # $1: path to build.prop file |
| 741 get_build_fingerprint_from () { | 742 get_build_fingerprint_from () { |
| 742 cat "$1" | grep -e '^ro.build.fingerprint=' | cut -d= -f2 | 743 cat "$1" | grep -e '^ro.build.fingerprint=' | cut -d= -f2 |
| 743 } | 744 } |
| 744 | 745 |
| 745 | 746 |
| 746 ORG_PULL_LIBS_DIR=$PULL_LIBS_DIR | 747 ORG_PULL_LIBS_DIR=$PULL_LIBS_DIR |
| 747 PULL_LIBS_DIR=${PULL_LIBS_DIR:-$DEFAULT_PULL_LIBS_DIR} | 748 PULL_LIBS_DIR=${PULL_LIBS_DIR:-$DEFAULT_PULL_LIBS_DIR} |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 # Determine if 'adb shell' runs as root or not. | 838 # Determine if 'adb shell' runs as root or not. |
| 838 # If so, we can launch gdbserver directly, otherwise, we have to | 839 # If so, we can launch gdbserver directly, otherwise, we have to |
| 839 # use run-as $PACKAGE_NAME ..., which requires the package to be debuggable. | 840 # use run-as $PACKAGE_NAME ..., which requires the package to be debuggable. |
| 840 # | 841 # |
| 841 if [ "$SU_PREFIX" ]; then | 842 if [ "$SU_PREFIX" ]; then |
| 842 # Need to check that this works properly. | 843 # Need to check that this works properly. |
| 843 SU_PREFIX_TEST_LOG=$TMPDIR/su-prefix.log | 844 SU_PREFIX_TEST_LOG=$TMPDIR/su-prefix.log |
| 844 adb_shell $SU_PREFIX \"echo "foo"\" > $SU_PREFIX_TEST_LOG 2>&1 | 845 adb_shell $SU_PREFIX \"echo "foo"\" > $SU_PREFIX_TEST_LOG 2>&1 |
| 845 if [ $? != 0 -o "$(cat $SU_PREFIX_TEST_LOG)" != "foo" ]; then | 846 if [ $? != 0 -o "$(cat $SU_PREFIX_TEST_LOG)" != "foo" ]; then |
| 846 echo "ERROR: Cannot use '$SU_PREFIX' as a valid su prefix:" | 847 echo "ERROR: Cannot use '$SU_PREFIX' as a valid su prefix:" |
| 847 echo "$ adb shell $SU_PREFIX echo foo" | 848 echo "$ adb shell $SU_PREFIX \"echo foo\"" |
| 848 cat $SU_PREFIX_TEST_LOG | 849 cat $SU_PREFIX_TEST_LOG |
| 849 exit 1 | 850 exit 1 |
| 850 fi | 851 fi |
| 851 COMMAND_PREFIX="$SU_PREFIX" | 852 COMMAND_PREFIX="$SU_PREFIX \"" |
| 853 COMMAND_SUFFIX="\"" |
| 852 else | 854 else |
| 853 SHELL_UID=$(adb shell cat /proc/self/status | \ | 855 SHELL_UID=$(adb shell cat /proc/self/status | \ |
| 854 awk '$1 == "Uid:" { print $2; }') | 856 awk '$1 == "Uid:" { print $2; }') |
| 855 log "Shell UID: $SHELL_UID" | 857 log "Shell UID: $SHELL_UID" |
| 856 if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then | 858 if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then |
| 857 COMMAND_PREFIX="run-as $PACKAGE_NAME" | 859 COMMAND_PREFIX="run-as $PACKAGE_NAME" |
| 860 COMMAND_SUFFIX= |
| 858 else | 861 else |
| 859 COMMAND_PREFIX= | 862 COMMAND_PREFIX= |
| 863 COMMAND_SUFFIX= |
| 860 fi | 864 fi |
| 861 fi | 865 fi |
| 862 log "Command prefix: '$COMMAND_PREFIX'" | 866 log "Command prefix: '$COMMAND_PREFIX'" |
| 867 log "Command suffix: '$COMMAND_SUFFIX'" |
| 863 | 868 |
| 864 # Pull device's system libraries that are mapped by our process. | 869 # Pull device's system libraries that are mapped by our process. |
| 865 # Pulling all system libraries is too long, so determine which ones | 870 # Pulling all system libraries is too long, so determine which ones |
| 866 # we need by looking at /proc/$PID/maps instead | 871 # we need by looking at /proc/$PID/maps instead |
| 867 if [ "$PULL_LIBS" -a -z "$NO_PULL_LIBS" ]; then | 872 if [ "$PULL_LIBS" -a -z "$NO_PULL_LIBS" ]; then |
| 868 echo "Extracting system libraries into: $PULL_LIBS_DIR" | 873 echo "Extracting system libraries into: $PULL_LIBS_DIR" |
| 869 rm -f $PULL_LIBS_DIR/build.prop | 874 rm -f $PULL_LIBS_DIR/build.prop |
| 870 MAPPINGS=$(adb_shell $COMMAND_PREFIX \"cat /proc/$PID/maps\") | 875 MAPPINGS=$(adb_shell $COMMAND_PREFIX cat /proc/$PID/maps $COMMAND_SUFFIX) |
| 871 if [ $? != 0 ]; then | 876 if [ $? != 0 ]; then |
| 872 echo "ERROR: Could not list process's memory mappings." | 877 echo "ERROR: Could not list process's memory mappings." |
| 873 if [ "$SU_PREFIX" ]; then | 878 if [ "$SU_PREFIX" ]; then |
| 874 panic "Are you sure your --su-prefix is correct?" | 879 panic "Are you sure your --su-prefix is correct?" |
| 875 else | 880 else |
| 876 panic "Use --su-prefix if the application is not debuggable." | 881 panic "Use --su-prefix if the application is not debuggable." |
| 877 fi | 882 fi |
| 878 fi | 883 fi |
| 879 SYSTEM_LIBS=$(echo "$MAPPINGS" | \ | 884 SYSTEM_LIBS=$(echo "$MAPPINGS" | \ |
| 880 awk '$6 ~ /\/system\/.*\.so$/ { print $6; }' | sort -u) | 885 awk '$6 ~ /\/system\/.*\.so$/ { print $6; }' | sort -u) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 895 SOLIB_DIRS=$(find $PULL_LIBS_DIR -mindepth 1 -maxdepth 4 -type d | \ | 900 SOLIB_DIRS=$(find $PULL_LIBS_DIR -mindepth 1 -maxdepth 4 -type d | \ |
| 896 grep -v "^$" | tr '\n' ':') | 901 grep -v "^$" | tr '\n' ':') |
| 897 | 902 |
| 898 # This is a re-implementation of gdbclient, where we use compatible | 903 # This is a re-implementation of gdbclient, where we use compatible |
| 899 # versions of gdbserver and $GDBNAME to ensure that everything works | 904 # versions of gdbserver and $GDBNAME to ensure that everything works |
| 900 # properly. | 905 # properly. |
| 901 # | 906 # |
| 902 | 907 |
| 903 # Push gdbserver to the device | 908 # Push gdbserver to the device |
| 904 log "Pushing gdbserver $GDBSERVER to $TARGET_GDBSERVER" | 909 log "Pushing gdbserver $GDBSERVER to $TARGET_GDBSERVER" |
| 905 adb push $GDBSERVER $TARGET_GDBSERVER &>/dev/null | 910 adb push $GDBSERVER $TMP_TARGET_GDBSERVER &>/dev/null |
| 911 adb shell run-as $PACKAGE_NAME cp $TMP_TARGET_GDBSERVER . |
| 912 adb shell rm $TMP_TARGET_GDBSERVER |
| 906 fail_panic "Could not copy gdbserver to the device!" | 913 fail_panic "Could not copy gdbserver to the device!" |
| 907 | 914 |
| 908 PORT=5039 | 915 PORT=5039 |
| 909 HOST_PORT=$PORT | 916 HOST_PORT=$PORT |
| 910 TARGET_PORT=$PORT | 917 TARGET_PORT=$PORT |
| 911 | 918 |
| 912 # Select correct app_process for architecture. | 919 # Select correct app_process for architecture. |
| 913 case $TARGET_ARCH in | 920 case $TARGET_ARCH in |
| 914 arm|x86|mips) GDBEXEC=app_process;; | 921 arm|x86|mips) GDBEXEC=app_process;; |
| 915 arm64|x86_64) GDBEXEC=app_process64;; | 922 arm64|x86_64) GDBEXEC=app_process64;; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 937 | 944 |
| 938 # Start gdbserver in the background | 945 # Start gdbserver in the background |
| 939 # Note that using run-as requires the package to be debuggable. | 946 # Note that using run-as requires the package to be debuggable. |
| 940 # | 947 # |
| 941 # If not, this will fail horribly. The alternative is to run the | 948 # If not, this will fail horribly. The alternative is to run the |
| 942 # program as root, which requires of course root privileges. | 949 # program as root, which requires of course root privileges. |
| 943 # Maybe we should add a --root option to enable this? | 950 # Maybe we should add a --root option to enable this? |
| 944 # | 951 # |
| 945 log "Starting gdbserver in the background:" | 952 log "Starting gdbserver in the background:" |
| 946 GDBSERVER_LOG=$TMPDIR/gdbserver-$TMP_ID.log | 953 GDBSERVER_LOG=$TMPDIR/gdbserver-$TMP_ID.log |
| 947 log "adb shell $COMMAND_PREFIX \"$TARGET_GDBSERVER :$TARGET_PORT \ | 954 log "adb shell $COMMAND_PREFIX $TARGET_GDBSERVER :$TARGET_PORT \ |
| 948 --attach $PID"\" | 955 --attach $PID $COMMAND_SUFFIX" |
| 949 ("$ADB" shell $COMMAND_PREFIX \"$TARGET_GDBSERVER :$TARGET_PORT \ | 956 ("$ADB" shell $COMMAND_PREFIX $TARGET_GDBSERVER :$TARGET_PORT \ |
| 950 --attach $PID\" > $GDBSERVER_LOG 2>&1) & | 957 --attach $PID $COMMAND_SUFFIX > $GDBSERVER_LOG 2>&1) & |
| 951 GDBSERVER_PID=$! | 958 GDBSERVER_PID=$! |
| 952 echo "$GDBSERVER_PID" > $GDBSERVER_PIDFILE | 959 echo "$GDBSERVER_PID" > $GDBSERVER_PIDFILE |
| 953 log "background job pid: $GDBSERVER_PID" | 960 log "background job pid: $GDBSERVER_PID" |
| 954 | 961 |
| 955 # Check that it is still running after a few seconds. If not, this means we | 962 # Check that it is still running after a few seconds. If not, this means we |
| 956 # could not properly attach to it | 963 # could not properly attach to it |
| 957 sleep 2 | 964 sleep 2 |
| 958 log "Job control: $(jobs -l)" | 965 log "Job control: $(jobs -l)" |
| 959 STATE=$(jobs -l | awk '$2 == "'$GDBSERVER_PID'" { print $3; }') | 966 STATE=$(jobs -l | awk '$2 == "'$GDBSERVER_PID'" { print $3; }') |
| 960 if [ "$STATE" != "Running" ]; then | 967 if [ "$STATE" != "Running" ]; then |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 | 1010 |
| 1004 if [ "$VERBOSE" -gt 0 ]; then | 1011 if [ "$VERBOSE" -gt 0 ]; then |
| 1005 echo "### START $COMMANDS" | 1012 echo "### START $COMMANDS" |
| 1006 cat $COMMANDS | 1013 cat $COMMANDS |
| 1007 echo "### END $COMMANDS" | 1014 echo "### END $COMMANDS" |
| 1008 fi | 1015 fi |
| 1009 | 1016 |
| 1010 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS" | 1017 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS" |
| 1011 $GDB $GDB_ARGS -x $COMMANDS && | 1018 $GDB $GDB_ARGS -x $COMMANDS && |
| 1012 rm -f "$GDBSERVER_PIDFILE" | 1019 rm -f "$GDBSERVER_PIDFILE" |
| OLD | NEW |