* libaout.h (enum machine_type): Change M_SPARCLET from 142 to 131.
[deliverable/binutils-gdb.git] / gdb / remote-sim.c
index 010d501138cd994d01766bdf37f740cdf1955530..e9c32dbab578e2f380230d6ba9259c4afe780204 100644 (file)
@@ -1,5 +1,5 @@
 /* Generic remote debugging interface for simulators.
-   Copyright 1993, 1994 Free Software Foundation, Inc.
+   Copyright 1993, 1994, 1996 Free Software Foundation, Inc.
    Contributed by Cygnus Support.
    Steve Chamberlain (sac@cygnus.com).
 
@@ -32,14 +32,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "terminal.h"
 #include "target.h"
 #include "gdbcore.h"
+#include "callback.h"
 #include "remote-sim.h"
 #include "remote-utils.h"
-#include "callback.h"
 
 /* Prototypes */
 
 static void dump_mem PARAMS ((char *buf, int len));
 
+static void init_callbacks PARAMS ((void));
+
+static void end_callbacks PARAMS ((void));
+
+static int gdb_os_write_stdout PARAMS ((host_callback *, const char *, int));
+
+static void gdb_os_printf_filtered PARAMS ((host_callback *, const char *, ...));
+
+static void gdb_os_error PARAMS ((host_callback *, const char *, ...));
+
 static void gdbsim_fetch_register PARAMS ((int regno));
 
 static void gdbsim_store_register PARAMS ((int regno));
@@ -76,7 +86,6 @@ static void simulator_command PARAMS ((char *args, int from_tty));
 /* Naming convention:
 
    sim_* are the interface to the simulator (see remote-sim.h).
-   sim_callback_* are the stuff which the simulator can see inside GDB.
    gdbsim_* are stuff which is internal to gdb.  */
 
 /* Forward data declarations */
@@ -109,6 +118,122 @@ dump_mem (buf, len)
     }
 }
 
+static host_callback gdb_callback;
+static int callbacks_initialized = 0;
+
+/* Initialize gdb_callback.  */
+
+static void
+init_callbacks ()
+{
+  if (! callbacks_initialized)
+    {
+      gdb_callback = default_callback;
+      gdb_callback.init (&gdb_callback);
+      gdb_callback.write_stdout = gdb_os_write_stdout;
+      gdb_callback.printf_filtered = gdb_os_printf_filtered;
+      gdb_callback.error = gdb_os_error;
+      sim_set_callbacks (&gdb_callback);
+      callbacks_initialized = 1;
+    }
+}
+
+/* Release callbacks (free resources used by them).  */
+
+static void
+end_callbacks ()
+{
+  if (callbacks_initialized)
+    {
+      gdb_callback.shutdown (&gdb_callback);
+      callbacks_initialized = 0;
+    }
+}
+
+/* GDB version of os_write_stdout callback.  */
+
+static int 
+gdb_os_write_stdout (p, buf, len)
+     host_callback *p;
+     const char *buf;
+     int len;
+{
+  int i;
+  char b[2];
+
+  for (i = 0; i < len; i++) 
+    {
+      b[0] = buf[i];
+      b[1] = 0;
+      if (target_output_hook)
+       target_output_hook (b);
+      else
+       fputs_filtered (b, gdb_stdout);
+    }
+  return len;
+}
+
+/* GDB version of printf_filtered callback.  */
+
+/* VARARGS */
+static void
+#ifdef ANSI_PROTOTYPES
+gdb_os_printf_filtered (host_callback *p, const char *format, ...)
+#else
+gdb_os_printf_filtered (p, va_alist)
+     host_callback *p;
+     va_dcl
+#endif
+{
+  va_list args;
+#ifdef ANSI_PROTOTYPES
+  va_start (args, format);
+#else
+  char *format;
+
+  va_start (args);
+  format = va_arg (args, char *);
+#endif
+
+  vfprintf_filtered (gdb_stdout, format, args);
+
+  va_end (args);
+}
+
+/* GDB version of error callback.  */
+
+/* VARARGS */
+static void
+#ifdef ANSI_PROTOTYPES
+gdb_os_error (host_callback *p, const char *format, ...)
+#else
+gdb_os_error (p, va_alist)
+     host_callback *p;
+     va_dcl
+#endif
+{
+  if (error_hook)
+    (*error_hook) ();
+  else 
+    {
+      va_list args;
+#ifdef ANSI_PROTOTYPES
+      va_start (args, format);
+#else
+      char *format;
+
+      va_start (args);
+      format = va_arg (args, char *);
+#endif
+
+      error_begin ();
+      vfprintf_filtered (gdb_stderr, format, args);
+      fprintf_filtered (gdb_stderr, "\n");
+      va_end (args);
+      return_to_top_level (RETURN_ERROR);
+    }
+}
+
 static void
 gdbsim_fetch_register (regno)
 int regno;
@@ -195,7 +320,7 @@ gdbsim_load (prog, fromtty)
 
 /* Start an inferior process and set inferior_pid to its pid.
    EXEC_FILE is the file to run.
-   ALLARGS is a string containing the arguments to the program.
+   ARGS is a string containing the arguments to the program.
    ENV is the environment vector to pass.  Errors reported with error().
    On VxWorks and various standalone systems, we ignore exec_file.  */
 /* This is called not only when we first attach, but also when the
@@ -227,7 +352,7 @@ gdbsim_create_inferior (exec_file, args, env)
   remove_breakpoints ();
   init_wait_for_inferior ();
 
-  len = 5 + strlen (exec_file) + 1 + strlen (args) + 1 + /*slop*/ 10;
+  len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop*/ 10;
   arg_buf = (char *) alloca (len);
   arg_buf[0] = '\0';
   strcat (arg_buf, exec_file);
@@ -255,8 +380,7 @@ gdbsim_open (args, from_tty)
   if (sr_get_debug ())
     printf_filtered ("gdbsim_open: args \"%s\"\n", args ? args : "(null)");
 
-  sim_set_callbacks (&default_callback);
-  default_callback.init (&default_callback);
+  init_callbacks ();
 
   sim_open (args);
 
@@ -284,6 +408,8 @@ gdbsim_close (quitting)
   program_loaded = 0;
 
   sim_close (quitting);
+
+  end_callbacks ();
 }
 
 /* Takes a program previously attached to and detaches it.
@@ -451,8 +577,7 @@ simulator_command (args, from_tty)
 {
   /* The user may give a command before the simulator is opened, so
      ensure that the callbacks have been set up.  */
-  sim_set_callbacks (&default_callback);
-  default_callback.init (&default_callback);
+  init_callbacks ();
 
   sim_do_command (args);
 }
This page took 0.025516 seconds and 4 git commands to generate.