20000-05-18 H.J. Lu (hjl@gnu.org)
[binutils-gdb.git] / gdb / target.c
index 9ba43fdfd6ccb39c13bf1fe92a2c8db35ffd3596..02ccc25da31b4a3629f44ca0b9d000cc1c0c3e3b 100644 (file)
@@ -1,5 +1,5 @@
 /* Select target systems and architectures at runtime for GDB.
-   Copyright 1990, 1992-1995, 1998, 1999 Free Software Foundation, Inc.
+   Copyright 1990, 1992-1995, 1998-2000 Free Software Foundation, Inc.
    Contributed by Cygnus Support.
 
    This file is part of GDB.
@@ -30,7 +30,7 @@
 #include "bfd.h"
 #include "symfile.h"
 #include "objfiles.h"
-#include "wait.h"
+#include "gdb_wait.h"
 #include <signal.h>
 
 extern int errno;
@@ -78,7 +78,7 @@ static void
 target_command PARAMS ((char *, int));
 
 static struct target_ops *
-  find_default_run_target PARAMS ((char *));
+find_default_run_target PARAMS ((char *));
 
 static void
 update_current_target PARAMS ((void));
@@ -87,10 +87,11 @@ static void nosupport_runtime PARAMS ((void));
 
 static void normal_target_post_startup_inferior PARAMS ((int pid));
 
-/* Transfer LEN bytes between target address MEMADDR and GDB address MYADDR.
-   Returns 0 for success, errno code for failure (which includes partial
-   transfers--if you want a more useful response to partial transfers, try
-   target_read_memory_partial).  */
+/* Transfer LEN bytes between target address MEMADDR and GDB address
+   MYADDR.  Returns 0 for success, errno code for failure (which
+   includes partial transfers -- if you want a more useful response to
+   partial transfers, try either target_read_memory_partial or
+   target_write_memory_partial).  */
 
 static int
 target_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr, int len,
@@ -271,6 +272,12 @@ target_ignore ()
 {
 }
 
+void
+target_load (char *arg, int from_tty)
+{
+  (*current_target.to_load) (arg, from_tty);
+}
+
 /* ARGSUSED */
 static int
 nomemory (memaddr, myaddr, len, write, t)
