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

Side by Side Diff: build/android/adb_gdb

Issue 880853002: Refix of adb gdb su usage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 COMMAND_SUFFIX="\""
852 else 853 else
853 SHELL_UID=$(adb shell cat /proc/self/status | \ 854 SHELL_UID=$(adb shell cat /proc/self/status | \
854 awk '$1 == "Uid:" { print $2; }') 855 awk '$1 == "Uid:" { print $2; }')
855 log "Shell UID: $SHELL_UID" 856 log "Shell UID: $SHELL_UID"
856 if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then 857 if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then
857 COMMAND_PREFIX="run-as $PACKAGE_NAME" 858 COMMAND_PREFIX="run-as $PACKAGE_NAME"
859 COMMAND_SUFFIX=
858 else 860 else
859 COMMAND_PREFIX= 861 COMMAND_PREFIX=
862 COMMAND_SUFFIX=
860 fi 863 fi
861 fi 864 fi
862 log "Command prefix: '$COMMAND_PREFIX'" 865 log "Command prefix: '$COMMAND_PREFIX'"
866 log "Command suffix: '$COMMAND_SUFFIX'"
863 867
864 # Pull device's system libraries that are mapped by our process. 868 # Pull device's system libraries that are mapped by our process.
865 # Pulling all system libraries is too long, so determine which ones 869 # Pulling all system libraries is too long, so determine which ones
866 # we need by looking at /proc/$PID/maps instead 870 # we need by looking at /proc/$PID/maps instead
867 if [ "$PULL_LIBS" -a -z "$NO_PULL_LIBS" ]; then 871 if [ "$PULL_LIBS" -a -z "$NO_PULL_LIBS" ]; then
868 echo "Extracting system libraries into: $PULL_LIBS_DIR" 872 echo "Extracting system libraries into: $PULL_LIBS_DIR"
869 rm -f $PULL_LIBS_DIR/build.prop 873 rm -f $PULL_LIBS_DIR/build.prop
870 MAPPINGS=$(adb_shell $COMMAND_PREFIX \"cat /proc/$PID/maps\") 874 MAPPINGS=$(adb_shell $COMMAND_PREFIX \"cat /proc/$PID/maps\")
875 MAPPINGS=$(adb_shell $COMMAND_PREFIX cat /proc/$PID/maps $COMMAND_SUFFIX)
jbudorick 2015/01/27 14:24:43 Shouldn't this replace the line above?
ripp 2015/01/28 07:01:32 Really should. My fault, don't know how it happene
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 942
938 # Start gdbserver in the background 943 # Start gdbserver in the background
939 # Note that using run-as requires the package to be debuggable. 944 # Note that using run-as requires the package to be debuggable.
940 # 945 #
941 # If not, this will fail horribly. The alternative is to run the 946 # If not, this will fail horribly. The alternative is to run the
942 # program as root, which requires of course root privileges. 947 # program as root, which requires of course root privileges.
943 # Maybe we should add a --root option to enable this? 948 # Maybe we should add a --root option to enable this?
944 # 949 #
945 log "Starting gdbserver in the background:" 950 log "Starting gdbserver in the background:"
946 GDBSERVER_LOG=$TMPDIR/gdbserver-$TMP_ID.log 951 GDBSERVER_LOG=$TMPDIR/gdbserver-$TMP_ID.log
947 log "adb shell $COMMAND_PREFIX \"$TARGET_GDBSERVER :$TARGET_PORT \ 952 log "adb shell $COMMAND_PREFIX $TARGET_GDBSERVER :$TARGET_PORT \
948 --attach $PID"\" 953 --attach $PID $COMMAND_SUFFIX"
949 ("$ADB" shell $COMMAND_PREFIX \"$TARGET_GDBSERVER :$TARGET_PORT \ 954 ("$ADB" shell $COMMAND_PREFIX $TARGET_GDBSERVER :$TARGET_PORT \
950 --attach $PID\" > $GDBSERVER_LOG 2>&1) & 955 --attach $PID $COMMAND_SUFFIX > $GDBSERVER_LOG 2>&1) &
951 GDBSERVER_PID=$! 956 GDBSERVER_PID=$!
952 echo "$GDBSERVER_PID" > $GDBSERVER_PIDFILE 957 echo "$GDBSERVER_PID" > $GDBSERVER_PIDFILE
953 log "background job pid: $GDBSERVER_PID" 958 log "background job pid: $GDBSERVER_PID"
954 959
955 # Check that it is still running after a few seconds. If not, this means we 960 # Check that it is still running after a few seconds. If not, this means we
956 # could not properly attach to it 961 # could not properly attach to it
957 sleep 2 962 sleep 2
958 log "Job control: $(jobs -l)" 963 log "Job control: $(jobs -l)"
959 STATE=$(jobs -l | awk '$2 == "'$GDBSERVER_PID'" { print $3; }') 964 STATE=$(jobs -l | awk '$2 == "'$GDBSERVER_PID'" { print $3; }')
960 if [ "$STATE" != "Running" ]; then 965 if [ "$STATE" != "Running" ]; then
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 1008
1004 if [ "$VERBOSE" -gt 0 ]; then 1009 if [ "$VERBOSE" -gt 0 ]; then
1005 echo "### START $COMMANDS" 1010 echo "### START $COMMANDS"
1006 cat $COMMANDS 1011 cat $COMMANDS
1007 echo "### END $COMMANDS" 1012 echo "### END $COMMANDS"
1008 fi 1013 fi
1009 1014
1010 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS" 1015 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS"
1011 $GDB $GDB_ARGS -x $COMMANDS && 1016 $GDB $GDB_ARGS -x $COMMANDS &&
1012 rm -f "$GDBSERVER_PIDFILE" 1017 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