* libaout.h (enum machine_type): Change M_SPARCLET from 142 to 131.
[deliverable/binutils-gdb.git] / gdb / remote-sim.c
index f2df37a48e75c3d9a3e59869f818b88c42492b27..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,13 +32,60 @@ 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"
 
+/* 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));
+
+static void gdbsim_kill PARAMS ((void));
+
+static void gdbsim_load PARAMS ((char *prog, int fromtty));
+
+static void gdbsim_create_inferior PARAMS ((char *exec_file, char *args, char **env));
+
+static void gdbsim_open PARAMS ((char *args, int from_tty));
+
+static void gdbsim_close PARAMS ((int quitting));
+
+static void gdbsim_detach PARAMS ((char *args, int from_tty));
+
+static void gdbsim_resume PARAMS ((int pid, int step, enum target_signal siggnal));
+
+static int gdbsim_wait PARAMS ((int pid, struct target_waitstatus *status));
+
+static void gdbsim_prepare_to_store PARAMS ((void));
+
+static int gdbsim_xfer_inferior_memory PARAMS ((CORE_ADDR memaddr,
+                                               char *myaddr, int len,
+                                               int write,
+                                               struct target_ops *target));
+
+static void gdbsim_files_info PARAMS ((struct target_ops *target));
+
+static void gdbsim_mourn_inferior PARAMS ((void));
+
+static void simulator_command PARAMS ((char *args, int from_tty));
+
 /* Naming convention:
 
    sim_* are the interface to the simulator (see remote-sim.h).
-
    gdbsim_* are stuff which is internal to gdb.  */
 
 /* Forward data declarations */
@@ -71,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;
@@ -95,6 +258,7 @@ int regno;
     }
 }
 
+
 static void
 gdbsim_store_register (regno)
 int regno;
@@ -150,13 +314,13 @@ gdbsim_load (prog, fromtty)
   program_loaded = 1;
 
   if (sim_load (prog, fromtty) != 0)
-    gr_load_image (prog, fromtty);
+    generic_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
@@ -184,11 +348,11 @@ gdbsim_create_inferior (exec_file, args, env)
 
   entry_pt = (CORE_ADDR) bfd_get_start_address (exec_bfd);
 
-  gdbsim_kill (NULL, NULL);     
+  gdbsim_kill ();       
   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);
@@ -200,12 +364,6 @@ gdbsim_create_inferior (exec_file, args, env)
 
   inferior_pid = 42;
   insert_breakpoints ();       /* Needed to get correct instruction in cache */
-
-  /* FIXME: This needs to be done in a target-specific fashion.
-     What you see here works for the PPC simulator tiemann 9/9/1995.
-     Also, the fact that we can find the addresses for breakpoints without
-     this mechanism suggests some redundant code that could be merged.  */     
-  add_text_to_loadinfo (entry_pt, entry_pt+exec_bfd->sections->_cooked_size);
   proceed (entry_pt, TARGET_SIGNAL_DEFAULT, 0);
 }
 
@@ -222,11 +380,12 @@ gdbsim_open (args, from_tty)
   if (sr_get_debug ())
     printf_filtered ("gdbsim_open: args \"%s\"\n", args ? args : "(null)");
 
+  init_callbacks ();
+
   sim_open (args);
 
   push_target (&gdbsim_ops);
   target_fetch_registers (-1);
-
   printf_filtered ("Connected to the simulator.\n");
 }
 
@@ -249,6 +408,8 @@ gdbsim_close (quitting)
   program_loaded = 0;
 
   sim_close (quitting);
+
+  end_callbacks ();
 }
 
 /* Takes a program previously attached to and detaches it.
@@ -282,6 +443,9 @@ gdbsim_resume (pid, step, siggnal)
      int pid, step;
      enum target_signal siggnal;
 {
+  if (inferior_pid != 42)
+    error ("The program is not being run.");
+
   if (sr_get_debug ())
     printf_filtered ("gdbsim_resume: step %d, signal %d\n", step, siggnal);
 
@@ -403,15 +567,18 @@ gdbsim_mourn_inferior ()
   generic_mourn_inferior ();
 }
 
-/* Put a command string, in args, out to MONITOR.  Output from MONITOR
-   is placed on the users terminal until the prompt is seen. FIXME: We
-   read the characters ourseleves here cause of a nasty echo.  */
+/* Pass the command argument through to the simulator verbatim.  The
+   simulator must do any command interpretation work.  */
 
 static void
 simulator_command (args, from_tty)
      char *args;
      int from_tty;
 {
+  /* The user may give a command before the simulator is opened, so
+     ensure that the callbacks have been set up.  */
+  init_callbacks ();
+
   sim_do_command (args);
 }
 
This page took 0.026476 seconds and 4 git commands to generate.