@@ -390,65 +397,181 @@ cleanup_target (t)
 {
 
 #define de_fault(field, value) \
-  if (!t->field)       t->field = value
-
-  /*        FIELD                       DEFAULT VALUE        */
-
-  de_fault (to_open, (void (*)PARAMS ((char *, int))) tcomplain);
-  de_fault (to_close, (void (*)PARAMS ((int))) target_ignore);
-  de_fault (to_attach, maybe_kill_then_attach);
-  de_fault (to_post_attach, (void (*)PARAMS ((int))) target_ignore);
-  de_fault (to_require_attach, maybe_kill_then_attach);
-  de_fault (to_detach, (void (*)PARAMS ((char *, int))) target_ignore);
-  de_fault (to_require_detach, (void (*)PARAMS ((int, char *, int))) target_ignore);
-  de_fault (to_resume, (void (*)PARAMS ((int, int, enum target_signal))) noprocess);
-  de_fault (to_wait, (int (*)PARAMS ((int, struct target_waitstatus *))) noprocess);
-  de_fault (to_post_wait, (void (*)PARAMS ((int, int))) target_ignore);
-  de_fault (to_fetch_registers, (void (*)PARAMS ((int))) target_ignore);
-  de_fault (to_store_registers, (void (*)PARAMS ((int))) noprocess);
-  de_fault (to_prepare_to_store, (void (*)PARAMS ((void))) noprocess);
-  de_fault (to_xfer_memory, (int (*)PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *))) nomemory);
-  de_fault (to_files_info, (void (*)PARAMS ((struct target_ops *))) target_ignore);
-  de_fault (to_insert_breakpoint, memory_insert_breakpoint);
-  de_fault (to_remove_breakpoint, memory_remove_breakpoint);
-  de_fault (to_terminal_init, (void (*)PARAMS ((void))) target_ignore);
-  de_fault (to_terminal_inferior, (void (*)PARAMS ((void))) target_ignore);
-  de_fault (to_terminal_ours_for_output, (void (*)PARAMS ((void))) target_ignore);
-  de_fault (to_terminal_ours, (void (*)PARAMS ((void))) target_ignore);
-  de_fault (to_terminal_info, default_terminal_info);
-  de_fault (to_kill, (void (*)PARAMS ((void))) noprocess);
-  de_fault (to_load, (void (*)PARAMS ((char *, int))) tcomplain);
-  de_fault (to_lookup_symbol, (int (*)PARAMS ((char *, CORE_ADDR *))) nosymbol);
-  de_fault (to_create_inferior, maybe_kill_then_create_inferior);
-  de_fault (to_post_startup_inferior, (void (*)PARAMS ((int))) target_ignore);
-  de_fault (to_acknowledge_created_inferior, (void (*)PARAMS ((int))) target_ignore);
-  de_fault (to_clone_and_follow_inferior, default_clone_and_follow_inferior);
-  de_fault (to_post_follow_inferior_by_clone, (void (*)PARAMS ((void))) target_ignore);
-  de_fault (to_insert_fork_catchpoint, (int (*)PARAMS ((int))) tcomplain);
-  de_fault (to_remove_fork_catchpoint, (int (*)PARAMS ((int))) tcomplain);
-  de_fault (to_insert_vfork_catchpoint, (int (*)PARAMS ((int))) tcomplain);
-  de_fault (to_remove_vfork_catchpoint, (int (*)PARAMS ((int))) tcomplain);
-  de_fault (to_has_forked, (int (*)PARAMS ((int, int *))) return_zero);
-  de_fault (to_has_vforked, (int (*)PARAMS ((int, int *))) return_zero);
-  de_fault (to_can_follow_vfork_prior_to_exec, (int (*)PARAMS ((void))) return_zero);
-  de_fault (to_post_follow_vfork, (void (*)PARAMS ((int, int, int, int))) target_ignore);
-  de_fault (to_insert_exec_catchpoint, (int (*)PARAMS ((int))) tcomplain);
-  de_fault (to_remove_exec_catchpoint, (int (*)PARAMS ((int))) tcomplain);
-  de_fault (to_has_execd, (int (*)PARAMS ((int, char **))) return_zero);
-  de_fault (to_reported_exec_events_per_exec_call, (int (*)PARAMS ((void))) return_one);
-  de_fault (to_has_syscall_event, (int (*)PARAMS ((int, enum target_waitkind *, int *))) return_zero);
-  de_fault (to_has_exited, (int (*)PARAMS ((int, int, int *))) return_zero);
-  de_fault (to_mourn_inferior, (void (*)PARAMS ((void))) noprocess);
-  de_fault (to_can_run, return_zero);
-  de_fault (to_notice_signals, (void (*)PARAMS ((int))) target_ignore);
-  de_fault (to_thread_alive, (int (*)PARAMS ((int))) target_ignore);
-  de_fault (to_stop, (void (*)PARAMS ((void))) target_ignore);
-  de_fault (to_query, (int (*)PARAMS ((int /*char */ , char *, char *, int *))) target_ignore);
-  de_fault (to_enable_exception_callback, (struct symtab_and_line * (*)PARAMS ((enum exception_event_kind, int))) nosupport_runtime);
-  de_fault (to_get_current_exception_event, (struct exception_event_record * (*)PARAMS ((void))) nosupport_runtime);
-
-  de_fault (to_pid_to_exec_file, (char *(*)PARAMS ((int))) return_zero);
-  de_fault (to_core_file_to_sym_file, (char *(*)PARAMS ((char *))) return_zero);
+  if (!t->field)               \
+    t->field = value
+
+  de_fault (to_open, 
+           (void (*) (char *, int)) 
+           tcomplain);
+  de_fault (to_close, 
+           (void (*) (int)) 
+           target_ignore);
+  de_fault (to_attach, 
+           maybe_kill_then_attach);
+  de_fault (to_post_attach, 
+           (void (*) (int)) 
+           target_ignore);
+  de_fault (to_require_attach, 
+           maybe_kill_then_attach);
+  de_fault (to_detach, 
+           (void (*) (char *, int)) 
+           target_ignore);
+  de_fault (to_require_detach, 
+           (void (*) (int, char *, int)) 
+           target_ignore);
+  de_fault (to_resume, 
+           (void (*) (int, int, enum target_signal)) 
+           noprocess);
+  de_fault (to_wait, 
+           (int (*) (int, struct target_waitstatus *)) 
+           noprocess);
+  de_fault (to_post_wait, 
+           (void (*) (int, int)) 
+           target_ignore);
+  de_fault (to_fetch_registers, 
+           (void (*) (int)) 
+           target_ignore);
+  de_fault (to_store_registers, 
+           (void (*) (int)) 
+           noprocess);
+  de_fault (to_prepare_to_store, 
+           (void (*) (void)) 
+           noprocess);
+  de_fault (to_xfer_memory, 
+           (int (*) (CORE_ADDR, char *, int, int, struct target_ops *)) 
+           nomemory);
+  de_fault (to_files_info, 
+           (void (*) (struct target_ops *)) 
+           target_ignore);
+  de_fault (to_insert_breakpoint, 
+           memory_insert_breakpoint);
+  de_fault (to_remove_breakpoint, 
+           memory_remove_breakpoint);
+  de_fault (to_terminal_init, 
+           (void (*) (void)) 
+           target_ignore);
+  de_fault (to_terminal_inferior, 
+           (void (*) (void)) 
+           target_ignore);
+  de_fault (to_terminal_ours_for_output, 
+           (void (*) (void)) 
+           target_ignore);
+  de_fault (to_terminal_ours, 
+           (void (*) (void)) 
+           target_ignore);
+  de_fault (to_terminal_info, 
+           default_terminal_info);
+  de_fault (to_kill, 
+           (void (*) (void)) 
+           noprocess);
+  de_fault (to_load, 
+           (void (*) (char *, int)) 
+           tcomplain);
+  de_fault (to_lookup_symbol, 
+           (int (*) (char *, CORE_ADDR *)) 
+           nosymbol);
+  de_fault (to_create_inferior, 
+           maybe_kill_then_create_inferior);
+  de_fault (to_post_startup_inferior, 
+           (void (*) (int)) 
+           target_ignore);
+  de_fault (to_acknowledge_created_inferior, 
+           (void (*) (int)) 
+           target_ignore);
+  de_fault (to_clone_and_follow_inferior, 
+           default_clone_and_follow_inferior);
+  de_fault (to_post_follow_inferior_by_clone, 
+           (void (*) (void)) 
+           target_ignore);
+  de_fault (to_insert_fork_catchpoint, 
+           (int (*) (int)) 
+           tcomplain);
+  de_fault (to_remove_fork_catchpoint, 
+           (int (*) (int)) 
+           tcomplain);
+  de_fault (to_insert_vfork_catchpoint, 
+           (int (*) (int)) 
+           tcomplain);
+  de_fault (to_remove_vfork_catchpoint, 
+           (int (*) (int)) 
+           tcomplain);
+  de_fault (to_has_forked, 
+           (int (*) (int, int *)) 
+           return_zero);
+  de_fault (to_has_vforked, 
+           (int (*) (int, int *)) 
+           return_zero);
+  de_fault (to_can_follow_vfork_prior_to_exec, 
+           (int (*) (void)) 
+           return_zero);
+  de_fault (to_post_follow_vfork, 
+           (void (*) (int, int, int, int)) 
+           target_ignore);
+  de_fault (to_insert_exec_catchpoint, 
+           (int (*) (int)) 
+           tcomplain);
+  de_fault (to_remove_exec_catchpoint, 
+           (int (*) (int)) 
+           tcomplain);
+  de_fault (to_has_execd, 
+           (int (*) (int, char **)) 
+           return_zero);
+  de_fault (to_reported_exec_events_per_exec_call, 
+           (int (*) (void)) 
+           return_one);
+  de_fault (to_has_syscall_event, 
+           (int (*) (int, enum target_waitkind *, int *)) 
+           return_zero);
+  de_fault (to_has_exited, 
+           (int (*) (int, int, int *)) 
+           return_zero);
+  de_fault (to_mourn_inferior, 
+           (void (*) (void)) 
+           noprocess);
+  de_fault (to_can_run, 
+           return_zero);
+  de_fault (to_notice_signals, 
+           (void (*) (int)) 
+           target_ignore);
+  de_fault (to_thread_alive, 
+           (int (*) (int)) 
+           return_zero);
+  de_fault (to_find_new_threads, 
+           (void (*) (void)) 
+           target_ignore);
+  de_fault (to_extra_thread_info, 
+           (char *(*) (struct thread_info *)) 
+           return_zero);
+  de_fault (to_stop, 
+           (void (*) (void)) 
+           target_ignore);
+  de_fault (to_query, 
+           (int (*) (int, char *, char *, int *)) 
+           return_zero);
+  de_fault (to_rcmd, 
+           (void (*) (char *, struct ui_file *)) 
+           tcomplain);
+  de_fault (to_enable_exception_callback, 
+           (struct symtab_and_line * (*) (enum exception_event_kind, int)) 
+           nosupport_runtime);
+  de_fault (to_get_current_exception_event, 
+           (struct exception_event_record * (*) (void)) 
+           nosupport_runtime);
+  de_fault (to_pid_to_exec_file, 
+           (char *(*) (int)) 
+           return_zero);
+  de_fault (to_core_file_to_sym_file, 
+           (char *(*) (char *)) 
+           return_zero);
+  de_fault (to_can_async_p, 
+           (int (*) (void)) 
+           return_zero);
+  de_fault (to_is_async_p, 
+           (int (*) (void)) 
+           return_zero);
+  de_fault (to_async, 
+           (void (*) (void (*) (enum inferior_event_type, void*), void*)) 
+           tcomplain);
 #undef de_fault
 }
 
