Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1009)

Side by Side Diff: build/android/adb_gdb

Issue 855943002: Fixed running gdb on rooted device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 echo "WARNING: --sandboxed option ignored due to use of --pid." 834 echo "WARNING: --sandboxed option ignored due to use of --pid."
835 fi 835 fi
836 836
837 # Determine if 'adb shell' runs as root or not. 837 # Determine if 'adb shell' runs as root or not.
838 # If so, we can launch gdbserver directly, otherwise, we have to 838 # If so, we can launch gdbserver directly, otherwise, we have to
839 # use run-as $PACKAGE_NAME ..., which requires the package to be debuggable. 839 # use run-as $PACKAGE_NAME ..., which requires the package to be debuggable.
840 # 840 #
841 if [ "$SU_PREFIX" ]; then 841 if [ "$SU_PREFIX" ]; then
842 # Need to check that this works properly. 842 # Need to check that this works properly.
843 SU_PREFIX_TEST_LOG=$TMPDIR/su-prefix.log 843 SU_PREFIX_TEST_LOG=$TMPDIR/su-prefix.log
844 adb_shell $SU_PREFIX echo "foo" > $SU_PREFIX_TEST_LOG 2>&1 844 adb_shell $SU_PREFIX \"echo "foo"\" > $SU_PREFIX_TEST_LOG 2>&1
845 if [ $? != 0 -o "$(cat $SU_PREFIX_TEST_LOG)" != "foo" ]; then 845 if [ $? != 0 -o "$(cat $SU_PREFIX_TEST_LOG)" != "foo" ]; then
846 echo "ERROR: Cannot use '$SU_PREFIX' as a valid su prefix:" 846 echo "ERROR: Cannot use '$SU_PREFIX' as a valid su prefix:"
847 echo "$ adb shell $SU_PREFIX echo foo" 847 echo "$ adb shell $SU_PREFIX echo foo"
848 cat $SU_PREFIX_TEST_LOG 848 cat $SU_PREFIX_TEST_LOG
849 exit 1 849 exit 1
850 fi 850 fi
851 COMMAND_PREFIX="$SU_PREFIX" 851 COMMAND_PREFIX="$SU_PREFIX"
852 else 852 else
853 SHELL_UID=$(adb shell cat /proc/self/status | \ 853 SHELL_UID=$(adb shell cat /proc/self/status | \
854 awk '$1 == "Uid:" { print $2; }') 854 awk '$1 == "Uid:" { print $2; }')
855 log "Shell UID: $SHELL_UID" 855 log "Shell UID: $SHELL_UID"
856 if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then 856 if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then
857 COMMAND_PREFIX="run-as $PACKAGE_NAME" 857 COMMAND_PREFIX="run-as $PACKAGE_NAME"
858 else 858 else
859 COMMAND_PREFIX= 859 COMMAND_PREFIX=
860 fi 860 fi
861 fi 861 fi
862 log "Command prefix: '$COMMAND_PREFIX'" 862 log "Command prefix: '$COMMAND_PREFIX'"
863 863
864 # Pull device's system libraries that are mapped by our process. 864 # Pull device's system libraries that are mapped by our process.
865 # Pulling all system libraries is too long, so determine which ones 865 # Pulling all system libraries is too long, so determine which ones
866 # we need by looking at /proc/$PID/maps instead 866 # we need by looking at /proc/$PID/maps instead
867 if [ "$PULL_LIBS" -a -z "$NO_PULL_LIBS" ]; then 867 if [ "$PULL_LIBS" -a -z "$NO_PULL_LIBS" ]; then
868 echo "Extracting system libraries into: $PULL_LIBS_DIR" 868 echo "Extracting system libraries into: $PULL_LIBS_DIR"
869 rm -f $PULL_LIBS_DIR/build.prop 869 rm -f $PULL_LIBS_DIR/build.prop
870 MAPPINGS=$(adb_shell $COMMAND_PREFIX cat /proc/$PID/maps) 870 MAPPINGS=$(adb_shell $COMMAND_PREFIX \"cat /proc/$PID/maps\")
871 if [ $? != 0 ]; then 871 if [ $? != 0 ]; then
872 echo "ERROR: Could not list process's memory mappings." 872 echo "ERROR: Could not list process's memory mappings."
873 if [ "$SU_PREFIX" ]; then 873 if [ "$SU_PREFIX" ]; then
874 panic "Are you sure your --su-prefix is correct?" 874 panic "Are you sure your --su-prefix is correct?"
875 else 875 else
876 panic "Use --su-prefix if the application is not debuggable." 876 panic "Use --su-prefix if the application is not debuggable."
877 fi 877 fi
878 fi 878 fi
879 SYSTEM_LIBS=$(echo "$MAPPINGS" | \ 879 SYSTEM_LIBS=$(echo "$MAPPINGS" | \
880 awk '$6 ~ /\/system\/.*\.so$/ { print $6; }' | sort -u) 880 awk '$6 ~ /\/system\/.*\.so$/ { print $6; }' | sort -u)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 937
938 # Start gdbserver in the background 938 # Start gdbserver in the background
939 # Note that using run-as requires the package to be debuggable. 939 # Note that using run-as requires the package to be debuggable.
940 # 940 #
941 # If not, this will fail horribly. The alternative is to run the 941 # If not, this will fail horribly. The alternative is to run the
942 # program as root, which requires of course root privileges. 942 # program as root, which requires of course root privileges.
943 # Maybe we should add a --root option to enable this? 943 # Maybe we should add a --root option to enable this?
944 # 944 #
945 log "Starting gdbserver in the background:" 945 log "Starting gdbserver in the background:"
946 GDBSERVER_LOG=$TMPDIR/gdbserver-$TMP_ID.log 946 GDBSERVER_LOG=$TMPDIR/gdbserver-$TMP_ID.log
947 log "adb shell $COMMAND_PREFIX $TARGET_GDBSERVER :$TARGET_PORT \ 947 log "adb shell $COMMAND_PREFIX \"$TARGET_GDBSERVER :$TARGET_PORT \
948 --attach $PID" 948 --attach $PID"\"
949 ("$ADB" shell $COMMAND_PREFIX $TARGET_GDBSERVER :$TARGET_PORT \ 949 ("$ADB" shell $COMMAND_PREFIX \"$TARGET_GDBSERVER :$TARGET_PORT \
950 --attach $PID > $GDBSERVER_LOG 2>&1) & 950 --attach $PID\" > $GDBSERVER_LOG 2>&1) &
951 GDBSERVER_PID=$! 951 GDBSERVER_PID=$!
952 echo "$GDBSERVER_PID" > $GDBSERVER_PIDFILE 952 echo "$GDBSERVER_PID" > $GDBSERVER_PIDFILE
953 log "background job pid: $GDBSERVER_PID" 953 log "background job pid: $GDBSERVER_PID"
954 954
955 # Check that it is still running after a few seconds. If not, this means we 955 # Check that it is still running after a few seconds. If not, this means we
956 # could not properly attach to it 956 # could not properly attach to it
957 sleep 2 957 sleep 2
958 log "Job control: $(jobs -l)" 958 log "Job control: $(jobs -l)"
959 STATE=$(jobs -l | awk '$2 == "'$GDBSERVER_PID'" { print $3; }') 959 STATE=$(jobs -l | awk '$2 == "'$GDBSERVER_PID'" { print $3; }')
960 if [ "$STATE" != "Running" ]; then 960 if [ "$STATE" != "Running" ]; then
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 1003
1004 if [ "$VERBOSE" -gt 0 ]; then 1004 if [ "$VERBOSE" -gt 0 ]; then
1005 echo "### START $COMMANDS" 1005 echo "### START $COMMANDS"
1006 cat $COMMANDS 1006 cat $COMMANDS
1007 echo "### END $COMMANDS" 1007 echo "### END $COMMANDS"
1008 fi 1008 fi
1009 1009
1010 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS" 1010 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS"
1011 $GDB $GDB_ARGS -x $COMMANDS && 1011 $GDB $GDB_ARGS -x $COMMANDS &&
1012 rm -f "$GDBSERVER_PIDFILE" 1012 rm -f "$GDBSERVER_PIDFILE"
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698