* mn10300-tdep.c (mn10300_dwarf2_reg_to_regnum): New function.
[deliverable/binutils-gdb.git] / gdb / target.c
index 563008051bc31dc5a825bfd50356b74184f8316f..83501e609619d8408705ced086ce3880ec5d75f1 100644 (file)
@@ -1,7 +1,7 @@
 /* Select target systems and architectures at runtime for GDB.
 
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.
 
@@ -71,8 +71,8 @@ static void nosupport_runtime (void);
 
 static LONGEST default_xfer_partial (struct target_ops *ops,
                                     enum target_object object,
-                                    const char *annex, void *readbuf,
-                                    const void *writebuf,
+                                    const char *annex, gdb_byte *readbuf,
+                                    const gdb_byte *writebuf,
                                     ULONGEST offset, LONGEST len);
 
 /* Transfer LEN bytes between target address MEMADDR and GDB address
@@ -81,7 +81,7 @@ static LONGEST default_xfer_partial (struct target_ops *ops,
    partial transfers, try either target_read_memory_partial or
    target_write_memory_partial).  */
 
-static int target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
+static int target_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len,
                               int write);
 
 static void init_dummy_target (void);
@@ -108,21 +108,17 @@ static void debug_to_store_registers (int);
 
 static void debug_to_prepare_to_store (void);
 
-static int deprecated_debug_xfer_memory (CORE_ADDR, char *, int, int,
-                                        struct mem_attrib *,
-                                        struct target_ops *);
-
 static void debug_to_files_info (struct target_ops *);
 
-static int debug_to_insert_breakpoint (CORE_ADDR, char *);
+static int debug_to_insert_breakpoint (CORE_ADDR, gdb_byte *);
 
-static int debug_to_remove_breakpoint (CORE_ADDR, char *);
+static int debug_to_remove_breakpoint (CORE_ADDR, gdb_byte *);
 
 static int debug_to_can_use_hw_breakpoint (int, int, int);
 
-static int debug_to_insert_hw_breakpoint (CORE_ADDR, char *);
+static int debug_to_insert_hw_breakpoint (CORE_ADDR, gdb_byte *);
 
-static int debug_to_remove_hw_breakpoint (CORE_ADDR, char *);
+static int debug_to_remove_hw_breakpoint (CORE_ADDR, gdb_byte *);
 
 static int debug_to_insert_watchpoint (CORE_ADDR, int, int);
 
@@ -203,6 +199,12 @@ int attach_flag;
 /* Non-zero if we want to see trace of target level stuff.  */
 
 static int targetdebug = 0;
+static void
+show_targetdebug (struct ui_file *file, int from_tty,
+                 struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Target debugging is %s.\n"), value);
+}
 
 static void setup_target_debug (void);
 
