gdbclient: fix gdbclient <processname> invocation

 - `pid` was being run on the host system and not the target.
 - toybox does not have `pid`, use `pidof` instead.
 - throw an error if more than one pid is matched

Change-Id: I049484013df804e7f0901ec8e4b872bacd839daa
diff --git a/scripts/gdbclient b/scripts/gdbclient
index 8ff9ae9..c2f1363 100755
--- a/scripts/gdbclient
+++ b/scripts/gdbclient
@@ -90,17 +90,20 @@
   fi
 
   # let's figure out which executable we are about to debug
-
   # check if user specified a name -> resolve to pid
   if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
     PROCESS_NAME=$PID
-    PID=$(pid --exact $PROCESS_NAME)
-    if [ -z "$PID" ]; then
+    PIDS=( $(adb shell "pidof $PROCESS_NAME 2> /dev/null" | tr -d '\r\n') )
+    if [[ ${#PIDS[@]} == 0 ]]; then
       echo "Error: couldn't resolve pid by process name: $PROCESS_NAME"
       return -4
-    else
-      echo "Resolved pid for $PROCESS_NAME is $PID"
+    elif [[ ${#PIDS[@]} != 1 ]]; then
+      echo "Error: more than one 1 PID resolved by process name: $PROCESS_NAME"
+      echo "       PIDs -> ${PIDS[@]}"
+      return -5
     fi
+    PID="${PIDS[0]}"
+    echo "Resolved pid for $PROCESS_NAME is [$PID]"
   fi
 
   local EXE=`adb shell readlink /proc/$PID/exe | tr -d '\r\n'`