2002-02-27 Daniel Jacobowitz <drow@mvista.com>
[deliverable/binutils-gdb.git] / gdb / remote-sim.c
index 11f17dd212a873b20f44d387e5d3cdf0842dde78..1d037c8fa79d777e410be702fd57a9b04447c8a9 100644 (file)
@@ -1,5 +1,8 @@
 /* Generic remote debugging interface for simulators.
-   Copyright 1993, 1994, 1996, 1997, 2000 Free Software Foundation, Inc.
+
+   Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+   2002 Free Software Foundation, Inc.
+
    Contributed by Cygnus Support.
    Steve Chamberlain (sac@cygnus.com).
 
@@ -22,7 +25,6 @@
 
 #include "defs.h"
 #include "inferior.h"
-#include "gdb_wait.h"
 #include "value.h"
 #include "gdb_string.h"
 #include <ctype.h>
 #include "remote-sim.h"
 #include "remote-utils.h"
 #include "command.h"
+#include "regcache.h"
 
 /* Prototypes */
 
 extern void _initialize_remote_sim (void);
 
-extern int (*ui_loop_hook) PARAMS ((int signo));
+extern int (*ui_loop_hook) (int signo);
 
 static void dump_mem (char *buf, int len);
 
@@ -85,15 +88,16 @@ static void gdbsim_close (int quitting);
 
 static void gdbsim_detach (char *args, int from_tty);
 
-static void gdbsim_resume (int pid, int step, enum target_signal siggnal);
+static void gdbsim_resume (ptid_t ptid, int step, enum target_signal siggnal);
 
-static int gdbsim_wait (int pid, struct target_waitstatus *status);
+static ptid_t gdbsim_wait (ptid_t ptid, struct target_waitstatus *status);
 
 static void gdbsim_prepare_to_store (void);
 
-static int gdbsim_xfer_inferior_memory (CORE_ADDR memaddr,
-                                       char *myaddr, int len,
-                                       int write, struct target_ops *target);
+static int gdbsim_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, 
+                                       int len, int write,
+                                       struct mem_attrib *attrib,
+                                       struct target_ops *target);
 
 static void gdbsim_files_info (struct target_ops *target);
 
@@ -120,9 +124,7 @@ static int program_loaded = 0;
 static SIM_DESC gdbsim_desc = 0;
 
 static void
-dump_mem (buf, len)
-     char *buf;
-     int len;
+dump_mem (char *buf, int len)
 {
   if (len <= 8)
     {
@@ -131,7 +133,9 @@ dump_mem (buf, len)
          long l[2];
          memcpy (l, buf, len);
          printf_filtered ("\t0x%lx", l[0]);
-         printf_filtered (len == 8 ? " 0x%x\n" : "\n", l[1]);
+         if (len == 8)
+           printf_filtered (" 0x%lx", l[1]);
+         printf_filtered ("\n");
        }
       else
        {
@@ -150,7 +154,7 @@ static int callbacks_initialized = 0;
 /* Initialize gdb_callback.  */
 
 static void
-init_callbacks ()
+init_callbacks (void)
 {
   if (!callbacks_initialized)
     {
@@ -173,7 +177,7 @@ init_callbacks ()
 /* Release callbacks (free resources used by them).  */
 
 static void
-end_callbacks ()
+end_callbacks (void)
 {
   if (callbacks_initialized)
     {
@@ -185,10 +189,7 @@ end_callbacks ()
 /* GDB version of os_write_stdout callback.  */
 
 static int
-gdb_os_write_stdout (p, buf, len)
-     host_callback *p;
-     const char *buf;
-     int len;
+gdb_os_write_stdout (host_callback *p, const char *buf, int len)
 {
   int i;
   char b[2];
@@ -200,8 +201,7 @@ gdb_os_write_stdout (p, buf, len)
 /* GDB version of os_flush_stdout callback.  */
 
 static void
-gdb_os_flush_stdout (p)
-     host_callback *p;
+gdb_os_flush_stdout (host_callback *p)
 {
   gdb_flush (gdb_stdtarg);
 }
@@ -209,10 +209,7 @@ gdb_os_flush_stdout (p)
 /* GDB version of os_write_stderr callback.  */
 
 static int
-gdb_os_write_stderr (p, buf, len)
-     host_callback *p;
-     const char *buf;
-     int len;
+gdb_os_write_stderr (host_callback *p, const char *buf, int len)
 {
   int i;
   char b[2];
@@ -229,8 +226,7 @@ gdb_os_write_stderr (p, buf, len)
 /* GDB version of os_flush_stderr callback.  */
 
 static void
-gdb_os_flush_stderr (p)
-     host_callback *p;
+gdb_os_flush_stderr (host_callback *p)
 {
   gdb_flush (gdb_stderr);
 }
@@ -280,13 +276,8 @@ gdb_os_error (host_callback * p, const char *format,...)
     }
 }
 
-#ifndef REGISTER_SIM_REGNO
-#define REGISTER_SIM_REGNO(N) (N)
-#endif
-
 static void
-gdbsim_fetch_register (regno)
-     int regno;
+gdbsim_fetch_register (int regno)
 {
   static int warn_user = 1;
   if (regno == -1)
@@ -330,8 +321,7 @@ gdbsim_fetch_register (regno)
 
 
 static void
-gdbsim_store_register (regno)
-     int regno;
+gdbsim_store_register (int regno)
 {
   if (regno == -1)
     {
@@ -349,7 +339,8 @@ gdbsim_store_register (regno)
                                     REGISTER_SIM_REGNO (regno),
                                     tmp, REGISTER_RAW_SIZE (regno));
       if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno))
-       internal_error ("Register size different to expected");
+       internal_error (__FILE__, __LINE__,
+                       "Register size different to expected");
       if (sr_get_debug ())
        {
          printf_filtered ("gdbsim_store_register: %d", regno);
@@ -363,14 +354,14 @@ gdbsim_store_register (regno)
    and releasing other resources acquired by the simulated program.  */
 
 static void
-gdbsim_kill ()
+gdbsim_kill (void)
 {
   if (sr_get_debug ())
     printf_filtered ("gdbsim_kill\n");
 
   /* There is no need to `kill' running simulator - the simulator is
      not running */
-  inferior_pid = 0;
+  inferior_ptid = null_ptid;
 }
 
 /* Load an executable file into the target process.  This is expected to
@@ -378,14 +369,12 @@ gdbsim_kill ()
    GDB's symbol tables to match.  */
 
 static void
-gdbsim_load (prog, fromtty)
-     char *prog;
-     int fromtty;
+gdbsim_load (char *prog, int fromtty)
 {
   if (sr_get_debug ())
     printf_filtered ("gdbsim_load: prog \"%s\"\n", prog);
 
-  inferior_pid = 0;
+  inferior_ptid = null_ptid;
 
   /* FIXME: We will print two messages on error.
      Need error to either not print anything if passed NULL or need
@@ -400,7 +389,7 @@ gdbsim_load (prog, fromtty)
 }
 
 
-/* Start an inferior process and set inferior_pid to its pid.
+/* Start an inferior process and set inferior_ptid to its pid.
    EXEC_FILE is the file to run.
    ARGS is a string containing the arguments to the program.
    ENV is the environment vector to pass.  Errors reported with error().
@@ -409,10 +398,7 @@ gdbsim_load (prog, fromtty)
    user types "run" after having attached.  */
 
 static void
-gdbsim_create_inferior (exec_file, args, env)
-     char *exec_file;
-     char *args;
-     char **env;
+gdbsim_create_inferior (char *exec_file, char *args, char **env)
 {
   int len;
   char *arg_buf, **argv;
@@ -446,7 +432,7 @@ gdbsim_create_inferior (exec_file, args, env)
     argv = NULL;
   sim_create_inferior (gdbsim_desc, exec_bfd, argv, env);
 
-  inferior_pid = 42;
+  inferior_ptid = pid_to_ptid (42);
   insert_breakpoints ();       /* Needed to get correct instruction in cache */
 
   clear_proceed_status ();
@@ -461,9 +447,7 @@ gdbsim_create_inferior (exec_file, args, env)
 /* Called when selecting the simulator. EG: (gdb) target sim name.  */
 
 static void
-gdbsim_open (args, from_tty)
-     char *args;
-     int from_tty;
+gdbsim_open (char *args, int from_tty)
 {
   int len;
   char *arg_buf;
@@ -490,19 +474,19 @@ gdbsim_open (args, from_tty)
   strcpy (arg_buf, "gdbsim");  /* 7 */
   /* Specify the byte order for the target when it is both selectable
      and explicitly specified by the user (not auto detected). */
-  if (TARGET_BYTE_ORDER_SELECTABLE_P
-      && !TARGET_BYTE_ORDER_AUTO)
+  if (!TARGET_BYTE_ORDER_AUTO)
     {
       switch (TARGET_BYTE_ORDER)
        {
-       case BIG_ENDIAN:
+       case BFD_ENDIAN_BIG:
          strcat (arg_buf, " -E big");
          break;
-       case LITTLE_ENDIAN:
+       case BFD_ENDIAN_LITTLE:
          strcat (arg_buf, " -E little");
          break;
        default:
-         internal_error ("Value of TARGET_BYTE_ORDER unknown");
+         internal_error (__FILE__, __LINE__,
+                         "Value of TARGET_BYTE_ORDER unknown");
        }
     }
   /* Specify the architecture of the target when it has been
@@ -544,8 +528,7 @@ gdbsim_open (args, from_tty)
 /* Close out all files and local state before this target loses control. */
 
 static void
-gdbsim_close (quitting)
-     int quitting;
+gdbsim_close (int quitting)
 {
   if (sr_get_debug ())
     printf_filtered ("gdbsim_close: quitting %d\n", quitting);
@@ -572,9 +555,7 @@ gdbsim_close (quitting)
    Use this when you want to detach and do something else with your gdb.  */
 
 static void
-gdbsim_detach (args, from_tty)
-     char *args;
-     int from_tty;
+gdbsim_detach (char *args, int from_tty)
 {
   if (sr_get_debug ())
     printf_filtered ("gdbsim_detach: args \"%s\"\n", args);
@@ -592,11 +573,9 @@ static enum target_signal resume_siggnal;
 static int resume_step;
 
 static void
-gdbsim_resume (pid, step, siggnal)
-     int pid, step;
-     enum target_signal siggnal;
+gdbsim_resume (ptid_t ptid, int step, enum target_signal siggnal)
 {
-  if (inferior_pid != 42)
+  if (PIDGET (inferior_ptid) != 42)
     error ("The program is not being run.");
 
   if (sr_get_debug ())
@@ -616,7 +595,7 @@ gdbsim_resume (pid, step, siggnal)
    For simulators that do not support this operation, just abort */
 
 static void
-gdbsim_stop ()
+gdbsim_stop (void)
 {
   if (!sim_stop (gdbsim_desc))
     {
@@ -628,13 +607,11 @@ gdbsim_stop ()
    Taken from gdb/util.c - should be in a library */
 
 static int
-gdb_os_poll_quit (p)
-     host_callback *p;
+gdb_os_poll_quit (host_callback *p)
 {
   if (ui_loop_hook != NULL)
     ui_loop_hook (0);
 
-  notice_quit ();
   if (quit_flag)               /* gdb's idea of quit */
     {
       quit_flag = 0;           /* we've stolen it */
@@ -652,16 +629,13 @@ gdb_os_poll_quit (p)
    just as `wait' would. */
 
 static void
-gdbsim_cntrl_c (signo)
-     int signo;
+gdbsim_cntrl_c (int signo)
 {
   gdbsim_stop ();
 }
 
-static int
-gdbsim_wait (pid, status)
-     int pid;
-     struct target_waitstatus *status;
+static ptid_t
+gdbsim_wait (ptid_t ptid, struct target_waitstatus *status)
 {
   static RETSIGTYPE (*prev_sigint) ();
   int sigrc = 0;
@@ -723,7 +697,7 @@ gdbsim_wait (pid, status)
       break;
     }
 
-  return inferior_pid;
+  return inferior_ptid;
 }
 
 /* Get ready to modify the registers array.  On machines which store
@@ -733,18 +707,21 @@ gdbsim_wait (pid, status)
    debugged.  */
 
 static void
-gdbsim_prepare_to_store ()
+gdbsim_prepare_to_store (void)
 {
   /* Do nothing, since we can store individual regs */
 }
 
+/* Transfer LEN bytes between GDB address MYADDR and target address
+   MEMADDR.  If WRITE is non-zero, transfer them to the target,
+   otherwise transfer them from the target.  TARGET is unused.
+
+   Returns the number of bytes transferred. */
+
 static int
-gdbsim_xfer_inferior_memory (memaddr, myaddr, len, write, target)
-     CORE_ADDR memaddr;
-     char *myaddr;
-     int len;
-     int write;
-     struct target_ops *target;        /* ignored */
+gdbsim_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len,
+                            int write, struct mem_attrib *attrib,
+                            struct target_ops *target)
 {
   if (!program_loaded)
     error ("No program loaded.");
@@ -774,8 +751,7 @@ gdbsim_xfer_inferior_memory (memaddr, myaddr, len, write, target)
 }
 
 static void
-gdbsim_files_info (target)
-     struct target_ops *target;
+gdbsim_files_info (struct target_ops *target)
 {
   char *file = "nothing";
 
@@ -796,7 +772,7 @@ gdbsim_files_info (target)
 /* Clear the simulator's notion of what the break points are.  */
 
 static void
-gdbsim_mourn_inferior ()
+gdbsim_mourn_inferior (void)
 {
   if (sr_get_debug ())
     printf_filtered ("gdbsim_mourn_inferior:\n");
@@ -806,9 +782,7 @@ gdbsim_mourn_inferior ()
 }
 
 static int
-gdbsim_insert_breakpoint (addr, contents_cache)
-     CORE_ADDR addr;
-     char *contents_cache;
+gdbsim_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
 {
 #ifdef SIM_HAS_BREAKPOINTS
   SIM_RC retcode;
@@ -830,9 +804,7 @@ gdbsim_insert_breakpoint (addr, contents_cache)
 }
 
 static int
-gdbsim_remove_breakpoint (addr, contents_cache)
-     CORE_ADDR addr;
-     char *contents_cache;
+gdbsim_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
 {
 #ifdef SIM_HAS_BREAKPOINTS
   SIM_RC retcode;
@@ -858,9 +830,7 @@ gdbsim_remove_breakpoint (addr, contents_cache)
    simulator must do any command interpretation work.  */
 
 void
-simulator_command (args, from_tty)
-     char *args;
-     int from_tty;
+simulator_command (char *args, int from_tty)
 {
   if (gdbsim_desc == NULL)
     {
@@ -944,7 +914,6 @@ init_gdbsim_ops (void)
   gdbsim_ops.to_thread_alive = 0;
   gdbsim_ops.to_stop = gdbsim_stop;
   gdbsim_ops.to_pid_to_exec_file = NULL;
-  gdbsim_ops.to_core_file_to_sym_file = NULL;
   gdbsim_ops.to_stratum = process_stratum;
   gdbsim_ops.DONT_USE = NULL;
   gdbsim_ops.to_has_all_memory = 1;
@@ -962,7 +931,7 @@ init_gdbsim_ops (void)
 }
 
 void
-_initialize_remote_sim ()
+_initialize_remote_sim (void)
 {
   init_gdbsim_ops ();
   add_target (&gdbsim_ops);
This page took 0.029641 seconds and 4 git commands to generate.