2008-11-12 Tristan Gingold <gingold@adacore.com>
[binutils-gdb.git] / gdb / remote.c
index da0a429aed09d7f102d984ab3eec33a55334222e..5cb36b8ade2cca9f9a1f3a57c95b5cdb66940116 100644 (file)
@@ -105,11 +105,11 @@ static void remote_close (int quitting);
 
 static void remote_store_registers (struct regcache *regcache, int regno);
 
-static void remote_mourn (void);
+static void remote_mourn (struct target_ops *ops);
 
 static void extended_remote_restart (void);
 
-static void extended_remote_mourn (void);
+static void extended_remote_mourn (struct target_ops *);
 
 static void remote_mourn_1 (struct target_ops *);
 
@@ -133,7 +133,7 @@ static void remote_async (void (*callback) (enum inferior_event_type event_type,
 
 static int remote_async_mask (int new_mask);
 
-static void remote_detach (char *args, int from_tty);
+static void remote_detach (struct target_ops *ops, char *args, int from_tty);
 
 static void remote_interrupt (int signo);
 
@@ -232,6 +232,8 @@ static int peek_stop_reply (ptid_t ptid);
 static void remote_async_inferior_event_handler (gdb_client_data);
 static void remote_async_get_pending_events_handler (gdb_client_data);
 
+static void remote_terminal_ours (void);
+
 /* The non-stop remote protocol provisions for one pending stop reply.
    This is where we keep it until it is acknowledged.  */
 
@@ -1125,13 +1127,6 @@ static ptid_t continue_thread;
 static void
 notice_new_inferiors (ptid_t currthread)
 {
-  /* When connecting to a target remote, or to a target
-     extended-remote which already was debugging an inferior, we may
-     not know about it yet.  Add it before adding its child thread, so
-     notifications are emitted in a sensible order.  */
-  if (!in_inferior_list (ptid_get_pid (currthread)))
-    add_inferior (ptid_get_pid (currthread));
-
   /* If this is a new thread, add it to GDB's thread list.
      If we leave it up to WFI to do this, bad things will happen.  */
 
@@ -1167,6 +1162,13 @@ notice_new_inferiors (ptid_t currthread)
          return;
        }
 
+      /* When connecting to a target remote, or to a target
+        extended-remote which already was debugging an inferior, we
+        may not know about it yet.  Add it before adding its child
+        thread, so notifications are emitted in a sensible order.  */
+      if (!in_inferior_list (ptid_get_pid (currthread)))
+       add_inferior (ptid_get_pid (currthread));
+
       /* This is really a new thread.  Add it.  */
       add_thread (currthread);
     }
@@ -2287,18 +2289,15 @@ extended_remote_restart (void)
 static void
 remote_close (int quitting)
 {
-  if (remote_desc)
-    {
-      /* Unregister the file descriptor from the event loop.  */
-      if (target_is_async_p ())
-       target_async (NULL, 0);
-      serial_close (remote_desc);
-      remote_desc = NULL;
-    }
+  if (remote_desc == NULL)
+    return; /* already closed */
 
-  /* Make sure we don't leave the async SIGINT signal handler
-     installed.  */
-  signal (SIGINT, handle_sigint);
+  /* Make sure we leave stdin registered in the event loop, and we
+     don't leave the async SIGINT signal handler installed.  */
+  remote_terminal_ours ();
+
+  serial_close (remote_desc);
+  remote_desc = NULL;
 
   /* We don't have a connection to the remote stub anymore.  Get rid
      of all the inferiors and their threads we were controlling.  */
@@ -2550,6 +2549,11 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
       getpkt (&rs->buf, &rs->buf_size, 0);
     }
 
+  /* On OSs where the list of libraries is global to all
+     processes, we fetch them early.  */
+  if (gdbarch_has_global_solist (target_gdbarch))
+    solib_add (NULL, args->from_tty, args->target, auto_solib_add);
+
   /* Next, if the target can specify a description, read it.  We do
      this before anything involving memory or registers.  */
   target_find_description ();
@@ -2717,6 +2721,12 @@ remote_start_remote (struct ui_out *uiout, void *opaque)
       if (exec_bfd)    /* No use without an exec file.  */
        remote_check_symbols (symfile_objfile);
     }
