Commit 20c136a1 authored by Chris Craik's avatar Chris Craik
Browse files

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
parent 60a34ed5
No related merge requests found
...@@ -776,13 +776,24 @@ function gdbclient() ...@@ -776,13 +776,24 @@ function gdbclient()
PORT=":5039" PORT=":5039"
fi fi
local PID local PID="$3"
local PROG="$3" if [ "$PID" ] ; then
if [ "$PROG" ] ; then if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
PID="$3"
else
PID=`pid $3` 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 fi
adb forward "tcp$PORT" "tcp$PORT" adb forward "tcp$PORT" "tcp$PORT"
adb shell gdbserver $PORT --attach $PID & adb shell gdbserver $PORT --attach $PID &
...@@ -792,7 +803,7 @@ function gdbclient() ...@@ -792,7 +803,7 @@ function gdbclient()
echo "If you haven't done so already, do this first on the device:" echo "If you haven't done so already, do this first on the device:"
echo " gdbserver $PORT /system/bin/$EXE" echo " gdbserver $PORT /system/bin/$EXE"
echo " or" echo " or"
echo " gdbserver $PORT --attach $PID" echo " gdbserver $PORT --attach <PID>"
echo "" echo ""
fi fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment