gdb/
[deliverable/binutils-gdb.git] / gdb / remote.c
index c4824e9fe7700f8ffec2118267bb1ee678f48aef..c66618eb42df84efd18b0d9674677f6c93e191d3 100644 (file)
@@ -108,7 +108,7 @@ static void extended_remote_open (char *name, int from_tty);
 
 static void remote_open_1 (char *, int, struct target_ops *, int extended_p);
 
-static void remote_close (int quitting);
+static void remote_close (void);
 
 static void remote_mourn (struct target_ops *ops);
 
@@ -430,8 +430,6 @@ trace_error (char *buf)
       else
        error (_("remote.c: error in outgoing packet at field #%ld."),
               strtol (buf, NULL, 16));
-    case '2':
-      error (_("trace API error 0x%s."), ++buf);
     default:
       error (_("Target returns error code '%s'."), buf);
     }
@@ -3001,7 +2999,7 @@ extended_remote_restart (void)
 /* Clean up connection to a remote debugger.  */
 
 static void
-remote_close (int quitting)
+remote_close (void)
 {
   if (remote_desc == NULL)
     return; /* already closed */
@@ -4188,6 +4186,14 @@ remote_query_supported (void)
       }
 }
 
+/* Remove any of the remote.c targets from target stack.  Upper targets depend
+   on it so remove them first.  */
+
+static void
+remote_unpush_target (void)
+{
+  pop_all_targets_above (process_stratum - 1);
+}
 
 static void
 remote_open_1 (char *name, int from_tty,
@@ -4205,30 +4211,18 @@ remote_open_1 (char *name, int from_tty,
     wait_forever_enabled_p = 1;
 
   /* If we're connected to a running target, target_preopen will kill it.
-     But if we're connected to a target system with no running process,
-     then we will still be connected when it returns.  Ask this question
-     first, before target_preopen has a chance to kill anything.  */
+     Ask this question first, before target_preopen has a chance to kill
+     anything.  */
   if (remote_desc != NULL && !have_inferiors ())
     {
-      if (!from_tty
-         || query (_("Already connected to a remote target.  Disconnect? ")))
-       pop_target ();
-      else
+      if (from_tty
+         && !query (_("Already connected to a remote target.  Disconnect? ")))
        error (_("Still connected."));
     }
 
+  /* Here the possibly existing remote target gets unpushed.  */
   target_preopen (from_tty);
 
-  unpush_target (target);
-
-  /* This time without a query.  If we were connected to an
-     extended-remote target and target_preopen killed the running
-     process, we may still be connected.  If we are starting "target
-     remote" now, the extended-remote target will not have been
-     removed by unpush_target.  */
-  if (remote_desc != NULL && !have_inferiors ())
-    pop_target ();
-
   /* Make sure we send the passed signals list the next time we resume.  */
   xfree (last_pass_packet);
   last_pass_packet = NULL;
@@ -4348,7 +4342,7 @@ remote_open_1 (char *name, int from_tty,
        /* Pop the partially set up target - unless something else did
           already before throwing the exception.  */
        if (remote_desc != NULL)
-         pop_target ();
+         remote_unpush_target ();
        if (target_async_permitted)
          wait_forever_enabled_p = 1;
        throw_exception (ex);
@@ -5096,7 +5090,7 @@ interrupt_query (void)
       if (query (_("Interrupted while waiting for the program.\n\
 Give up (and stop debugging it)? ")))
        {
-         pop_target ();
+         remote_unpush_target ();
          deprecated_throw_reason (RETURN_QUIT);
        }
     }
@@ -7051,13 +7045,14 @@ readchar (int timeout)
   switch ((enum serial_rc) ch)
     {
     case SERIAL_EOF:
-      pop_target ();
-      error (_("Remote connection closed"));
+      remote_unpush_target ();
+      throw_error (TARGET_CLOSE_ERROR, _("Remote connection closed"));
       /* no return */
     case SERIAL_ERROR:
-      pop_target ();
-      perror_with_name (_("Remote communication error.  "
-                         "Target disconnected."));
+      remote_unpush_target ();
+      throw_perror_with_name (TARGET_CLOSE_ERROR,
+                             _("Remote communication error.  "
+                               "Target disconnected."));
       /* no return */
     case SERIAL_TIMEOUT:
       break;
@@ -7579,8 +7574,10 @@ getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever,
              if (forever)      /* Watchdog went off?  Kill the target.  */
                {
                  QUIT;
-                 pop_target ();
-                 error (_("Watchdog timeout has expired.  Target detached."));
+                 remote_unpush_target ();
+                 throw_error (TARGET_CLOSE_ERROR,
+                              _("Watchdog timeout has expired.  "
+                                "Target detached."));
                }
              if (remote_debug)
                fputs_filtered ("Timed out.\n", gdb_stdlog);
@@ -10703,8 +10700,12 @@ remote_get_trace_status (struct trace_status *ts)
     }
   if (ex.reason < 0)
     {
-      exception_fprintf (gdb_stderr, ex, "qTStatus: ");
-      return -1;
+      if (ex.error != TARGET_CLOSE_ERROR)
+       {
+         exception_fprintf (gdb_stderr, ex, "qTStatus: ");
+         return -1;
+       }
+      throw_exception (ex);
     }
 
   /* If the remote target doesn't do tracing, flag it.  */
@@ -11612,7 +11613,7 @@ _initialize_remote (void)
 {
   struct remote_state *rs;
   struct cmd_list_element *cmd;
-  char *cmd_name;
+  const char *cmd_name;
 
   /* architecture specific data */
   remote_gdbarch_data_handle =
This page took 0.029762 seconds and 4 git commands to generate.