@@ -525,8 +648,11 @@ update_current_target ()
       INHERIT (to_notice_signals, t);
       INHERIT (to_thread_alive, t);
       INHERIT (to_find_new_threads, t);
+      INHERIT (to_pid_to_str, t);
+      INHERIT (to_extra_thread_info, t);
       INHERIT (to_stop, t);
       INHERIT (to_query, t);
+      INHERIT (to_rcmd, t);
       INHERIT (to_enable_exception_callback, t);
       INHERIT (to_get_current_exception_event, t);
       INHERIT (to_pid_to_exec_file, t);
@@ -539,9 +665,12 @@ update_current_target ()
       INHERIT (to_has_registers, t);
       INHERIT (to_has_execution, t);
       INHERIT (to_has_thread_control, t);
-      INHERIT (to_has_async_exec, t);
       INHERIT (to_sections, t);
       INHERIT (to_sections_end, t);
+      INHERIT (to_can_async_p, t);
+      INHERIT (to_is_async_p, t);
+      INHERIT (to_async, t);
+      INHERIT (to_async_mask_value, t);
       INHERIT (to_magic, t);
 
 #undef INHERIT
@@ -780,48 +909,6 @@ target_read_memory_section (memaddr, myaddr, len, bfd_section)
   return target_xfer_memory (memaddr, myaddr, len, 0, bfd_section);
 }
 
-/* Read LEN bytes of target memory at address MEMADDR, placing the results
-   in GDB's memory at MYADDR.  Returns a count of the bytes actually read,
-   and optionally an errno value in the location pointed to by ERRNOPTR
-   if ERRNOPTR is non-null. */
-
-int
-target_read_memory_partial (memaddr, myaddr, len, errnoptr)
-     CORE_ADDR memaddr;
-     char *myaddr;
-     int len;
-     int *errnoptr;
-{
-  int nread;                   /* Number of bytes actually read. */
-  int errcode;                 /* Error from last read. */
-
-  /* First try a complete read. */
-  errcode = target_xfer_memory (memaddr, myaddr, len, 0, NULL);
-  if (errcode == 0)
-    {
-      /* Got it all. */
-      nread = len;
-    }
-  else
-    {
-      /* Loop, reading one byte at a time until we get as much as we can. */
-      for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--)
-       {
-         errcode = target_xfer_memory (memaddr++, myaddr++, 1, 0, NULL);
-       }
-      /* If an error, the last read was unsuccessful, so adjust count. */
-      if (errcode != 0)
-       {
-         nread--;
-       }
-    }
-  if (errnoptr != NULL)
-    {
-      *errnoptr = errcode;
-    }
-  return (nread);
-}
-
 int
 target_write_memory (memaddr, myaddr, len)
      CORE_ADDR memaddr;
@@ -916,6 +1003,75 @@ target_xfer_memory (memaddr, myaddr, len, write, bfd_section)
 }
 
 
+/* Perform a partial memory transfer.  */
+
+static int
+target_xfer_memory_partial (CORE_ADDR memaddr, char *buf, int len,
+                           int write_p, int *err)
+{
+  int res;
+  int err_res;
+  int len_res;
+  struct target_ops *t;
+  struct target_stack_item *item;
+
+  /* Zero length requests are ok and require no work.  */
+  if (len == 0)
+    {
+      *err = 0;
+      return 0;
+    }
+
+  /* The quick case is that the top target does it all.  */
+  res = current_target.to_xfer_memory (memaddr, buf, len, write_p, &current_target);
+  if (res > 0)
+    {
+      *err = 0;
+      return res;
+    }
+
+  /* xfer memory doesn't always reliably set errno. */
+  errno = 0;
+
+  /* Try all levels of the target stack to see one can handle it. */
+  for (item = target_stack; item; item = item->next)
+    {
+      t = item->target_ops;
+      if (!t->to_has_memory)
+       continue;
+      res = t->to_xfer_memory (memaddr, buf, len, write_p, t);
+      if (res > 0)
+       {
+         /* Handled all or part of xfer */
+         *err = 0;
+         return res;
+       }
+      if (t->to_has_all_memory)
+       break;
+    }
+
+  /* Total failure.  Return error. */
+  if (errno != 0)
+    {
+      *err = errno;
+      return -1;
+    }
+  *err = EIO;
+  return -1;
+}
+
+int
+target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
+{
+  return target_xfer_memory_partial (memaddr, buf, len, 0, err);
+}
+
+int
+target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
+{
+  return target_xfer_memory_partial (memaddr, buf, len, 1, err);
+}
+
 /* ARGSUSED */
 static void
 target_info (args, from_tty)
@@ -962,7 +1118,8 @@ target_preopen (from_tty)
 
   if (target_has_execution)
     {
-      if (query ("A program is being debugged already.  Kill it? "))
+      if (!from_tty
+          || query ("A program is being debugged already.  Kill it? "))
        target_kill ();
       else
        error ("Program not killed.");
@@ -1001,7 +1158,15 @@ target_link (modname, t_reloc)
        error ("Unable to link to %s and get relocation in rombug", modname);
     }
   else
