Resolve gdbclient.py -r executable from target

gdbclient.py -r allows to provide an executable to be run on the target.
Before this patch the absolute path of the executable had to be
provided. This was inconvenient as the user has to first look up for the
exe on the target before debuging it.

With this patch, gdbclient.py will look for the executable on the
target if an absolute path is not provided.

Test: gdbserver -r ls
Change-Id: I610fd0a57b034ba8864874eeb1f7345d4a7daad9
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/scripts/gdbclient.py b/scripts/gdbclient.py
index 2e37e0b..ff593b3 100755
--- a/scripts/gdbclient.py
+++ b/scripts/gdbclient.py
@@ -144,9 +144,15 @@
     elif args.run_cmd:
         if not args.run_cmd[0]:
             sys.exit("empty command passed to -r")
-        if not args.run_cmd[0].startswith("/"):
-            sys.exit("commands passed to -r must use absolute paths")
         run_cmd = args.run_cmd
+        if not run_cmd[0].startswith("/"):
+            try:
+                run_cmd[0] = gdbrunner.find_executable_path(device, args.run_cmd[0],
+                                                            run_as_cmd=args.su_cmd)
+            except RuntimeError:
+              sys.exit("Could not find executable '{}' passed to -r, "
+                       "please provide an absolute path.".format(args.run_cmd[0]))
+
         binary_file, local = gdbrunner.find_file(device, run_cmd[0], sysroot,
                                                  run_as_cmd=args.su_cmd)
     if binary_file is None: