gdb: allow gdbclient.py to find local files.

gdbclient.py is always downloading the stripped version of executable
files from the device. This CL first tries to find the unstripped local
file before falling back to the stripped version.

Bug: http://b/24947939
Change-Id: I7a49d0d8b28590ee99ce892d3e3476921f4ae974
diff --git a/scripts/gdbclient.py b/scripts/gdbclient.py
index 9d029ef..2415106 100755
--- a/scripts/gdbclient.py
+++ b/scripts/gdbclient.py
@@ -106,7 +106,7 @@
         device.pull(remote_path, local_path)
 
 
-def handle_switches(args):
+def handle_switches(args, sysroot):
     """Fetch the targeted binary and determine how to attach gdb.
 
     Args:
@@ -135,14 +135,20 @@
         if not args.run_cmd[0].startswith("/"):
             sys.exit("commands passed to -r must use absolute paths")
         run_cmd = args.run_cmd
-        binary_file = gdbrunner.pull_file(device, run_cmd[0], user=args.user)
+        binary_file, local = gdbrunner.find_file(device, run_cmd[0], sysroot,
+                                                 user=args.user)
     if binary_file is None:
         assert pid is not None
         try:
-            binary_file = gdbrunner.pull_binary(device, pid=pid, user=args.user)
+            binary_file, local = gdbrunner.find_binary(device, pid, sysroot,
+                                                       user=args.user)
         except adb.ShellError:
             sys.exit("failed to pull binary for PID {}".format(pid))
 
+    if not local:
+        logging.warning("Couldn't find local unstripped executable in {},"
+                        " symbols may not be available.".format(sysroot))
+
     return (binary_file, pid, run_cmd)
 
 def generate_gdb_script(sysroot, binary_file, is64bit, port, connect_timeout=5):
@@ -216,7 +222,7 @@
     run_cmd = None
 
     # Fetch binary for -p, -n.
-    binary_file, pid, run_cmd = handle_switches(args)
+    binary_file, pid, run_cmd = handle_switches(args, sysroot)
 
     with binary_file:
         arch = gdbrunner.get_binary_arch(binary_file)
@@ -249,6 +255,9 @@
         gdb_path = os.path.join(root, "prebuilts", "gdb", platform_name, "bin",
                                 "gdb")
 
+        # Print a newline to separate our messages from the GDB session.
+        print("")
+
         # Start gdb.
         gdbrunner.start_gdb(gdb_path, gdb_commands)