2003-05-15 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / monitor.c
index 060380616cb76d43bc0966068119a08970154e72..eabbbd938cc23258a4dfe3910fe083b207ad8107 100644 (file)
@@ -1,6 +1,8 @@
 /* Remote debugging interface for boot monitors, for GDB.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001 Free Software Foundation, Inc.
+
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+
    Contributed by Cygnus Support.  Written by Rob Savoye for Cygnus.
    Resurrected from the ashes by Stu Grossman.
 
@@ -567,12 +569,14 @@ monitor_expect (char *string, char *buf, int buflen)
                return 0;
            }
        }
-      else if ((c == '\021' || c == '\023') &&
-              (STREQ (targ_ops->to_shortname, "m32r")
-               || STREQ (targ_ops->to_shortname, "mon2000")))
-       {                       /* m32r monitor emits random DC1/DC3 chars */
-         continue;
-       }
+#if 0
+      // OBSOLETE       else if ((c == '\021' || c == '\023') &&
+      // OBSOLETE             (STREQ (targ_ops->to_shortname, "m32r")
+      // OBSOLETE              || STREQ (targ_ops->to_shortname, "mon2000")))
+      // OBSOLETE      {                       /* m32r monitor emits random DC1/DC3 chars */
+      // OBSOLETE        continue;
+      // OBSOLETE      }
+#endif
       else
        {
          /* We got a character that doesn't match the string.  We need to
@@ -892,7 +896,7 @@ char *
 monitor_supply_register (int regno, char *valstr)
 {
   ULONGEST val;
-  unsigned char regbuf[MAX_REGISTER_RAW_SIZE];
+  unsigned char regbuf[MAX_REGISTER_SIZE];
   char *p;
 
   val = 0;
@@ -1034,7 +1038,7 @@ monitor_interrupt_query (void)
 Give up (and stop debugging it)? "))
     {
       target_mourn_inferior ();
-      return_to_top_level (RETURN_QUIT);
+      throw_exception (RETURN_QUIT);
     }
 
   target_terminal_inferior ();
@@ -1172,16 +1176,19 @@ monitor_wait (ptid_t ptid, struct target_waitstatus *status)
 static void
 monitor_fetch_register (int regno)
 {
-  char *name;
+  const char *name;
   char *zerobuf;
   char *regbuf;
   int i;
 
-  regbuf  = alloca (MAX_REGISTER_RAW_SIZE * 2 + 1);
-  zerobuf = alloca (MAX_REGISTER_RAW_SIZE);
-  memset (zerobuf, 0, MAX_REGISTER_RAW_SIZE);
+  regbuf  = alloca (MAX_REGISTER_SIZE * 2 + 1);
+  zerobuf = alloca (MAX_REGISTER_SIZE);
+  memset (zerobuf, 0, MAX_REGISTER_SIZE);
 
-  name = current_monitor->regnames[regno];
+  if (current_monitor->regname != NULL)
+    name = current_monitor->regname (regno);
+  else
+    name = current_monitor->regnames[regno];
   monitor_debug ("MON fetchreg %d '%s'\n", regno, name ? name : "(null name)");
 
   if (!name || (*name == '\0'))
@@ -1331,10 +1338,14 @@ monitor_fetch_registers (int regno)
 static void
 monitor_store_register (int regno)
 {
-  char *name;
+  const char *name;
   ULONGEST val;
-
-  name = current_monitor->regnames[regno];
+  
+  if (current_monitor->regname != NULL)
+    name = current_monitor->regname (regno);
+  else
+    name = current_monitor->regnames[regno];
+  
   if (!name || (*name == '\0'))
     {
       monitor_debug ("MON Cannot store unknown register\n");
@@ -2019,8 +2030,7 @@ monitor_read_memory (CORE_ADDR memaddr, char *myaddr, int len)
 
 static int
 monitor_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
-                    struct mem_attrib *attrib ATTRIBUTE_UNUSED,
-                    struct target_ops *target ATTRIBUTE_UNUSED)
+                    struct mem_attrib *attrib, struct target_ops *target)
 {
   int res;
 
@@ -2077,7 +2087,7 @@ static int
 monitor_insert_breakpoint (CORE_ADDR addr, char *shadow)
 {
   int i;
-  unsigned char *bp;
+  const unsigned char *bp;
   int bplen;
 
   monitor_debug ("MON inst bkpt %s\n", paddr (addr));
@@ -2088,7 +2098,7 @@ monitor_insert_breakpoint (CORE_ADDR addr, char *shadow)
     addr = ADDR_BITS_REMOVE (addr);
 
   /* Determine appropriate breakpoint size for this address.  */
-  bp = memory_breakpoint_from_pc (&addr, &bplen);
+  bp = gdbarch_breakpoint_from_pc (current_gdbarch, &addr, &bplen);
 
   for (i = 0; i < current_monitor->num_breakpoints; i++)
     {
@@ -2206,15 +2216,19 @@ monitor_load (char *file, int from_tty)
   if (exec_bfd)
     write_pc (bfd_get_start_address (exec_bfd));
 
-  inferior_ptid = null_ptid ;  /* No process now */
-
-  /* This is necessary because many things were based on the PC at the
-     time that we attached to the monitor, which is no longer valid
-     now that we have loaded new code (and just changed the PC).
-     Another way to do this might be to call normal_stop, except that
-     the stack may not be valid, and things would get horribly
-     confused... */
-  clear_symtab_users ();
+  /* There used to be code here which would clear inferior_ptid and
+     call clear_symtab_users.  None of that should be necessary:
+     monitor targets should behave like remote protocol targets, and
+     since generic_load does none of those things, this function
+     shouldn't either.
+
+     Furthermore, clearing inferior_ptid is *incorrect*.  After doing
+     a load, we still have a valid connection to the monitor, with a
+     live processor state to fiddle with.  The user can type
+     `continue' or `jump *start' and make the program run.  If they do
+     these things, however, GDB will be talking to a running program
+     while inferior_ptid is null_ptid; this makes things like
+     reinit_frame_cache very confused.  */
 }
 
 static void
@@ -2282,19 +2296,10 @@ static struct target_ops monitor_ops;
 static void
 init_base_monitor_ops (void)
 {
-  monitor_ops.to_shortname = NULL;
-  monitor_ops.to_longname = NULL;
-  monitor_ops.to_doc = NULL;
-  monitor_ops.to_open = NULL;
   monitor_ops.to_close = monitor_close;
-  monitor_ops.to_attach = NULL;
-  monitor_ops.to_post_attach = NULL;
-  monitor_ops.to_require_attach = NULL;
   monitor_ops.to_detach = monitor_detach;
-  monitor_ops.to_require_detach = NULL;
   monitor_ops.to_resume = monitor_resume;
   monitor_ops.to_wait = monitor_wait;
-  monitor_ops.to_post_wait = NULL;
   monitor_ops.to_fetch_registers = monitor_fetch_registers;
   monitor_ops.to_store_registers = monitor_store_registers;
   monitor_ops.to_prepare_to_store = monitor_prepare_to_store;
@@ -2302,48 +2307,18 @@ init_base_monitor_ops (void)
   monitor_ops.to_files_info = monitor_files_info;
   monitor_ops.to_insert_breakpoint = monitor_insert_breakpoint;
   monitor_ops.to_remove_breakpoint = monitor_remove_breakpoint;
-  monitor_ops.to_terminal_init = 0;
-  monitor_ops.to_terminal_inferior = 0;
-  monitor_ops.to_terminal_ours_for_output = 0;
-  monitor_ops.to_terminal_ours = 0;
-  monitor_ops.to_terminal_info = 0;
   monitor_ops.to_kill = monitor_kill;
   monitor_ops.to_load = monitor_load;
-  monitor_ops.to_lookup_symbol = 0;
   monitor_ops.to_create_inferior = monitor_create_inferior;
-  monitor_ops.to_post_startup_inferior = NULL;
-  monitor_ops.to_acknowledge_created_inferior = NULL;
-  monitor_ops.to_clone_and_follow_inferior = NULL;
-  monitor_ops.to_post_follow_inferior_by_clone = NULL;
-  monitor_ops.to_insert_fork_catchpoint = NULL;
-  monitor_ops.to_remove_fork_catchpoint = NULL;
-  monitor_ops.to_insert_vfork_catchpoint = NULL;
-  monitor_ops.to_remove_vfork_catchpoint = NULL;
-  monitor_ops.to_has_forked = NULL;
-  monitor_ops.to_has_vforked = NULL;
-  monitor_ops.to_can_follow_vfork_prior_to_exec = NULL;
-  monitor_ops.to_post_follow_vfork = NULL;
-  monitor_ops.to_insert_exec_catchpoint = NULL;
-  monitor_ops.to_remove_exec_catchpoint = NULL;
-  monitor_ops.to_has_execd = NULL;
-  monitor_ops.to_reported_exec_events_per_exec_call = NULL;
-  monitor_ops.to_has_exited = NULL;
   monitor_ops.to_mourn_inferior = monitor_mourn_inferior;
-  monitor_ops.to_can_run = 0;
-  monitor_ops.to_notice_signals = 0;
-  monitor_ops.to_thread_alive = 0;
   monitor_ops.to_stop = monitor_stop;
   monitor_ops.to_rcmd = monitor_rcmd;
-  monitor_ops.to_pid_to_exec_file = NULL;
   monitor_ops.to_stratum = process_stratum;
-  monitor_ops.DONT_USE = 0;
   monitor_ops.to_has_all_memory = 1;
   monitor_ops.to_has_memory = 1;
   monitor_ops.to_has_stack = 1;
   monitor_ops.to_has_registers = 1;
   monitor_ops.to_has_execution = 1;
-  monitor_ops.to_sections = 0;
-  monitor_ops.to_sections_end = 0;
   monitor_ops.to_magic = OPS_MAGIC;
 }                              /* init_base_monitor_ops */
 
This page took 0.027095 seconds and 4 git commands to generate.