| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 BUILDTYPE= | 90 BUILDTYPE= |
| 91 FORCE= | 91 FORCE= |
| 92 GDBEXEPOSTFIX=gdb | 92 GDBEXEPOSTFIX=gdb |
| 93 GDBINIT= | 93 GDBINIT= |
| 94 GDBSERVER= | 94 GDBSERVER= |
| 95 HELP= | 95 HELP= |
| 96 NDK_DIR= | 96 NDK_DIR= |
| 97 NO_PULL_LIBS= | 97 NO_PULL_LIBS= |
| 98 PACKAGE_NAME= | 98 PACKAGE_NAME= |
| 99 PID= | 99 PID= |
| 100 PRIVILEGED= |
| 101 PRIVILEGED_INDEX= |
| 100 PROGRAM_NAME="activity" | 102 PROGRAM_NAME="activity" |
| 101 PULL_LIBS= | 103 PULL_LIBS= |
| 102 PULL_LIBS_DIR= | 104 PULL_LIBS_DIR= |
| 103 SANDBOXED= | 105 SANDBOXED= |
| 104 SANDBOXED_INDEX= | 106 SANDBOXED_INDEX= |
| 105 START= | 107 START= |
| 106 SU_PREFIX= | 108 SU_PREFIX= |
| 107 SYMBOL_DIR= | 109 SYMBOL_DIR= |
| 108 TARGET_ARCH= | 110 TARGET_ARCH= |
| 109 TOOLCHAIN= | 111 TOOLCHAIN= |
| (...skipping 28 matching lines...) Expand all Loading... |
| 138 ;; | 140 ;; |
| 139 --no-pull-libs) | 141 --no-pull-libs) |
| 140 NO_PULL_LIBS=true | 142 NO_PULL_LIBS=true |
| 141 ;; | 143 ;; |
| 142 --package-name=*) | 144 --package-name=*) |
| 143 PACKAGE_NAME=$optarg | 145 PACKAGE_NAME=$optarg |
| 144 ;; | 146 ;; |
| 145 --pid=*) | 147 --pid=*) |
| 146 PID=$optarg | 148 PID=$optarg |
| 147 ;; | 149 ;; |
| 150 --privileged) |
| 151 PRIVILEGED=true |
| 152 ;; |
| 153 --privileged=*) |
| 154 PRIVILEGED=true |
| 155 PRIVILEGED_INDEX=$optarg |
| 156 ;; |
| 148 --program-name=*) | 157 --program-name=*) |
| 149 PROGRAM_NAME=$optarg | 158 PROGRAM_NAME=$optarg |
| 150 ;; | 159 ;; |
| 151 --pull-libs) | 160 --pull-libs) |
| 152 PULL_LIBS=true | 161 PULL_LIBS=true |
| 153 ;; | 162 ;; |
| 154 --pull-libs-dir=*) | 163 --pull-libs-dir=*) |
| 155 PULL_LIBS_DIR=$optarg | 164 PULL_LIBS_DIR=$optarg |
| 156 ;; | 165 ;; |
| 157 --sandboxed) | 166 --sandboxed) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 238 |
| 230 If provided, <package-name> must be the name of the Android application's | 239 If provided, <package-name> must be the name of the Android application's |
| 231 package name to be debugged. You can also use --package-name=<name> to | 240 package name to be debugged. You can also use --package-name=<name> to |
| 232 specify it. | 241 specify it. |
| 233 EOF | 242 EOF |
| 234 fi | 243 fi |
| 235 | 244 |
| 236 cat <<EOF | 245 cat <<EOF |
| 237 | 246 |
| 238 This script is used to debug a running $PROGRAM_NAME process. | 247 This script is used to debug a running $PROGRAM_NAME process. |
| 239 This can be a regular Android application process, or a sandboxed | 248 This can be a regular Android application process, sandboxed (if you use the |
| 240 service, if you use the --sandboxed or --sandboxed=<num> option. | 249 --sandboxed or --sandboxed=<num> option) or a privileged (--privileged or |
| 250 --privileged=<num>) service. |
| 241 | 251 |
| 242 This script needs several things to work properly. It will try to pick | 252 This script needs several things to work properly. It will try to pick |
| 243 them up automatically for you though: | 253 them up automatically for you though: |
| 244 | 254 |
| 245 - target gdbserver binary | 255 - target gdbserver binary |
| 246 - host gdb client (e.g. arm-linux-androideabi-gdb) | 256 - host gdb client (e.g. arm-linux-androideabi-gdb) |
| 247 - directory with symbolic version of $PROGRAM_NAME's shared libraries. | 257 - directory with symbolic version of $PROGRAM_NAME's shared libraries. |
| 248 | 258 |
| 249 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 |
| 250 directory. | 260 directory. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 307 |
| 298 Valid options: | 308 Valid options: |
| 299 --help|-h|-? Print this message. | 309 --help|-h|-? Print this message. |
| 300 --verbose Increase verbosity. | 310 --verbose Increase verbosity. |
| 301 | 311 |
| 302 --sandboxed Debug first sandboxed process we find. | 312 --sandboxed Debug first sandboxed process we find. |
| 303 --sandboxed=<num> Debug specific sandboxed process. | 313 --sandboxed=<num> Debug specific sandboxed process. |
| 304 --symbol-dir=<path> Specify directory with symbol shared libraries. | 314 --symbol-dir=<path> Specify directory with symbol shared libraries. |
| 305 --out-dir=<path> Specify the out directory. | 315 --out-dir=<path> Specify the out directory. |
| 306 --package-name=<name> Specify package name (alternative to 1st argument). | 316 --package-name=<name> Specify package name (alternative to 1st argument). |
| 317 --privileged Debug first privileged process we find. |
| 318 --privileged=<num> Debug specific privileged process. |
| 307 --program-name=<name> Specify program name (cosmetic only). | 319 --program-name=<name> Specify program name (cosmetic only). |
| 308 --pid=<pid> Specify application process pid. | 320 --pid=<pid> Specify application process pid. |
| 309 --force Kill any previous debugging session, if any. | 321 --force Kill any previous debugging session, if any. |
| 310 --start Start package's activity on device. | 322 --start Start package's activity on device. |
| 311 --ui Use gdbtui instead of gdb | 323 --ui Use gdbtui instead of gdb |
| 312 --activity=<name> Activity name for --start [$DEFAULT_ACTIVITY]. | 324 --activity=<name> Activity name for --start [$DEFAULT_ACTIVITY]. |
| 313 --annotate=<num> Enable gdb annotation. | 325 --annotate=<num> Enable gdb annotation. |
| 314 --script=<file> Specify extra GDB init script. | 326 --script=<file> Specify extra GDB init script. |
| 315 | 327 |
| 316 --gdbserver=<file> Specify target gdbserver binary. | 328 --gdbserver=<file> Specify target gdbserver binary. |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 # Get the PID from the first argument or else find the PID of the | 823 # Get the PID from the first argument or else find the PID of the |
| 812 # browser process. | 824 # browser process. |
| 813 if [ -z "$PID" ]; then | 825 if [ -z "$PID" ]; then |
| 814 PROCESSNAME=$PACKAGE_NAME | 826 PROCESSNAME=$PACKAGE_NAME |
| 815 if [ "$SANDBOXED_INDEX" ]; then | 827 if [ "$SANDBOXED_INDEX" ]; then |
| 816 PROCESSNAME=$PROCESSNAME:sandboxed_process$SANDBOXED_INDEX | 828 PROCESSNAME=$PROCESSNAME:sandboxed_process$SANDBOXED_INDEX |
| 817 elif [ "$SANDBOXED" ]; then | 829 elif [ "$SANDBOXED" ]; then |
| 818 PROCESSNAME=$PROCESSNAME:sandboxed_process | 830 PROCESSNAME=$PROCESSNAME:sandboxed_process |
| 819 PID=$(adb_shell ps | \ | 831 PID=$(adb_shell ps | \ |
| 820 awk '$9 ~ /^'$PROCESSNAME'/ { print $2; }' | head -1) | 832 awk '$9 ~ /^'$PROCESSNAME'/ { print $2; }' | head -1) |
| 833 elif [ "$PRIVILEGED_INDEX" ]; then |
| 834 PROCESSNAME=$PROCESSNAME:privileged_process$PRIVILEGED_INDEX |
| 835 elif [ "$PRIVILEGED" ]; then |
| 836 PROCESSNAME=$PROCESSNAME:privileged_process |
| 837 PID=$(adb_shell ps | \ |
| 838 awk '$9 ~ /^'$PROCESSNAME'/ { print $2; }' | head -1) |
| 821 fi | 839 fi |
| 822 if [ -z "$PID" ]; then | 840 if [ -z "$PID" ]; then |
| 823 PID=$(adb_shell ps | \ | 841 PID=$(adb_shell ps | \ |
| 824 awk '$9 == "'$PROCESSNAME'" { print $2; }' | head -1) | 842 awk '$9 == "'$PROCESSNAME'" { print $2; }' | head -1) |
| 825 fi | 843 fi |
| 826 if [ -z "$PID" ]; then | 844 if [ -z "$PID" ]; then |
| 827 if [ "$START" ]; then | 845 if [ "$START" ]; then |
| 828 panic "Can't find application process PID, did it crash?" | 846 panic "Can't find application process PID, did it crash?" |
| 829 else | 847 else |
| 830 panic "Can't find application process PID, are you sure it is \ | 848 panic "Can't find application process PID, are you sure it is \ |
| 831 running? Try using --start." | 849 running? Try using --start." |
| 832 fi | 850 fi |
| 833 fi | 851 fi |
| 834 log "Found process PID: $PID" | 852 log "Found process PID: $PID" |
| 835 elif [ "$SANDBOXED" ]; then | 853 elif [ "$SANDBOXED" ]; then |
| 836 echo "WARNING: --sandboxed option ignored due to use of --pid." | 854 echo "WARNING: --sandboxed option ignored due to use of --pid." |
| 855 elif [ "$PRIVILEGED" ]; then |
| 856 echo "WARNING: --privileged option ignored due to use of --pid." |
| 837 fi | 857 fi |
| 838 | 858 |
| 839 # Determine if 'adb shell' runs as root or not. | 859 # Determine if 'adb shell' runs as root or not. |
| 840 # If so, we can launch gdbserver directly, otherwise, we have to | 860 # If so, we can launch gdbserver directly, otherwise, we have to |
| 841 # use run-as $PACKAGE_NAME ..., which requires the package to be debuggable. | 861 # use run-as $PACKAGE_NAME ..., which requires the package to be debuggable. |
| 842 # | 862 # |
| 843 if [ "$SU_PREFIX" ]; then | 863 if [ "$SU_PREFIX" ]; then |
| 844 # Need to check that this works properly. | 864 # Need to check that this works properly. |
| 845 SU_PREFIX_TEST_LOG=$TMPDIR/su-prefix.log | 865 SU_PREFIX_TEST_LOG=$TMPDIR/su-prefix.log |
| 846 adb_shell $SU_PREFIX \"echo "foo"\" > $SU_PREFIX_TEST_LOG 2>&1 | 866 adb_shell $SU_PREFIX \"echo "foo"\" > $SU_PREFIX_TEST_LOG 2>&1 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 | 1031 |
| 1012 if [ "$VERBOSE" -gt 0 ]; then | 1032 if [ "$VERBOSE" -gt 0 ]; then |
| 1013 echo "### START $COMMANDS" | 1033 echo "### START $COMMANDS" |
| 1014 cat $COMMANDS | 1034 cat $COMMANDS |
| 1015 echo "### END $COMMANDS" | 1035 echo "### END $COMMANDS" |
| 1016 fi | 1036 fi |
| 1017 | 1037 |
| 1018 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS" | 1038 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS" |
| 1019 $GDB $GDB_ARGS -x $COMMANDS && | 1039 $GDB $GDB_ARGS -x $COMMANDS && |
| 1020 rm -f "$GDBSERVER_PIDFILE" | 1040 rm -f "$GDBSERVER_PIDFILE" |
| OLD | NEW |