-    *t_reloc = (CORE_ADDR) - 1;
+    *t_reloc = (CORE_ADDR) -1;
+}
+
+int
+target_async_mask (int mask)
+{
+  int saved_async_masked_status = target_async_mask_value;
+  target_async_mask_value = mask;
+  return saved_async_masked_status;
 }
 
 /* Look through the list of possible targets for a target that can
@@ -1110,6 +1275,89 @@ return_one ()
   return 1;
 }
 
+/*
+ * Resize the to_sections pointer.  Also make sure that anyone that
+ * was holding on to an old value of it gets updated.
+ * Returns the old size.
+ */
+
+int
+target_resize_to_sections (struct target_ops *target, int num_added)
+{
+  struct target_ops **t;
+  struct section_table *old_value;
+  int old_count;
+
+  old_value = target->to_sections;
+
+  if (target->to_sections)
+    {
+      old_count = target->to_sections_end - target->to_sections;
+      target->to_sections = (struct section_table *)
+       xrealloc ((char *) target->to_sections,
+                 (sizeof (struct section_table)) * (num_added + old_count));
+    }
+  else
+    {
+      old_count = 0;
+      target->to_sections = (struct section_table *)
+       xmalloc ((sizeof (struct section_table)) * num_added);
+    }
+  target->to_sections_end = target->to_sections + (num_added + old_count);
+
+  /* Check to see if anyone else was pointing to this structure.
+     If old_value was null, then no one was. */
+     
+  if (old_value)
+    {
+      for (t = target_structs; t < target_structs + target_struct_size;
+          ++t)
+       {
+         if ((*t)->to_sections == old_value)
+           {
+             (*t)->to_sections = target->to_sections;
+             (*t)->to_sections_end = target->to_sections_end;
+           }
+       }
+    }
+  
+  return old_count;
+
+}
+
+/* Remove all target sections taken from ABFD.
+
+   Scan the current target stack for targets whose section tables
+   refer to sections from BFD, and remove those sections.  We use this
+   when we notice that the inferior has unloaded a shared object, for
+   example.  */
+void
+remove_target_sections (bfd *abfd)
+{
+  struct target_ops **t;
+
+  for (t = target_structs; t < target_structs + target_struct_size; t++)
+    {
+      struct section_table *src, *dest;
+
+      dest = (*t)->to_sections;
+      for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++)
+       if (src->bfd != abfd)
+         {
+           /* Keep this section.  */
+           if (dest < src) *dest = *src;
+           dest++;
+         }
+
+      /* If we've dropped any sections, resize the section table.  */
+      if (dest < src)
+       target_resize_to_sections (*t, dest - src);
+    }
+}
+
+
+
+
 /* Find a single runnable target in the stack and return it.  If for
    some reason there is more than one, return NULL.  */
 
@@ -1134,6 +1382,9 @@ find_run_target ()
   return (count == 1 ? runable : NULL);
 }
 
+/* Find a single core_stratum target in the list of targets and return it.
+   If for some reason there is more than one, return NULL.  */
+
 struct target_ops *
 find_core_target ()
 {
@@ -1155,6 +1406,27 @@ find_core_target ()
 
   return (count == 1 ? runable : NULL);
 }
+
+/*
+ * Find the next target down the stack from the specified target.
+ */
+
+struct target_ops *
+find_target_beneath (t)
+     struct target_ops *t;
+{
+  struct target_stack_item *cur;
+
+  for (cur = target_stack; cur; cur = cur->next)
+    if (cur->target_ops == t)
+      break;
+
+  if (cur == NULL || cur->next == NULL)
+    return NULL;
+  else
+    return cur->next->target_ops;
+}
+
 \f
 /* The inferior process has died.  Long live the inferior!  */
 
@@ -1269,6 +1541,7 @@ static struct {
   {"SIG62", "Real-time event 62"},
   {"SIG63", "Real-time event 63"},
   {"SIGCANCEL", "LWP internal signal"},
+  {"SIG32", "Real-time event 32"},
 
 #if defined(MACH) || defined(__MACH__)
   /* Mach exceptions */
@@ -1568,16 +1841,30 @@ target_signal_from_host (hostsig)
 
 #if defined (REALTIME_LO)
   if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI)
-    return (enum target_signal)
-      (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33);
+    {
+      /* This block of TARGET_SIGNAL_REALTIME value is in order.  */
+      if (33 <= hostsig && hostsig <= 63)
+       return (enum target_signal)
+         (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33);
+      else if (hostsig == 32)
+       return TARGET_SIGNAL_REALTIME_32;
+      else
+       error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
+    }
 #endif
   return TARGET_SIGNAL_UNKNOWN;
 }
 
