gdb_remote: Fix debug symbol check errors

Move debug symbol checks down to after finding remote file path
by pid. This fixes the false complaints about missing debug symbols
when --remote_pid flag is used.

BUG=brillo:474
TEST=Manual tests

Change-Id: I927581d1801f7d018a7f420e8b0ddd104772f1df
Reviewed-on: https://chromium-review.googlesource.com/256733
Reviewed-by: Bertrand Simonnet <bsimonnet@chromium.org>
Commit-Queue: Yiming Chen <yimingc@chromium.org>
Tested-by: Yiming Chen <yimingc@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/host/gdb_remote b/host/gdb_remote
index de5704a..fe2d776 100755
--- a/host/gdb_remote
+++ b/host/gdb_remote
@@ -115,41 +115,6 @@
     die "${CHOST}-gdb does not exist. Please run setup_board."
   fi
 
-  # Verify that the debug version of the remote file exists.
-
-  local local_file="${BOARD_ROOT}${FLAGS_remote_file}"
-  if [[ ! -x "${local_file}" ]]; then
-    echo
-    warn "${local_file} does not exist on your local machine or is not"
-    warn "executable.  You may need to re-run build_packages before attempting to debug."
-    echo
-    read -p "Do you want to stop now? [y/N] " y_or_n
-    case "${y_or_n}" in
-      y|Y) exit 1 ;;
-      *) ;;
-    esac
-  fi
-
-  local local_symbols="${BOARD_ROOT}/usr/lib/debug${FLAGS_remote_file}.debug"
-  local file_info="$(file "${local_file}")"
-  if [[ "${file_info}" != *"not stripped"* && ! -e "${local_symbols}" ]]; then
-    echo
-    local package="$(qfile-${BOARD} -C -q "${FLAGS_remote_file}")"
-    warn "${local_file} is stripped and ${local_symbols} does not exist"
-    warn "on your local machine. The debug symbols for that package may not be"
-    warn "installed."
-    warn "To install the debug symbols for ${package} only, run:"
-    warn " cros_install_debug_syms --board=${BOARD} ${package}"
-    warn "To install the debug symbols for all available packages, run:"
-    warn " cros_install_debug_syms --board=${BOARD} --all"
-    echo
-    read -p "Do you want to stop now? [y/N] " y_or_n
-    case "${y_or_n}" in
-      y|Y) exit 1 ;;
-      *) ;;
-    esac
-  fi
-
   # Verify that the IP Address is currently active.
 
   if [[ -z "${FLAGS_remote}" ]] ; then
@@ -199,6 +164,41 @@
       die "--remote_file must contain full pathname."
     fi
   fi
+
+  # Verify that the debug version of the remote file exists.
+
+  local local_file="${BOARD_ROOT}${FLAGS_remote_file}"
+  if [[ ! -x "${local_file}" ]]; then
+    echo
+    warn "${local_file} does not exist on your local machine or is not"
+    warn "executable.  You may need to re-run build_packages before attempting to debug."
+    echo
+    read -p "Do you want to stop now? [y/N] " y_or_n
+    case "${y_or_n}" in
+      y|Y) exit 1 ;;
+      *) ;;
+    esac
+  fi
+
+  local local_symbols="${BOARD_ROOT}/usr/lib/debug${FLAGS_remote_file}.debug"
+  local file_info="$(file "${local_file}")"
+  if [[ "${file_info}" != *"not stripped"* && ! -e "${local_symbols}" ]]; then
+    echo
+    local package="$(qfile-${BOARD} -C -q "${FLAGS_remote_file}")"
+    warn "${local_file} is stripped and ${local_symbols} does not exist"
+    warn "on your local machine. The debug symbols for that package may not be"
+    warn "installed."
+    warn "To install the debug symbols for ${package} only, run:"
+    warn " cros_install_debug_syms --board=${BOARD} ${package}"
+    warn "To install the debug symbols for all available packages, run:"
+    warn " cros_install_debug_syms --board=${BOARD} --all"
+    echo
+    read -p "Do you want to stop now? [y/N] " y_or_n
+    case "${y_or_n}" in
+      y|Y) exit 1 ;;
+      *) ;;
+    esac
+  fi
 }
 
 setup_remote_iptable ()