* ppc-linux-nat.c (PTRACE_GET_DEBUGREG, PTRACE_SET_DEBUGREG,
[deliverable/binutils-gdb.git] / gdb / target.c
index dfe942775c9ec69987f4ce3b50ad71fab494c57c..d542bbf1c1047a0b4b5aee0ea6a71a8d522d8f39 100644 (file)
@@ -1,7 +1,8 @@
 /* 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, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+   Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.
 
@@ -19,8 +20,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
 
 #include "defs.h"
 #include <errno.h>
@@ -47,6 +48,8 @@ static void kill_or_be_killed (int);
 
 static void default_terminal_info (char *, int);
 
+static int default_region_ok_for_hw_watchpoint (CORE_ADDR, int);
+
 static int default_region_size_ok_for_hw_watchpoint (int);
 
 static int nosymbol (char *, CORE_ADDR *);
@@ -128,6 +131,8 @@ static int debug_to_stopped_by_watchpoint (void);
 
 static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *);
 
+static int debug_to_region_ok_for_hw_watchpoint (CORE_ADDR, int);
+
 static int debug_to_region_size_ok_for_hw_watchpoint (int);
 
 static void debug_to_terminal_init (void);
@@ -405,6 +410,7 @@ update_current_target (void)
       INHERIT (to_stopped_data_address, t);
       INHERIT (to_stopped_by_watchpoint, t);
       INHERIT (to_have_continuable_watchpoint, t);
+      INHERIT (to_region_ok_for_hw_watchpoint, t);
       INHERIT (to_region_size_ok_for_hw_watchpoint, t);
       INHERIT (to_terminal_init, t);
       INHERIT (to_terminal_inferior, t);
@@ -422,7 +428,7 @@ update_current_target (void)
       INHERIT (to_remove_fork_catchpoint, t);
       INHERIT (to_insert_vfork_catchpoint, t);
       INHERIT (to_remove_vfork_catchpoint, t);
-      INHERIT (to_follow_fork, t);
+      /* Do not inherit to_follow_fork.  */
       INHERIT (to_insert_exec_catchpoint, t);
       INHERIT (to_remove_exec_catchpoint, t);
       INHERIT (to_reported_exec_events_per_exec_call, t);
@@ -531,6 +537,8 @@ update_current_target (void)
   de_fault (to_stopped_data_address,
            (int (*) (struct target_ops *, CORE_ADDR *))
            return_zero);
+  de_fault (to_region_ok_for_hw_watchpoint,
+           default_region_ok_for_hw_watchpoint);
   de_fault (to_region_size_ok_for_hw_watchpoint,
            default_region_size_ok_for_hw_watchpoint);
   de_fault (to_terminal_init, 
@@ -579,9 +587,6 @@ update_current_target (void)
   de_fault (to_remove_vfork_catchpoint, 
            (int (*) (int)) 
            tcomplain);
-  de_fault (to_follow_fork,
-           (int (*) (int)) 
-           target_ignore);
   de_fault (to_insert_exec_catchpoint, 
            (void (*) (int)) 
            tcomplain);
@@ -1178,10 +1183,11 @@ target_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write)
 
 /* Perform a partial memory transfer.
 
-   Result is -1 on error, or the number of bytes transfered.  */
+   If we succeed, set *ERR to zero and return the number of bytes transferred.
+   If we fail, set *ERR to a non-zero errno value, and return -1.  */
 
 static int
-target_xfer_memory_partial (CORE_ADDR memaddr, char *myaddr, int len,
+target_xfer_memory_partial (CORE_ADDR memaddr, gdb_byte *myaddr, int len,
                            int write_p, int *err)
 {
   int res;
@@ -1242,7 +1248,8 @@ target_xfer_memory_partial (CORE_ADDR memaddr, char *myaddr, int len,
 }
 
 int
-target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
+target_read_memory_partial (CORE_ADDR memaddr, gdb_byte *buf,
+                           int len, int *err)
 {
   if (target_xfer_partial_p ())
     {
@@ -1270,7 +1277,8 @@ target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
 }
 
 int
-target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
+target_write_memory_partial (CORE_ADDR memaddr, gdb_byte *buf,
+                            int len, int *err)
 {
   if (target_xfer_partial_p ())
     {
@@ -1423,7 +1431,7 @@ ULONGEST
 get_target_memory_unsigned (struct target_ops *ops,
                            CORE_ADDR addr, int len)
 {
-  char buf[sizeof (ULONGEST)];
+  gdb_byte buf[sizeof (ULONGEST)];
 
   gdb_assert (len <= sizeof (buf));
   get_target_memory (ops, addr, buf, len);
@@ -1500,6 +1508,31 @@ target_async_mask (int mask)
   return saved_async_masked_status;
 }
 
+/* Look through the list of possible targets for a target that can
+   follow forks.  */
+
+int
+target_follow_fork (int follow_child)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    {
+      if (t->to_follow_fork != NULL)
+       {
+         int retval = t->to_follow_fork (t, follow_child);
+         if (targetdebug)
+           fprintf_unfiltered (gdb_stdlog, "target_follow_fork (%d) = %d\n",
+                               follow_child, retval);
+         return retval;
+       }
+    }
+
+  /* Some target returned a fork event, but did not know how to follow it.  */
+  internal_error (__FILE__, __LINE__,
+                 "could not find a target to follow fork");
+}
+
 /* Look through the list of possible targets for a target that can
    execute a run or attach command without any other data.  This is
    used to locate the default process stratum.
@@ -1552,6 +1585,12 @@ find_default_create_inferior (char *exec_file, char *allargs, char **env,
   return;
 }
 
+static int
+default_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
+{
+  return TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (len);
+}
+
 static int
 default_region_size_ok_for_hw_watchpoint (int byte_count)
 {
@@ -1793,10 +1832,8 @@ char *
 normal_pid_to_str (ptid_t ptid)
 {
   static char buf[32];
-  int size;
 
-  size = snprintf (buf, sizeof buf, "process %d", ptid_get_pid (ptid));
-  gdb_assert (size < sizeof buf);
+  xsnprintf (buf, sizeof buf, "process %d", ptid_get_pid (ptid));
   return buf;
 }
 
@@ -2094,6 +2131,21 @@ debug_to_can_use_hw_breakpoint (int type, int cnt, int from_tty)
   return retval;
 }
 
+static int
+debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
+{
+  CORE_ADDR retval;
+
+  retval = debug_target.to_region_ok_for_hw_watchpoint (addr, len);
+
+  fprintf_unfiltered (gdb_stdlog,
+                     "TARGET_REGION_OK_FOR_HW_WATCHPOINT (%ld, %ld) = 0x%lx\n",
+                     (unsigned long) addr,
+                     (unsigned long) len,
+                     (unsigned long) retval);
+  return retval;
+}
+
 static int
 debug_to_region_size_ok_for_hw_watchpoint (int byte_count)
 {
@@ -2338,17 +2390,6 @@ debug_to_remove_vfork_catchpoint (int pid)
   return retval;
 }
 
-static int
-debug_to_follow_fork (int follow_child)
-{
-  int retval =  debug_target.to_follow_fork (follow_child);
-
-  fprintf_unfiltered (gdb_stdlog, "target_follow_fork (%d) = %d\n",
-                     follow_child, retval);
-
-  return retval;
-}
-
 static void
 debug_to_insert_exec_catchpoint (int pid)
 {
@@ -2524,6 +2565,7 @@ setup_target_debug (void)
   current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
   current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
   current_target.to_stopped_data_address = debug_to_stopped_data_address;
+  current_target.to_region_ok_for_hw_watchpoint = debug_to_region_ok_for_hw_watchpoint;
   current_target.to_region_size_ok_for_hw_watchpoint = debug_to_region_size_ok_for_hw_watchpoint;
   current_target.to_terminal_init = debug_to_terminal_init;
   current_target.to_terminal_inferior = debug_to_terminal_inferior;
@@ -2541,7 +2583,6 @@ setup_target_debug (void)
   current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
   current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
   current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
-  current_target.to_follow_fork = debug_to_follow_fork;
   current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
   current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
   current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call;
This page took 0.029529 seconds and 4 git commands to generate.