-int
-target_signal_to_host (oursig)
-     enum target_signal oursig;
+/* Convert a OURSIG (an enum target_signal) to the form used by the
+   target operating system (refered to as the ``host'') or zero if the
+   equivalent host signal is not available.  Set/clear OURSIG_OK
+   accordingly. */
+
+static int
+do_target_signal_to_host (enum target_signal oursig,
+                         int *oursig_ok)
 {
+  *oursig_ok = 1;
   switch (oursig)
     {
     case TARGET_SIGNAL_0:
@@ -1804,18 +2091,50 @@ target_signal_to_host (oursig)
       if (oursig >= TARGET_SIGNAL_REALTIME_33
          && oursig <= TARGET_SIGNAL_REALTIME_63)
        {
+         /* This block of signals is continuous, and
+             TARGET_SIGNAL_REALTIME_33 is 33 by definition.  */
          int retsig =
-         (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + REALTIME_LO;
-         if (retsig < REALTIME_HI)
+           (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + 33;
+         if (retsig >= REALTIME_LO && retsig < REALTIME_HI)
            return retsig;
        }
+#if (REALTIME_LO < 33)
+      else if (oursig == TARGET_SIGNAL_REALTIME_32)
+       {
+         /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with
+             TARGET_SIGNAL_REALTIME_33.  It is 32 by definition.  */
+         return 32;
+       }
 #endif
+#endif
+      *oursig_ok = 0;
+      return 0;
+    }
+}
+
+int
+target_signal_to_host_p (enum target_signal oursig)
+{
+  int oursig_ok;
+  do_target_signal_to_host (oursig, &oursig_ok);
+  return oursig_ok;
+}
+
+int
+target_signal_to_host (enum target_signal oursig)
+{
+  int oursig_ok;
+  int targ_signo = do_target_signal_to_host (oursig, &oursig_ok);
+  if (!oursig_ok)
+    {
       /* The user might be trying to do "signal SIGSAK" where this system
          doesn't have SIGSAK.  */
       warning ("Signal %s does not exist on this system.\n",
               target_signal_to_name (oursig));
       return 0;
     }
+  else
+    return targ_signo;
 }
 
 /* Helper function for child_wait and the Lynx derivatives of child_wait.
@@ -1882,9 +2201,9 @@ normal_pid_to_str (pid)
   static char buf[30];
 
   if (STREQ (current_target.to_shortname, "remote"))
-    sprintf (buf, "thread %d\0", pid);
+    sprintf (buf, "thread %d", pid);
   else
-    sprintf (buf, "process %d\0", pid);
+    sprintf (buf, "process %d", pid);
 
   return buf;
 }
@@ -1922,6 +2241,7 @@ init_dummy_target ()
   dummy_target.to_require_detach = find_default_require_detach;
   dummy_target.to_create_inferior = find_default_create_inferior;
   dummy_target.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
+  dummy_target.to_pid_to_str = normal_pid_to_str;
   dummy_target.to_stratum = dummy_stratum;
   dummy_target.to_magic = OPS_MAGIC;
 }
@@ -1936,7 +2256,7 @@ debug_to_open (args, from_tty)
 {
   debug_target.to_open (args, from_tty);
 
-  fprintf_unfiltered (gdb_stderr, "target_open (%s, %d)\n", args, from_tty);
+  fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
 }
 
 static void
@@ -1945,7 +2265,7 @@ debug_to_close (quitting)
 {
   debug_target.to_close (quitting);
 
-  fprintf_unfiltered (gdb_stderr, "target_close (%d)\n", quitting);
+  fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting);
 }
 
 static void
@@ -1955,7 +2275,7 @@ debug_to_attach (args, from_tty)
 {
   debug_target.to_attach (args, from_tty);
 
-  fprintf_unfiltered (gdb_stderr, "target_attach (%s, %d)\n", args, from_tty);
+  fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty);
 }
 
 
@@ -1965,7 +2285,7 @@ debug_to_post_attach (pid)
 {
   debug_target.to_post_attach (pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_post_attach (%d)\n", pid);
+  fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
 }
 
 static void
@@ -1975,7 +2295,7 @@ debug_to_require_attach (args, from_tty)
 {
   debug_target.to_require_attach (args, from_tty);
 
-  fprintf_unfiltered (gdb_stderr,
+  fprintf_unfiltered (gdb_stdlog,
                      "target_require_attach (%s, %d)\n", args, from_tty);
 }
 
@@ -1986,7 +2306,7 @@ debug_to_detach (args, from_tty)
 {
   debug_target.to_detach (args, from_tty);
 
-  fprintf_unfiltered (gdb_stderr, "target_detach (%s, %d)\n", args, from_tty);
+  fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty);
 }
 
 static void
@@ -1997,7 +2317,7 @@ debug_to_require_detach (pid, args, from_tty)
 {
   debug_target.to_require_detach (pid, args, from_tty);
 
-  fprintf_unfiltered (gdb_stderr,
+  fprintf_unfiltered (gdb_stdlog,
               "target_require_detach (%d, %s, %d)\n", pid, args, from_tty);
 }
 
@@ -2009,7 +2329,7 @@ debug_to_resume (pid, step, siggnal)
 {
   debug_target.to_resume (pid, step, siggnal);
 
-  fprintf_unfiltered (gdb_stderr, "target_resume (%d, %s, %s)\n", pid,
+  fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", pid,
                      step ? "step" : "continue",
                      target_signal_to_name (siggnal));
 }
@@ -2023,40 +2343,40 @@ debug_to_wait (pid, status)
 
   retval = debug_target.to_wait (pid, status);
 
-  fprintf_unfiltered (gdb_stderr,
+  fprintf_unfiltered (gdb_stdlog,
                      "target_wait (%d, status) = %d,   ", pid, retval);
-  fprintf_unfiltered (gdb_stderr, "status->kind = ");
+  fprintf_unfiltered (gdb_stdlog, "status->kind = ");
   switch (status->kind)
     {
     case TARGET_WAITKIND_EXITED:
-      fprintf_unfiltered (gdb_stderr, "exited, status = %d\n",
+      fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n",
                          status->value.integer);
       break;
     case TARGET_WAITKIND_STOPPED:
-      fprintf_unfiltered (gdb_stderr, "stopped, signal = %s\n",
+      fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n",
                          target_signal_to_name (status->value.sig));
       break;
     case TARGET_WAITKIND_SIGNALLED:
-      fprintf_unfiltered (gdb_stderr, "signalled, signal = %s\n",
+      fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n",
                          target_signal_to_name (status->value.sig));
       break;
     case TARGET_WAITKIND_LOADED:
-      fprintf_unfiltered (gdb_stderr, "loaded\n");
+      fprintf_unfiltered (gdb_stdlog, "loaded\n");
       break;
     case TARGET_WAITKIND_FORKED:
-      fprintf_unfiltered (gdb_stderr, "forked\n");
+      fprintf_unfiltered (gdb_stdlog, "forked\n");
       break;
     case TARGET_WAITKIND_VFORKED:
-      fprintf_unfiltered (gdb_stderr, "vforked\n");
+      fprintf_unfiltered (gdb_stdlog, "vforked\n");
       break;
     case TARGET_WAITKIND_EXECD:
-      fprintf_unfiltered (gdb_stderr, "execd\n");
+      fprintf_unfiltered (gdb_stdlog, "execd\n");
       break;
     case TARGET_WAITKIND_SPURIOUS:
-      fprintf_unfiltered (gdb_stderr, "spurious\n");
+      fprintf_unfiltered (gdb_stdlog, "spurious\n");
       break;
     default:
-      fprintf_unfiltered (gdb_stderr, "unknown???\n");
+      fprintf_unfiltered (gdb_stdlog, "unknown???\n");
       break;
     }
 
@@ -2070,7 +2390,7 @@ debug_to_post_wait (pid, status)
 {
   debug_target.to_post_wait (pid, status);
 
-  fprintf_unfiltered (gdb_stderr, "target_post_wait (%d, %d)\n",
+  fprintf_unfiltered (gdb_stdlog, "target_post_wait (%d, %d)\n",
                      pid, status);
 }
 
@@ -2080,13 +2400,13 @@ debug_to_fetch_registers (regno)
 {
   debug_target.to_fetch_registers (regno);
 
-  fprintf_unfiltered (gdb_stderr, "target_fetch_registers (%s)",
+  fprintf_unfiltered (gdb_stdlog, "target_fetch_registers (%s)",
                      regno != -1 ? REGISTER_NAME (regno) : "-1");
   if (regno != -1)
-    fprintf_unfiltered (gdb_stderr, " = 0x%x %d",
+    fprintf_unfiltered (gdb_stdlog, " = 0x%lx %ld",
                        (unsigned long) read_register (regno),
-                       read_register (regno));
-  fprintf_unfiltered (gdb_stderr, "\n");
+                       (unsigned long) read_register (regno));
+  fprintf_unfiltered (gdb_stdlog, "\n");
 }
 
 static void
@@ -2096,12 +2416,12 @@ debug_to_store_registers (regno)
   debug_target.to_store_registers (regno);
 
   if (regno >= 0 && regno < NUM_REGS)
-    fprintf_unfiltered (gdb_stderr, "target_store_registers (%s) = 0x%x %d\n",
+    fprintf_unfiltered (gdb_stdlog, "target_store_registers (%s) = 0x%lx %ld\n",
                        REGISTER_NAME (regno),
                        (unsigned long) read_register (regno),
                        (unsigned long) read_register (regno));
   else
-    fprintf_unfiltered (gdb_stderr, "target_store_registers (%d)\n", regno);
+    fprintf_unfiltered (gdb_stdlog, "target_store_registers (%d)\n", regno);
 }
 
 static void
@@ -2109,7 +2429,7 @@ debug_to_prepare_to_store ()
 {
   debug_target.to_prepare_to_store ();
 
-  fprintf_unfiltered (gdb_stderr, "target_prepare_to_store ()\n");
+  fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
 }
 
 static int
@@ -2124,7 +2444,7 @@ debug_to_xfer_memory (memaddr, myaddr, len, write, target)
 
   retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write, target);
 
-  fprintf_unfiltered (gdb_stderr,
+  fprintf_unfiltered (gdb_stdlog,
                      "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
                      (unsigned int) memaddr,   /* possable truncate long long */
                      len, write ? "write" : "read", retval);
@@ -2135,16 +2455,16 @@ debug_to_xfer_memory (memaddr, myaddr, len, write, target)
     {
       int i;
 
-      fputs_unfiltered (", bytes =", gdb_stderr);
+      fputs_unfiltered (", bytes =", gdb_stdlog);
       for (i = 0; i < retval; i++)
        {
          if ((((long) &(myaddr[i])) & 0xf) == 0)
-           fprintf_unfiltered (gdb_stderr, "\n");
-         fprintf_unfiltered (gdb_stderr, " %02x", myaddr[i] & 0xff);
+           fprintf_unfiltered (gdb_stdlog, "\n");
+         fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
        }
     }
 
-  fputc_unfiltered ('\n', gdb_stderr);
+  fputc_unfiltered ('\n', gdb_stdlog);
 
   return retval;
 }
