Improve gdbclient pid handling

Improves attaching to multi-process applications, connecting to the root process
if child process not specified instead of passing bad data to gdbserver

Also logs error instead of passing bad data to gdbserver if pid undetermined

Change-Id: I68ad62645c4f0a7a24aef02c84e3b5b84e14461e
This commit is contained in:
Chris Craik 2012-11-09 18:02:19 -08:00
parent 60a34ed501
commit 20c136a151
1 changed files with 18 additions and 7 deletions

View File

@ -776,13 +776,24 @@ function gdbclient()
PORT=":5039"
fi
local PID
local PROG="$3"
if [ "$PROG" ] ; then
if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
PID="$3"
else
local PID="$3"
if [ "$PID" ] ; then
if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
PID=`pid $3`
if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
# that likely didn't work because of returning multiple processes
# try again, filtering by root processes (don't contain colon)
PID=`adb shell ps | grep $3 | grep -v ":" | awk '{print $2}'`
if [[ ! "$PID" =~ ^[0-9]+$ ]]
then
echo "Couldn't resolve '$3' to single PID"
return 1
else
echo ""
echo "WARNING: multiple processes matching '$3' observed, using root process"
echo ""
fi
fi
fi
adb forward "tcp$PORT" "tcp$PORT"
adb shell gdbserver $PORT --attach $PID &
@ -792,7 +803,7 @@ function gdbclient()
echo "If you haven't done so already, do this first on the device:"
echo " gdbserver $PORT /system/bin/$EXE"
echo " or"
echo " gdbserver $PORT --attach $PID"
echo " gdbserver $PORT --attach <PID>"
echo ""
fi