@@ -499,7 +501,7 @@ update_current_target (void)
            (void (*) (void)) 
            noprocess);
   de_fault (deprecated_xfer_memory, 
-           (int (*) (CORE_ADDR, char *, int, int, struct mem_attrib *, struct target_ops *)) 
+           (int (*) (CORE_ADDR, gdb_byte *, int, int, struct mem_attrib *, struct target_ops *)) 
            nomemory);
   de_fault (to_files_info, 
            (void (*) (struct target_ops *)) 
@@ -512,10 +514,10 @@ update_current_target (void)
            (int (*) (int, int, int))
            return_zero);
   de_fault (to_insert_hw_breakpoint,
-           (int (*) (CORE_ADDR, char *))
+           (int (*) (CORE_ADDR, gdb_byte *))
            return_minus_one);
   de_fault (to_remove_hw_breakpoint,
-           (int (*) (CORE_ADDR, char *))
+           (int (*) (CORE_ADDR, gdb_byte *))
            return_minus_one);
   de_fault (to_insert_watchpoint,
            (int (*) (CORE_ADDR, int, int))
@@ -765,7 +767,7 @@ int
 target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
 {
   int tlen, origlen, offset, i;
-  char buf[4];
+  gdb_byte buf[4];
   int errcode = 0;
   char *buffer;
   int buffer_allocated;
@@ -784,7 +786,7 @@ target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
       tlen = MIN (len, 4 - (memaddr & 3));
       offset = memaddr & 3;
 
-      errcode = target_read_memory (memaddr & ~3, buf, 4);
+      errcode = target_read_memory (memaddr & ~3, buf, sizeof buf);
       if (errcode != 0)
        {
          /* The transfer request might have crossed the boundary to an
@@ -960,9 +962,9 @@ xfer_using_stratum (enum target_object object, const char *annex,
            return 0;
          offset += xfered;
          if (readbuf != NULL)
-           readbuf = (bfd_byte *) readbuf + xfered;
+           readbuf = (gdb_byte *) readbuf + xfered;
          if (writebuf != NULL)
-           writebuf = (bfd_byte *) writebuf + xfered;
+           writebuf = (gdb_byte *) writebuf + xfered;
          target = target_stack;
        }
       else if (xfered < 0)
@@ -995,7 +997,7 @@ xfer_using_stratum (enum target_object object, const char *annex,
    deal with partial reads should call target_read_memory_partial. */
 
 int
-target_read_memory (CORE_ADDR memaddr, bfd_byte *myaddr, int len)
+target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
 {
   if (target_xfer_partial_p ())
     return xfer_using_stratum (TARGET_OBJECT_MEMORY, NULL,
@@ -1005,9 +1007,9 @@ target_read_memory (CORE_ADDR memaddr, bfd_byte *myaddr, int len)
 }
 
 int
-target_write_memory (CORE_ADDR memaddr, const bfd_byte *myaddr, int len)
+target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
 {
-  bfd_byte *bytes = alloca (len);
+  gdb_byte *bytes = alloca (len);
   memcpy (bytes, myaddr, len);
   if (target_xfer_partial_p ())
     return xfer_using_stratum (TARGET_OBJECT_MEMORY, NULL,
@@ -1032,6 +1034,14 @@ target_stopped_data_address_p (struct target_ops *target)
 #endif
 
 static int trust_readonly = 0;
+static void
+show_trust_readonly (struct ui_file *file, int from_tty,
+                    struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("\
+Mode for reading from readonly sections is %s.\n"),
+                   value);
+}
 
 /* Move memory to or from the targets.  The top target gets priority;
    if it cannot handle it, it is offered to the next one down, etc.
@@ -1039,7 +1049,7 @@ static int trust_readonly = 0;
    Result is -1 on error, or the number of bytes transfered.  */
 
 int
-do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
+do_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
                struct mem_attrib *attrib)
 {
   int res;
@@ -1100,7 +1110,7 @@ do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
    Result is 0 or errno value.  */
 
 static int
-target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write)
+target_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write)
 {
   int res;
   int reg_len;
@@ -1137,7 +1147,7 @@ target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write)
        {
          if (region->attrib.cache)
            res = dcache_xfer_memory (target_dcache, memaddr, myaddr,
-                                    reg_len, write);
+                                     reg_len, write);
          else
            res = do_xfer_memory (memaddr, myaddr, reg_len, write,
                                 &region->attrib);
@@ -1235,8 +1245,26 @@ int
 target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
 {
   if (target_xfer_partial_p ())
-    return target_xfer_partial (target_stack, TARGET_OBJECT_MEMORY, NULL,
-                               buf, NULL, memaddr, len);
+    {
+      int retval;
+
+      retval = target_xfer_partial (target_stack, TARGET_OBJECT_MEMORY,
+                                   NULL, buf, NULL, memaddr, len);
+
+      if (retval <= 0)
+       {
+         if (errno)
+           *err = errno;
+         else
+           *err = EIO;
+         return -1;
+       }
+      else
+       {
+         *err = 0;
+         return retval;
+       }
+    }
   else
     return target_xfer_memory_partial (memaddr, buf, len, 0, err);
 }
@@ -1245,8 +1273,26 @@ int
 target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
 {
   if (target_xfer_partial_p ())
-    return target_xfer_partial (target_stack, TARGET_OBJECT_MEMORY, NULL,
-                               NULL, buf, memaddr, len);
+    {
+      int retval;
+
+      retval = target_xfer_partial (target_stack, TARGET_OBJECT_MEMORY,
+                                   NULL, NULL, buf, memaddr, len);
+
+      if (retval <= 0)
+       {
+         if (errno)
+           *err = errno;
+         else
+           *err = EIO;
+         return -1;
+       }
+      else
+       {
+         *err = 0;
+         return retval;
+       }
+    }
   else
     return target_xfer_memory_partial (memaddr, buf, len, 1, err);
 }
@@ -1255,8 +1301,8 @@ target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
 
 static LONGEST
 default_xfer_partial (struct target_ops *ops, enum target_object object,
-                     const char *annex, void *readbuf, 
-                     const void *writebuf, ULONGEST offset, LONGEST len)
+                     const char *annex, gdb_byte *readbuf, 
+                     const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
 {
   if (object == TARGET_OBJECT_MEMORY
       && ops->deprecated_xfer_memory != NULL)
@@ -1302,7 +1348,7 @@ default_xfer_partial (struct target_ops *ops, enum target_object object,
 LONGEST
 target_read_partial (struct target_ops *ops,
                     enum target_object object,
-                    const char *annex, void *buf,
+                    const char *annex, gdb_byte *buf,
                     ULONGEST offset, LONGEST len)
 {
   return target_xfer_partial (ops, object, annex, buf, NULL, offset, len);
@@ -1311,7 +1357,7 @@ target_read_partial (struct target_ops *ops,
 LONGEST
 target_write_partial (struct target_ops *ops,
                      enum target_object object,
-                     const char *annex, const void *buf,
+                     const char *annex, const gdb_byte *buf,
                      ULONGEST offset, LONGEST len)
 {
   return target_xfer_partial (ops, object, annex, NULL, buf, offset, len);
@@ -1321,14 +1367,14 @@ target_write_partial (struct target_ops *ops,
 LONGEST
 target_read (struct target_ops *ops,
             enum target_object object,
-            const char *annex, void *buf,
+            const char *annex, gdb_byte *buf,
             ULONGEST offset, LONGEST len)
 {
   LONGEST xfered = 0;
   while (xfered < len)
     {
       LONGEST xfer = target_read_partial (ops, object, annex,
-                                         (bfd_byte *) buf + xfered,
+                                         (gdb_byte *) buf + xfered,
                                          offset + xfered, len - xfered);
       /* Call an observer, notifying them of the xfer progress?  */
       if (xfer <= 0)
@@ -1343,14 +1389,14 @@ target_read (struct target_ops *ops,
 LONGEST
 target_write (struct target_ops *ops,
              enum target_object object,
-             const char *annex, const void *buf,
+             const char *annex, const gdb_byte *buf,
              ULONGEST offset, LONGEST len)
 {
   LONGEST xfered = 0;
   while (xfered < len)
     {
       LONGEST xfer = target_write_partial (ops, object, annex,
-                                          (bfd_byte *) buf + xfered,
+                                          (gdb_byte *) buf + xfered,
                                           offset + xfered, len - xfered);
       /* Call an observer, notifying them of the xfer progress?  */
       if (xfer <= 0)
@@ -1365,7 +1411,7 @@ target_write (struct target_ops *ops,
 /* Memory transfer methods.  */
 
 void
-get_target_memory (struct target_ops *ops, CORE_ADDR addr, void *buf,
+get_target_memory (struct target_ops *ops, CORE_ADDR addr, gdb_byte *buf,
                   LONGEST len)
 {
   if (target_read (ops, TARGET_OBJECT_MEMORY, NULL, buf, addr, len)
@@ -1446,19 +1492,6 @@ target_disconnect (char *args, int from_tty)
   (current_target.to_disconnect) (args, from_tty);
 }
 
-void
-target_link (char *modname, CORE_ADDR *t_reloc)
-{
-  if (DEPRECATED_STREQ (current_target.to_shortname, "rombug"))
-    {
-      (current_target.to_lookup_symbol) (modname, t_reloc);
-      if (*t_reloc == 0)
-       error (_("Unable to link to %s and get relocation in rombug"), modname);
-    }
-  else
-    *t_reloc = (CORE_ADDR) -1;
-}
-
 int
 target_async_mask (int mask)
 {
@@ -1753,15 +1786,15 @@ store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
 int (*target_activity_function) (void);
 int target_activity_fd;
 \f
-/* Convert a normal process ID to a string.  Returns the string in a static
-   buffer.  */
+/* Convert a normal process ID to a string.  Returns the string in a
+   static buffer.  */
 
 char *
 normal_pid_to_str (ptid_t ptid)
 {
-  static char buf[30];
+  static char buf[32];
 
-  sprintf (buf, "process %d", PIDGET (ptid));
+  xsnprintf (buf, sizeof buf, "process %d", ptid_get_pid (ptid));
   return buf;
 }
 
@@ -1967,7 +2000,7 @@ debug_to_prepare_to_store (void)
 }
 
 static int
-deprecated_debug_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
+deprecated_debug_xfer_memory (CORE_ADDR memaddr, bfd_byte *myaddr, int len,
                              int write, struct mem_attrib *attrib,
                              struct target_ops *target)
 {
@@ -2016,7 +2049,7 @@ debug_to_files_info (struct target_ops *target)
 }
 
 static int
-debug_to_insert_breakpoint (CORE_ADDR addr, char *save)
+debug_to_insert_breakpoint (CORE_ADDR addr, gdb_byte *save)
 {
   int retval;
 
@@ -2030,7 +2063,7 @@ debug_to_insert_breakpoint (CORE_ADDR addr, char *save)
 }
 
 static int
-debug_to_remove_breakpoint (CORE_ADDR addr, char *save)
+debug_to_remove_breakpoint (CORE_ADDR addr, gdb_byte *save)
 {
   int retval;
 
@@ -2101,7 +2134,7 @@ debug_to_stopped_data_address (struct target_ops *target, CORE_ADDR *addr)
 }
 
 static int
-debug_to_insert_hw_breakpoint (CORE_ADDR addr, char *save)
+debug_to_insert_hw_breakpoint (CORE_ADDR addr, gdb_byte *save)
 {
   int retval;
 
@@ -2115,7 +2148,7 @@ debug_to_insert_hw_breakpoint (CORE_ADDR addr, char *save)
 }
 
 static int
-debug_to_remove_hw_breakpoint (CORE_ADDR addr, char *save)
+debug_to_remove_hw_breakpoint (CORE_ADDR addr, gdb_byte *save)
 {
   int retval;
 
@@ -2552,14 +2585,15 @@ initialize_targets (void)
   add_info ("target", target_info, targ_desc);
   add_info ("files", target_info, targ_desc);
 
-  deprecated_add_show_from_set 
-    (add_set_cmd ("target", class_maintenance, var_zinteger,
-                 (char *) &targetdebug,
-                 "Set target debugging.\n\
+  add_setshow_zinteger_cmd ("target", class_maintenance, &targetdebug, _("\
+Set target debugging."), _("\
+Show target debugging."), _("\
 When non-zero, target debugging is enabled.  Higher numbers are more\n\
 verbose.  Changes do not take effect until the next \"run\" or \"target\"\n\
-command.", &setdebuglist),
-     &showdebuglist);
+command."),
+                           NULL,
+                           show_targetdebug,
+                           &setdebuglist, &showdebuglist);
 
   add_setshow_boolean_cmd ("trust-readonly-sections", class_support, 
                           &trust_readonly, _("\
@@ -2569,7 +2603,7 @@ When this mode is on, memory reads from readonly sections (such as .text)\n\
 will be read from the object file instead of from the target.  This will\n\
 result in significant performance improvement for remote targets."),
                           NULL,
-                          NULL, /* FIXME: i18n: Mode for reading from readonly sections is %s.  */
+                          show_trust_readonly,
                           &setlist, &showlist);
 
   add_com ("monitor", class_obscure, do_monitor_command,
This page took 0.029414 seconds and 4 git commands to generate.