@@ -2155,7 +2475,7 @@ debug_to_files_info (target)
 {
   debug_target.to_files_info (target);
 
-  fprintf_unfiltered (gdb_stderr, "target_files_info (xxx)\n");
+  fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n");
 }
 
 static int
@@ -2167,9 +2487,10 @@ debug_to_insert_breakpoint (addr, save)
 
   retval = debug_target.to_insert_breakpoint (addr, save);
 
-  fprintf_unfiltered (gdb_stderr,
-                     "target_insert_breakpoint (0x%x, xxx) = %d\n",
-                     (unsigned long) addr, retval);
+  fprintf_unfiltered (gdb_stdlog,
+                     "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
+                     (unsigned long) addr,
+                     (unsigned long) retval);
   return retval;
 }
 
@@ -2182,9 +2503,10 @@ debug_to_remove_breakpoint (addr, save)
 
   retval = debug_target.to_remove_breakpoint (addr, save);
 
-  fprintf_unfiltered (gdb_stderr,
-                     "target_remove_breakpoint (0x%x, xxx) = %d\n",
-                     (unsigned long) addr, retval);
+  fprintf_unfiltered (gdb_stdlog,
+                     "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
+                     (unsigned long) addr,
+                     (unsigned long) retval);
   return retval;
 }
 
@@ -2193,7 +2515,7 @@ debug_to_terminal_init ()
 {
   debug_target.to_terminal_init ();
 
-  fprintf_unfiltered (gdb_stderr, "target_terminal_init ()\n");
+  fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n");
 }
 
 static void
@@ -2201,7 +2523,7 @@ debug_to_terminal_inferior ()
 {
   debug_target.to_terminal_inferior ();
 
-  fprintf_unfiltered (gdb_stderr, "target_terminal_inferior ()\n");
+  fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n");
 }
 
 static void
@@ -2209,7 +2531,7 @@ debug_to_terminal_ours_for_output ()
 {
   debug_target.to_terminal_ours_for_output ();
 
-  fprintf_unfiltered (gdb_stderr, "target_terminal_ours_for_output ()\n");
+  fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n");
 }
 
 static void
@@ -2217,7 +2539,7 @@ debug_to_terminal_ours ()
 {
   debug_target.to_terminal_ours ();
 
-  fprintf_unfiltered (gdb_stderr, "target_terminal_ours ()\n");
+  fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
 }
 
 static void
@@ -2227,7 +2549,7 @@ debug_to_terminal_info (arg, from_tty)
 {
   debug_target.to_terminal_info (arg, from_tty);
 
-  fprintf_unfiltered (gdb_stderr, "target_terminal_info (%s, %d)\n", arg,
+  fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg,
                      from_tty);
 }
 
@@ -2236,7 +2558,7 @@ debug_to_kill ()
 {
   debug_target.to_kill ();
 
-  fprintf_unfiltered (gdb_stderr, "target_kill ()\n");
+  fprintf_unfiltered (gdb_stdlog, "target_kill ()\n");
 }
 
 static void
@@ -2246,7 +2568,7 @@ debug_to_load (args, from_tty)
 {
   debug_target.to_load (args, from_tty);
 
-  fprintf_unfiltered (gdb_stderr, "target_load (%s, %d)\n", args, from_tty);
+  fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
 }
 
 static int
@@ -2258,7 +2580,7 @@ debug_to_lookup_symbol (name, addrp)
 
   retval = debug_target.to_lookup_symbol (name, addrp);
 