+
+  /* If code is shared between processes, then breakpoints are global
+     too; Insert them now.  */
+  if (gdbarch_has_global_solist (target_gdbarch)
+      && breakpoints_always_inserted_mode ())
+    insert_breakpoints ();
 }
 
 /* Open a connection to a remote debugger.
@@ -3296,13 +3306,13 @@ remote_detach_1 (char *args, int from_tty, int extended)
 }
 
 static void
-remote_detach (char *args, int from_tty)
+remote_detach (struct target_ops *ops, char *args, int from_tty)
 {
   remote_detach_1 (args, from_tty, 0);
 }
 
 static void
-extended_remote_detach (char *args, int from_tty)
+extended_remote_detach (struct target_ops *ops, char *args, int from_tty)
 {
   remote_detach_1 (args, from_tty, 1);
 }
@@ -3425,9 +3435,9 @@ extended_remote_attach_1 (struct target_ops *target, char *args, int from_tty)
 }
 
 static void
-extended_remote_attach (char *args, int from_tty)
+extended_remote_attach (struct target_ops *ops, char *args, int from_tty)
 {
-  extended_remote_attach_1 (&extended_remote_ops, args, from_tty);
+  extended_remote_attach_1 (ops, args, from_tty);
 }
 
 /* Convert hex digit A to a number.  */
@@ -6442,9 +6452,9 @@ extended_remote_kill (void)
 }
 
 static void
-remote_mourn (void)
+remote_mourn (struct target_ops *ops)
 {
-  remote_mourn_1 (&remote_ops);
+  remote_mourn_1 (ops);
 }
 
 /* Worker function for remote_mourn.  */
@@ -6527,9 +6537,9 @@ extended_remote_mourn_1 (struct target_ops *target)
 }
 
 static void
-extended_remote_mourn (void)
+extended_remote_mourn (struct target_ops *ops)
 {
-  extended_remote_mourn_1 (&extended_remote_ops);
+  extended_remote_mourn_1 (ops);
 }
 
 static int
@@ -6645,7 +6655,8 @@ extended_remote_create_inferior_1 (char *exec_file, char *args,
 }
 
 static void
-extended_remote_create_inferior (char *exec_file, char *args,
+extended_remote_create_inferior (struct target_ops *ops, 
+                                char *exec_file, char *args,
                                 char **env, int from_tty)
 {
   extended_remote_create_inferior_1 (exec_file, args, env, from_tty);
@@ -8212,12 +8223,6 @@ remote_hostio_error (int errnum)
     error (_("Remote I/O error: %s"), safe_strerror (host_error));
 }
 
-static void
-fclose_cleanup (void *file)
-{
-  fclose (file);
-}
-
 static void
 remote_hostio_close_cleanup (void *opaque)
 {
@@ -8335,7 +8340,7 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty)
   file = fopen (local_file, "rb");
   if (file == NULL)
     perror_with_name (local_file);
-  back_to = make_cleanup (fclose_cleanup, file);
+  back_to = make_cleanup_fclose (file);
 
   fd = remote_hostio_open (remote_file, (FILEIO_O_WRONLY | FILEIO_O_CREAT
                                         | FILEIO_O_TRUNC),
@@ -8425,7 +8430,7 @@ remote_file_get (const char *remote_file, const char *local_file, int from_tty)
   file = fopen (local_file, "wb");
   if (file == NULL)
     perror_with_name (local_file);
-  back_to = make_cleanup (fclose_cleanup, file);
+  back_to = make_cleanup_fclose (file);
 
   /* Send up to this many bytes at once.  They won't all fit in the
      remote packet limit, so we'll transfer slightly fewer.  */
@@ -8554,6 +8559,13 @@ remote_supports_non_stop (void)
   return 1;
 }
 
+static int
+remote_supports_multi_process (void)
+{
+  struct remote_state *rs = get_remote_state ();
+  return remote_multi_process_p (rs);
+}
+
 static void
 init_remote_ops (void)
 {
@@ -8616,6 +8628,7 @@ Specify the serial device it is connected to\n\
   remote_ops.to_terminal_inferior = remote_terminal_inferior;
   remote_ops.to_terminal_ours = remote_terminal_ours;
   remote_ops.to_supports_non_stop = remote_supports_non_stop;
+  remote_ops.to_supports_multi_process = remote_supports_multi_process;
 }
 
 /* Set up the extended remote vector by making a copy of the standard