* ppc-linux-nat.c (store_register, fetch_register): Rename 'mess'
[deliverable/binutils-gdb.git] / gdb / target.c
index e99d9472d9632769e77b5e5d7345b3edfe33d510..97ab6a8bcdb02426c329fe6b48929d0d9a8fd2b4 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 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.
 
@@ -41,8 +41,6 @@
 
 static void target_info (char *, int);
 
-static void maybe_kill_then_create_inferior (char *, char *, char **);
-
 static void maybe_kill_then_attach (char *, int);
 
 static void kill_or_be_killed (int);
@@ -71,16 +69,11 @@ static struct target_ops *find_default_run_target (char *);
 
 static void nosupport_runtime (void);
 
-static void normal_target_post_startup_inferior (ptid_t ptid);
-
-static LONGEST default_read_partial (struct target_ops *ops,
+static LONGEST default_xfer_partial (struct target_ops *ops,
                                     enum target_object object,
-                                    const char *annex, void *buf,
+                                    const char *annex, void *readbuf,
+                                    const void *writebuf,
                                     ULONGEST offset, LONGEST len);
-static LONGEST default_write_partial (struct target_ops *ops,
-                                     enum target_object object,
-                                     const char *annex, const void *buf,
-                                     ULONGEST offset, LONGEST len);
 
 /* Transfer LEN bytes between target address MEMADDR and GDB address
    MYADDR.  Returns 0 for success, errno code for failure (which
@@ -156,8 +149,6 @@ static void debug_to_load (char *, int);
 
 static int debug_to_lookup_symbol (char *, CORE_ADDR *);
 
-static void debug_to_create_inferior (char *, char *, char **);
-
 static void debug_to_mourn_inferior (void);
 
 static int debug_to_can_run (void);
@@ -223,8 +214,8 @@ void
 add_target (struct target_ops *t)
 {
   /* Provide default values for all "must have" methods.  */
-  t->to_read_partial = default_read_partial;
-  t->to_write_partial = default_write_partial;
+  if (t->to_xfer_partial == NULL)
+    t->to_xfer_partial = default_xfer_partial;
 
   if (!target_structs)
     {
@@ -344,10 +335,11 @@ maybe_kill_then_attach (char *args, int from_tty)
 }
 
 static void
-maybe_kill_then_create_inferior (char *exec, char *args, char **env)
+maybe_kill_then_create_inferior (char *exec, char *args, char **env,
+                                int from_tty)
 {
   kill_or_be_killed (0);
-  target_create_inferior (exec, args, env);
+  target_create_inferior (exec, args, env, from_tty);
 }
 
 /* Go through the target stack from top to bottom, copying over zero
@@ -433,8 +425,7 @@ update_current_target (void)
       INHERIT (to_pid_to_str, t);
       INHERIT (to_extra_thread_info, t);
       INHERIT (to_stop, t);
-      /* Do not inherit to_read_partial.  */
-      /* Do not inherit to_write_partial.  */
+      /* Do not inherit to_xfer_partial.  */
       INHERIT (to_rcmd, t);
       INHERIT (to_enable_exception_callback, t);
       INHERIT (to_get_current_exception_event, t);
@@ -616,8 +607,7 @@ update_current_target (void)
   de_fault (to_stop, 
            (void (*) (void)) 
            target_ignore);
-  current_target.to_read_partial = default_read_partial;
-  current_target.to_write_partial = default_write_partial;
+  current_target.to_xfer_partial = default_xfer_partial;
   de_fault (to_rcmd, 
            (void (*) (char *, struct ui_file *)) 
            tcomplain);
@@ -714,8 +704,6 @@ unpush_target (struct target_ops *t)
   struct target_ops **cur;
   struct target_ops *tmp;
 
-  target_close (t, 0);
-
   /* Look for the specified target.  Note that we assume that a target
      can only occur once in the target stack. */
 
@@ -728,6 +716,14 @@ unpush_target (struct target_ops *t)
   if ((*cur) == NULL)
     return 0;                  /* Didn't find target_ops, quit now */
 
+  /* NOTE: cagney/2003-12-06: In '94 the close call was made
+     unconditional by moving it to before the above check that the
+     target was in the target stack (something about "Change the way
+     pushing and popping of targets work to support target overlays
+     and inheritance").  This doesn't make much sense - only open
+     targets should be closed.  */
+  target_close (t, 0);
+
   /* Unchain the target */
   tmp = (*cur);
   (*cur) = (*cur)->beneath;
@@ -1079,55 +1075,29 @@ target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
 /* More generic transfers.  */
 
 static LONGEST
-default_read_partial (struct target_ops *ops,
-                     enum target_object object,
-                     const char *annex, void *buf,
-                     ULONGEST offset, LONGEST len)
+default_xfer_partial (struct target_ops *ops, enum target_object object,
+                     const char *annex, void *readbuf, 
+                     const void *writebuf, ULONGEST offset, LONGEST len)
 {
   if (object == TARGET_OBJECT_MEMORY
       && ops->to_xfer_memory != NULL)
     /* If available, fall back to the target's "to_xfer_memory"
        method.  */
     {
-      int xfered;
+      int xfered = -1;
       errno = 0;
-      xfered = ops->to_xfer_memory (offset, buf, len, 0/*read*/, NULL, ops);
-      if (xfered > 0)
-       return xfered;
-      else if (xfered == 0 && errno == 0)
-       /* "to_xfer_memory" uses 0, cross checked against ERRNO as one
-           indication of an error.  */
-       return 0;
-      else
-       return -1;
-    }
-  else if (ops->beneath != NULL)
-    return target_read_partial (ops->beneath, object, annex, buf, offset, len);
-  else
-    return -1;
-}
-
-static LONGEST
-default_write_partial (struct target_ops *ops,
-                      enum target_object object,
-                      const char *annex, const void *buf,
-                      ULONGEST offset, LONGEST len)
-{
-  if (object == TARGET_OBJECT_MEMORY
-      && ops->to_xfer_memory != NULL)
-    /* If available, fall back to the target's "to_xfer_memory"
-       method.  */
-    {
-      int xfered;
-      errno = 0;
-      {
-       void *buffer = xmalloc (len);
-       struct cleanup *cleanup = make_cleanup (xfree, buffer);
-       memcpy (buffer, buf, len);
-       xfered = ops->to_xfer_memory (offset, buffer, len, 1/*write*/, NULL,
+      if (writebuf != NULL)
+       {
+         void *buffer = xmalloc (len);
+         struct cleanup *cleanup = make_cleanup (xfree, buffer);
+         memcpy (buffer, writebuf, len);
+         xfered = ops->to_xfer_memory (offset, buffer, len, 1/*write*/, NULL,
+                                       ops);
+         do_cleanups (cleanup);
+       }
+      if (readbuf != NULL)
+       xfered = ops->to_xfer_memory (offset, readbuf, len, 0/*read*/, NULL,
                                      ops);
-       do_cleanups (cleanup);
-      }
       if (xfered > 0)
        return xfered;
       else if (xfered == 0 && errno == 0)
@@ -1138,8 +1108,8 @@ default_write_partial (struct target_ops *ops,
        return -1;
     }
   else if (ops->beneath != NULL)
-    return target_write_partial (ops->beneath, object, annex, buf, offset,
-                                len);
+    return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
+                                         readbuf, writebuf, offset, len);
   else
     return -1;
 }
@@ -1156,8 +1126,8 @@ target_read_partial (struct target_ops *ops,
                     const char *annex, void *buf,
                     ULONGEST offset, LONGEST len)
 {
-  gdb_assert (ops->to_read_partial != NULL);
-  return ops->to_read_partial (ops, object, annex, buf, offset, len);
+  gdb_assert (ops->to_xfer_partial != NULL);
+  return ops->to_xfer_partial (ops, object, annex, buf, NULL, offset, len);
 }
 
 LONGEST
@@ -1166,8 +1136,8 @@ target_write_partial (struct target_ops *ops,
                      const char *annex, const void *buf,
                      ULONGEST offset, LONGEST len)
 {
-  gdb_assert (ops->to_write_partial != NULL);
-  return ops->to_write_partial (ops, object, annex, buf, offset, len);
+  gdb_assert (ops->to_xfer_partial != NULL);
+  return ops->to_xfer_partial (ops, object, annex, NULL, buf, offset, len);
 }
 
 /* Wrappers to perform the full transfer.  */
@@ -1295,27 +1265,19 @@ target_preopen (int from_tty)
 void
 target_detach (char *args, int from_tty)
 {
-  /* Handle any optimized stores to the inferior.  */
-#ifdef DO_DEFERRED_STORES
-  DO_DEFERRED_STORES;
-#endif
   (current_target.to_detach) (args, from_tty);
 }
 
 void
 target_disconnect (char *args, int from_tty)
 {
-  /* Handle any optimized stores to the inferior.  */
-#ifdef DO_DEFERRED_STORES
-  DO_DEFERRED_STORES;
-#endif
   (current_target.to_disconnect) (args, from_tty);
 }
 
 void
 target_link (char *modname, CORE_ADDR *t_reloc)
 {
-  if (STREQ (current_target.to_shortname, "rombug"))
+  if (DEPRECATED_STREQ (current_target.to_shortname, "rombug"))
     {
       (current_target.to_lookup_symbol) (modname, t_reloc);
       if (*t_reloc == 0)
@@ -1375,19 +1337,20 @@ find_default_attach (char *args, int from_tty)
 }
 
 void
-find_default_create_inferior (char *exec_file, char *allargs, char **env)
+find_default_create_inferior (char *exec_file, char *allargs, char **env,
+                             int from_tty)
 {
   struct target_ops *t;
 
   t = find_default_run_target ("run");
-  (t->to_create_inferior) (exec_file, allargs, env);
+  (t->to_create_inferior) (exec_file, allargs, env, from_tty);
   return;
 }
 
 static int
 default_region_size_ok_for_hw_watchpoint (int byte_count)
 {
-  return (byte_count <= DEPRECATED_REGISTER_SIZE);
+  return (byte_count <= TYPE_LENGTH (builtin_type_void_data_ptr));
 }
 
 static int
@@ -1578,8 +1541,8 @@ generic_mourn_inferior (void)
   if (!show_breakpoint_hit_counts)
     breakpoint_clear_ignore_counts ();
 
-  if (detach_hook)
-    detach_hook ();
+  if (deprecated_detach_hook)
+    deprecated_detach_hook ();
 }
 \f
 /* Helper function for child_wait and the Lynx derivatives of child_wait.
@@ -1628,24 +1591,6 @@ normal_pid_to_str (ptid_t ptid)
   return buf;
 }
 
-/* Some targets (such as ttrace-based HPUX) don't allow us to request
-   notification of inferior events such as fork and vork immediately
-   after the inferior is created.  (This because of how gdb gets an
-   inferior created via invoking a shell to do it.  In such a scenario,
-   if the shell init file has commands in it, the shell will fork and
-   exec for each of those commands, and we will see each such fork
-   event.  Very bad.)
-
-   This function is used by all targets that allow us to request
-   notification of forks, etc at inferior creation time; e.g., in
-   target_acknowledge_forked_child.
- */
-static void
-normal_target_post_startup_inferior (ptid_t ptid)
-{
-  /* This space intentionally left blank. */
-}
-
 /* Error-catcher for target_find_memory_regions */
 static int dummy_find_memory_regions (int (*ignore1) (), void *ignore2)
 {
@@ -1675,6 +1620,7 @@ init_dummy_target (void)
   dummy_target.to_stratum = dummy_stratum;
   dummy_target.to_find_memory_regions = dummy_find_memory_regions;
   dummy_target.to_make_corefile_notes = dummy_make_corefile_notes;
+  dummy_target.to_xfer_partial = default_xfer_partial;
   dummy_target.to_magic = OPS_MAGIC;
 }
 \f
@@ -1873,8 +1819,6 @@ debug_to_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
                      (unsigned int) memaddr,   /* possable truncate long long */
                      len, write ? "write" : "read", retval);
 
-
-
   if (retval > 0)
     {
       int i;
@@ -1883,7 +1827,15 @@ debug_to_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
       for (i = 0; i < retval; i++)
        {
          if ((((long) &(myaddr[i])) & 0xf) == 0)
-           fprintf_unfiltered (gdb_stdlog, "\n");
+           {
+             if (targetdebug < 2 && i > 0)
+               {
+                 fprintf_unfiltered (gdb_stdlog, " ...");
+                 break;
+               }
+             fprintf_unfiltered (gdb_stdlog, "\n");
+           }
+         
          fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
        }
     }
@@ -2117,12 +2069,13 @@ debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
 }
 
 static void