-  fprintf_unfiltered (gdb_stderr, "target_lookup_symbol (%s, xxx)\n", name);
+  fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
 
   return retval;
 }
@@ -2271,7 +2593,7 @@ debug_to_create_inferior (exec_file, args, env)
 {
   debug_target.to_create_inferior (exec_file, args, env);
 
-  fprintf_unfiltered (gdb_stderr, "target_create_inferior (%s, %s, xxx)\n",
+  fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n",
                      exec_file, args);
 }
 
@@ -2281,7 +2603,7 @@ debug_to_post_startup_inferior (pid)
 {
   debug_target.to_post_startup_inferior (pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_post_startup_inferior (%d)\n",
+  fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n",
                      pid);
 }
 
@@ -2291,7 +2613,7 @@ debug_to_acknowledge_created_inferior (pid)
 {
   debug_target.to_acknowledge_created_inferior (pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_acknowledge_created_inferior (%d)\n",
+  fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
                      pid);
 }
 
@@ -2302,7 +2624,7 @@ debug_to_clone_and_follow_inferior (child_pid, followed_child)
 {
   debug_target.to_clone_and_follow_inferior (child_pid, followed_child);
 
-  fprintf_unfiltered (gdb_stderr,
+  fprintf_unfiltered (gdb_stdlog,
                      "target_clone_and_follow_inferior (%d, %d)\n",
                      child_pid, *followed_child);
 }
@@ -2312,7 +2634,7 @@ debug_to_post_follow_inferior_by_clone ()
 {
   debug_target.to_post_follow_inferior_by_clone ();
 
-  fprintf_unfiltered (gdb_stderr, "target_post_follow_inferior_by_clone ()\n");
+  fprintf_unfiltered (gdb_stdlog, "target_post_follow_inferior_by_clone ()\n");
 }
 
 static int
@@ -2323,7 +2645,7 @@ debug_to_insert_fork_catchpoint (pid)
 
   retval = debug_target.to_insert_fork_catchpoint (pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_insert_fork_catchpoint (%d) = %d\n",
+  fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n",
                      pid, retval);
 
   return retval;
@@ -2337,7 +2659,7 @@ debug_to_remove_fork_catchpoint (pid)
 
   retval = debug_target.to_remove_fork_catchpoint (pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_remove_fork_catchpoint (%d) = %d\n",
+  fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n",
                      pid, retval);
 
   return retval;
@@ -2351,7 +2673,7 @@ debug_to_insert_vfork_catchpoint (pid)
 
   retval = debug_target.to_insert_vfork_catchpoint (pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_insert_vfork_catchpoint (%d)= %d\n",
+  fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)= %d\n",
                      pid, retval);
 
   return retval;
@@ -2365,7 +2687,7 @@ debug_to_remove_vfork_catchpoint (pid)
 
   retval = debug_target.to_remove_vfork_catchpoint (pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_remove_vfork_catchpoint (%d) = %d\n",
+  fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n",
                      pid, retval);
 
   return retval;
@@ -2380,7 +2702,7 @@ debug_to_has_forked (pid, child_pid)
 
   has_forked = debug_target.to_has_forked (pid, child_pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_has_forked (%d, %d) = %d\n",
+  fprintf_unfiltered (gdb_stdlog, "target_has_forked (%d, %d) = %d\n",
                      pid, *child_pid, has_forked);
 
   return has_forked;
@@ -2395,7 +2717,7 @@ debug_to_has_vforked (pid, child_pid)
 
   has_vforked = debug_target.to_has_vforked (pid, child_pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_has_vforked (%d, %d) = %d\n",
+  fprintf_unfiltered (gdb_stdlog, "target_has_vforked (%d, %d) = %d\n",
                      pid, *child_pid, has_vforked);
 
   return has_vforked;
@@ -2408,7 +2730,7 @@ debug_to_can_follow_vfork_prior_to_exec ()
 
   can_immediately_follow_vfork = debug_target.to_can_follow_vfork_prior_to_exec ();
 
-  fprintf_unfiltered (gdb_stderr, "target_can_follow_vfork_prior_to_exec () = %d\n",
+  fprintf_unfiltered (gdb_stdlog, "target_can_follow_vfork_prior_to_exec () = %d\n",
                      can_immediately_follow_vfork);
 
   return can_immediately_follow_vfork;
@@ -2423,7 +2745,7 @@ debug_to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_chi
 {
   debug_target.to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child);
 
-  fprintf_unfiltered (gdb_stderr,
+  fprintf_unfiltered (gdb_stdlog,
                      "target_post_follow_vfork (%d, %d, %d, %d)\n",
                    parent_pid, followed_parent, child_pid, followed_child);
 }
@@ -2436,7 +2758,7 @@ debug_to_insert_exec_catchpoint (pid)
 
   retval = debug_target.to_insert_exec_catchpoint (pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_insert_exec_catchpoint (%d) = %d\n",
+  fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n",
                      pid, retval);
 
   return retval;
@@ -2450,7 +2772,7 @@ debug_to_remove_exec_catchpoint (pid)
 
   retval = debug_target.to_remove_exec_catchpoint (pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_remove_exec_catchpoint (%d) = %d\n",
+  fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n",
                      pid, retval);
 
   return retval;
@@ -2465,7 +2787,7 @@ debug_to_has_execd (pid, execd_pathname)
 
   has_execd = debug_target.to_has_execd (pid, execd_pathname);
 
-  fprintf_unfiltered (gdb_stderr, "target_has_execd (%d, %s) = %d\n",
+  fprintf_unfiltered (gdb_stdlog, "target_has_execd (%d, %s) = %d\n",
                      pid, (*execd_pathname ? *execd_pathname : "<NULL>"),
                      has_execd);
 
@@ -2479,7 +2801,7 @@ debug_to_reported_exec_events_per_exec_call ()
 
   reported_exec_events = debug_target.to_reported_exec_events_per_exec_call ();
 
-  fprintf_unfiltered (gdb_stderr,
+  fprintf_unfiltered (gdb_stdlog,
                      "target_reported_exec_events_per_exec_call () = %d\n",
                      reported_exec_events);
 
@@ -2511,7 +2833,7 @@ debug_to_has_syscall_event (pid, kind, syscall_id)
        }
     }
 
-  fprintf_unfiltered (gdb_stderr,
+  fprintf_unfiltered (gdb_stdlog,
                      "target_has_syscall_event (%d, %s, %d) = %d\n",
                      pid, kind_spelling, *syscall_id, has_syscall_event);
 
@@ -2528,7 +2850,7 @@ debug_to_has_exited (pid, wait_status, exit_status)
 
   has_exited = debug_target.to_has_exited (pid, wait_status, exit_status);
 
-  fprintf_unfiltered (gdb_stderr, "target_has_exited (%d, %d, %d) = %d\n",
+  fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n",
                      pid, wait_status, *exit_status, has_exited);
 
   return has_exited;
@@ -2539,7 +2861,7 @@ debug_to_mourn_inferior ()
 {
   debug_target.to_mourn_inferior ();
 
-  fprintf_unfiltered (gdb_stderr, "target_mourn_inferior ()\n");
+  fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
 }
 
 static int
@@ -2549,7 +2871,7 @@ debug_to_can_run ()
 
   retval = debug_target.to_can_run ();
 
-  fprintf_unfiltered (gdb_stderr, "target_can_run () = %d\n", retval);
+  fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval);
 
   return retval;
 }
@@ -2560,7 +2882,7 @@ debug_to_notice_signals (pid)
 {
   debug_target.to_notice_signals (pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_notice_signals (%d)\n", pid);
+  fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n", pid);
 }
 
 static int
@@ -2571,18 +2893,26 @@ debug_to_thread_alive (pid)
 
   retval = debug_target.to_thread_alive (pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_thread_alive (%d) = %d\n",
+  fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
                      pid, retval);
 
   return retval;
 }
 
+static void
+debug_to_find_new_threads ()
+{
+  debug_target.to_find_new_threads ();
+
+  fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog);
+}
+
 static void
 debug_to_stop ()
 {
   debug_target.to_stop ();
 
-  fprintf_unfiltered (gdb_stderr, "target_stop ()\n");
+  fprintf_unfiltered (gdb_stdlog, "target_stop ()\n");
 }
 
 static int
@@ -2596,11 +2926,19 @@ debug_to_query (type, req, resp, siz)
 
   retval = debug_target.to_query (type, req, resp, siz);
 
-  fprintf_unfiltered (gdb_stderr, "target_query (%c, %s, %s,  %d) = %d\n", type, req, resp, *siz, retval);
+  fprintf_unfiltered (gdb_stdlog, "target_query (%c, %s, %s,  %d) = %d\n", type, req, resp, *siz, retval);
 
   return retval;
 }
 