-debug_to_create_inferior (char *exec_file, char *args, char **env)
+debug_to_create_inferior (char *exec_file, char *args, char **env,
+                         int from_tty)
 {
-  debug_target.to_create_inferior (exec_file, args, env);
+  debug_target.to_create_inferior (exec_file, args, env, from_tty);
 
-  fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n",
-                     exec_file, args);
+  fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx, %d)\n",
+                     exec_file, args, from_tty);
 }
 
 static void
@@ -2318,40 +2271,19 @@ debug_to_stop (void)
 }
 
 static LONGEST
-debug_to_read_partial (struct target_ops *ops,
-                      enum target_object object,
-                      const char *annex, void *buf,
+debug_to_xfer_partial (struct target_ops *ops, enum target_object object,
+                      const char *annex, void *readbuf, const void *writebuf,
                       ULONGEST offset, LONGEST len)
 {
   LONGEST retval;
 
-  retval = target_read_partial (&debug_target, object, annex, buf, offset,
-                               len);
-
-  fprintf_unfiltered (gdb_stdlog,
-                     "target_read_partial (%d, %s, 0x%lx,  0x%s, %s) = %s\n",
-                     (int) object, (annex ? annex : "(null)"),
-                     (long) buf, paddr_nz (offset),
-                     paddr_d (len), paddr_d (retval));
-
-  return retval;
-}
-
-static LONGEST
-debug_to_write_partial (struct target_ops *ops,
-                       enum target_object object,
-                       const char *annex, const void *buf,
-                       ULONGEST offset, LONGEST len)
-{
-  LONGEST retval;
-
-  retval = target_write_partial (&debug_target, object, annex, buf, offset,
-                               len);
+  retval = debug_target.to_xfer_partial (&debug_target, object, annex,
+                                        readbuf, writebuf, offset, len);
 
   fprintf_unfiltered (gdb_stdlog,
-                     "target_write_partial (%d, %s, 0x%lx,  0x%s, %s) = %s\n",
+                     "target_xfer_partial (%d, %s, 0x%lx,  0x%lx,  0x%s, %s) = %s\n",
                      (int) object, (annex ? annex : "(null)"),
-                     (long) buf, paddr_nz (offset),
+                     (long) readbuf, (long) writebuf, paddr_nz (offset),
                      paddr_d (len), paddr_d (retval));
 
   return retval;
@@ -2454,8 +2386,7 @@ setup_target_debug (void)
   current_target.to_thread_alive = debug_to_thread_alive;
   current_target.to_find_new_threads = debug_to_find_new_threads;
   current_target.to_stop = debug_to_stop;
-  current_target.to_read_partial = debug_to_read_partial;
-  current_target.to_write_partial = debug_to_write_partial;
+  current_target.to_xfer_partial = debug_to_xfer_partial;
   current_target.to_rcmd = debug_to_rcmd;
   current_target.to_enable_exception_callback = debug_to_enable_exception_callback;
   current_target.to_get_current_exception_event = debug_to_get_current_exception_event;
@@ -2497,7 +2428,9 @@ initialize_targets (void)
     (add_set_cmd ("target", class_maintenance, var_zinteger,
                  (char *) &targetdebug,
                  "Set target debugging.\n\
-When non-zero, target debugging is enabled.", &setdebuglist),
+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);
 
   add_setshow_boolean_cmd ("trust-readonly-sections", class_support, 
This page took 0.049566 seconds and 4 git commands to generate.