+static void
+debug_to_rcmd (char *command,
+              struct ui_file *outbuf)
+{
+  debug_target.to_rcmd (command, outbuf);
+  fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command);
+}
+
 static struct symtab_and_line *
 debug_to_enable_exception_callback (kind, enable)
      enum exception_event_kind kind;
@@ -2608,7 +2946,7 @@ debug_to_enable_exception_callback (kind, enable)
 {
   struct symtab_and_line *result;
   result = debug_target.to_enable_exception_callback (kind, enable);
-  fprintf_unfiltered (gdb_stderr,
+  fprintf_unfiltered (gdb_stdlog,
                      "target get_exception_callback_sal (%d, %d)\n",
                      kind, enable);
   return result;
@@ -2619,7 +2957,7 @@ debug_to_get_current_exception_event ()
 {
   struct exception_event_record *result;
   result = debug_target.to_get_current_exception_event ();
-  fprintf_unfiltered (gdb_stderr, "target get_current_exception_event ()\n");
+  fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n");
   return result;
 }
 
@@ -2631,7 +2969,7 @@ debug_to_pid_to_exec_file (pid)
 
   exec_file = debug_target.to_pid_to_exec_file (pid);
 
-  fprintf_unfiltered (gdb_stderr, "target_pid_to_exec_file (%d) = %s\n",
+  fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n",
                      pid, exec_file);
 
   return exec_file;
@@ -2645,7 +2983,7 @@ debug_to_core_file_to_sym_file (core)
 
   sym_file = debug_target.to_core_file_to_sym_file (core);
 
-  fprintf_unfiltered (gdb_stderr, "target_core_file_to_sym_file (%s) = %s\n",
+  fprintf_unfiltered (gdb_stdlog, "target_core_file_to_sym_file (%s) = %s\n",
                      core, sym_file);
 
   return sym_file;
@@ -2704,8 +3042,10 @@ setup_target_debug ()
   current_target.to_can_run = debug_to_can_run;
   current_target.to_notice_signals = debug_to_notice_signals;
   current_target.to_thread_alive = debug_to_thread_alive;
+  current_target.to_find_new_threads = debug_to_find_new_threads;
   current_target.to_stop = debug_to_stop;
   current_target.to_query = debug_to_query;
+  current_target.to_rcmd = debug_to_rcmd;
   current_target.to_enable_exception_callback = debug_to_enable_exception_callback;
   current_target.to_get_current_exception_event = debug_to_get_current_exception_event;
   current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
@@ -2719,6 +3059,21 @@ static char targ_desc[] =
 Shows the entire stack of targets currently in use (including the exec-file,\n\
 core-file, and process, if any), as well as the symbol file name.";
 
+static void
+do_monitor_command (char *cmd,
+                int from_tty)
+{
+  if ((current_target.to_rcmd
+       == (void (*) (char *, struct ui_file *)) tcomplain)
+      || (current_target.to_rcmd == debug_to_rcmd
+         && (debug_target.to_rcmd
+             == (void (*) (char *, struct ui_file *)) tcomplain)))
+    {
+      error ("\"monitor\" command not supported by this target.\n");
+    }
+  target_rcmd (cmd, gdb_stdtarg);
+}
+
 void
 initialize_targets ()
 {
@@ -2729,11 +3084,15 @@ initialize_targets ()
   add_info ("files", target_info, targ_desc);
 
   add_show_from_set (
-               add_set_cmd ("targetdebug", class_maintenance, var_zinteger,
+               add_set_cmd ("target", class_maintenance, var_zinteger,
                             (char *) &targetdebug,
                             "Set target debugging.\n\
-When non-zero, target debugging is enabled.", &setlist),
-                     &showlist);
+When non-zero, target debugging is enabled.", &setdebuglist),
+                     &showdebuglist);
+
+
+  add_com ("monitor", class_obscure, do_monitor_command,
+          "Send a command to the remote monitor (remote targets only).");
 
   if (!STREQ (signals[TARGET_SIGNAL_LAST].string, "TARGET_SIGNAL_MAGIC"))
     abort ();