Add target_ops argument to to_close
[deliverable/binutils-gdb.git] / gdb / target.c
index f08dad0add7a7c7ee39088a4026787b8b3387df8..e63725af6702424ff9ae87861de9460d3be6c178 100644 (file)
@@ -74,11 +74,15 @@ static struct target_ops *find_default_run_target (char *);
 
 static target_xfer_partial_ftype default_xfer_partial;
 
-static target_xfer_partial_ftype current_xfer_partial;
-
 static struct gdbarch *default_thread_architecture (struct target_ops *ops,
                                                    ptid_t ptid);
 
+static int find_default_can_async_p (struct target_ops *ignore);
+
+static int find_default_is_async_p (struct target_ops *ignore);
+
+#include "target-delegates.c"
+
 static void init_dummy_target (void);
 
 static struct target_ops debug_target;
@@ -110,8 +114,6 @@ static int debug_to_insert_watchpoint (CORE_ADDR, int, int,
 static int debug_to_remove_watchpoint (CORE_ADDR, int, int,
                                       struct expression *);
 
-static int debug_to_stopped_by_watchpoint (void);
-
 static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *);
 
 static int debug_to_watchpoint_addr_within_range (struct target_ops *,
@@ -355,6 +357,8 @@ complete_target_initialization (struct target_ops *t)
 
   if (t->to_has_execution == NULL)
     t->to_has_execution = (int (*) (struct target_ops *, ptid_t)) return_zero;
+
+  install_delegators (t);
 }
 
 /* Add possible target architecture T to the list and add a new
@@ -562,6 +566,9 @@ update_current_target (void)
   /* First, reset current's contents.  */
   memset (&current_target, 0, sizeof (current_target));
 
+  /* Install the delegators.  */
+  install_delegators (&current_target);
+
 #define INHERIT(FIELD, TARGET) \
       if (!current_target.FIELD) \
        current_target.FIELD = (TARGET)->FIELD
@@ -595,10 +602,10 @@ update_current_target (void)
       INHERIT (to_remove_watchpoint, t);
       /* Do not inherit to_insert_mask_watchpoint.  */
       /* Do not inherit to_remove_mask_watchpoint.  */
-      INHERIT (to_stopped_data_address, t);
+      /* Do not inherit to_stopped_data_address.  */
       INHERIT (to_have_steppable_watchpoint, t);
       INHERIT (to_have_continuable_watchpoint, t);
-      INHERIT (to_stopped_by_watchpoint, t);
+      /* Do not inherit to_stopped_by_watchpoint.  */
       INHERIT (to_watchpoint_addr_within_range, t);
       INHERIT (to_region_ok_for_hw_watchpoint, t);
       INHERIT (to_can_accel_watchpoint_condition, t);
@@ -643,9 +650,9 @@ update_current_target (void)
       /* Do not inherit to_has_registers.  */
       /* Do not inherit to_has_execution.  */
       INHERIT (to_has_thread_control, t);
-      INHERIT (to_can_async_p, t);
-      INHERIT (to_is_async_p, t);
-      INHERIT (to_async, t);
+      /* Do not inherit to_can_async_p.  */
+      /* Do not inherit to_is_async_p.  */
+      /* Do not inherit to_async.  */
       INHERIT (to_find_memory_regions, t);
       INHERIT (to_make_corefile_notes, t);
       INHERIT (to_get_bookmark, t);
@@ -711,7 +718,7 @@ update_current_target (void)
            (void (*) (char *, int))
            tcomplain);
   de_fault (to_close,
-           (void (*) (void))
+           (void (*) (struct target_ops *))
            target_ignore);
   de_fault (to_post_attach,
            (void (*) (int))
@@ -741,12 +748,6 @@ update_current_target (void)
   de_fault (to_remove_watchpoint,
            (int (*) (CORE_ADDR, int, int, struct expression *))
            return_minus_one);
-  de_fault (to_stopped_by_watchpoint,
-           (int (*) (void))
-           return_zero);
-  de_fault (to_stopped_data_address,
-           (int (*) (struct target_ops *, CORE_ADDR *))
-           return_zero);
   de_fault (to_watchpoint_addr_within_range,
            default_watchpoint_addr_within_range);
   de_fault (to_region_ok_for_hw_watchpoint,
@@ -812,16 +813,12 @@ update_current_target (void)
   de_fault (to_stop,
            (void (*) (ptid_t))
            target_ignore);
-  current_target.to_xfer_partial = current_xfer_partial;
   de_fault (to_rcmd,
            (void (*) (char *, struct ui_file *))
            tcomplain);
   de_fault (to_pid_to_exec_file,
            (char *(*) (int))
            return_null);
-  de_fault (to_async,
-           (void (*) (void (*) (enum inferior_event_type, void*), void*))
-           tcomplain);
   de_fault (to_thread_architecture,
            default_thread_architecture);
   current_target.to_read_description = NULL;
@@ -2035,30 +2032,13 @@ default_xfer_partial (struct target_ops *ops, enum target_object object,
       else
        return TARGET_XFER_E_IO;
     }
-  else if (ops->beneath != NULL)
-    return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
-                                         readbuf, writebuf, offset, len,
-                                         xfered_len);
   else
-    return TARGET_XFER_E_IO;
-}
-
-/* The xfer_partial handler for the topmost target.  Unlike the default,
-   it does not need to handle memory specially; it just passes all
-   requests down the stack.  */
-
-static enum target_xfer_status
-current_xfer_partial (struct target_ops *ops, enum target_object object,
-                     const char *annex, gdb_byte *readbuf,
-                     const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
-                     ULONGEST *xfered_len)
-{
-  if (ops->beneath != NULL)
-    return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
-                                         readbuf, writebuf, offset, len,
-                                         xfered_len);
-  else
-    return TARGET_XFER_E_IO;
+    {
+      gdb_assert (ops->beneath != NULL);
+      return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
+                                           readbuf, writebuf, offset, len,
+                                           xfered_len);
+    }
 }
 
 /* Target vector read/write partial wrapper functions.  */
@@ -2074,7 +2054,7 @@ target_read_partial (struct target_ops *ops,
                              xfered_len);
 }
 
-static LONGEST
+static enum target_xfer_status
 target_write_partial (struct target_ops *ops,
                      enum target_object object,
                      const char *annex, const gdb_byte *buf,
@@ -2522,20 +2502,6 @@ get_target_memory_unsigned (struct target_ops *ops, CORE_ADDR addr,
 
 /* See target.h.  */
 
-int
-forward_target_insert_breakpoint (struct target_ops *ops,
-                                 struct gdbarch *gdbarch,
-                                 struct bp_target_info *bp_tgt)
-{
-  for (; ops != NULL; ops = ops->beneath)
-    if (ops->to_insert_breakpoint != NULL)
-      return ops->to_insert_breakpoint (ops, gdbarch, bp_tgt);
-
-  return memory_insert_breakpoint (ops, gdbarch, bp_tgt);
-}
-
-/* See target.h.  */
-
 int
 target_insert_breakpoint (struct gdbarch *gdbarch,
                          struct bp_target_info *bp_tgt)
@@ -2546,15 +2512,15 @@ target_insert_breakpoint (struct gdbarch *gdbarch,
       return 1;
     }
 
-  return forward_target_insert_breakpoint (&current_target, gdbarch, bp_tgt);
+  return current_target.to_insert_breakpoint (&current_target,
+                                             gdbarch, bp_tgt);
 }
 
 /* See target.h.  */
 
 int
-forward_target_remove_breakpoint (struct target_ops *ops,
-                                 struct gdbarch *gdbarch,
-                                 struct bp_target_info *bp_tgt)
+target_remove_breakpoint (struct gdbarch *gdbarch,
+                         struct bp_target_info *bp_tgt)
 {
   /* This is kind of a weird case to handle, but the permission might
      have been changed after breakpoints were inserted - in which case
@@ -2566,20 +2532,8 @@ forward_target_remove_breakpoint (struct target_ops *ops,
       return 1;
     }
 
-  for (; ops != NULL; ops = ops->beneath)
-    if (ops->to_remove_breakpoint != NULL)
-      return ops->to_remove_breakpoint (ops, gdbarch, bp_tgt);
-
-  return memory_remove_breakpoint (ops, gdbarch, bp_tgt);
-}
-
-/* See target.h.  */
-
-int
-target_remove_breakpoint (struct gdbarch *gdbarch,
-                         struct bp_target_info *bp_tgt)
-{
-  return forward_target_remove_breakpoint (&current_target, gdbarch, bp_tgt);
+  return current_target.to_remove_breakpoint (&current_target,
+                                             gdbarch, bp_tgt);
 }
 
 static void
@@ -2759,34 +2713,26 @@ ptid_t
 target_wait (ptid_t ptid, struct target_waitstatus *status, int options)
 {
   struct target_ops *t;
+  ptid_t retval = (current_target.to_wait) (&current_target, ptid,
+                                           status, options);
 
-  for (t = current_target.beneath; t != NULL; t = t->beneath)
+  if (targetdebug)
     {
-      if (t->to_wait != NULL)
-       {
-         ptid_t retval = (*t->to_wait) (t, ptid, status, options);
+      char *status_string;
+      char *options_string;
 
-         if (targetdebug)
-           {
-             char *status_string;
-             char *options_string;
-
-             status_string = target_waitstatus_to_string (status);
-             options_string = target_options_to_string (options);
-             fprintf_unfiltered (gdb_stdlog,
-                                 "target_wait (%d, status, options={%s})"
-                                 " = %d,   %s\n",
-                                 ptid_get_pid (ptid), options_string,
-                                 ptid_get_pid (retval), status_string);
-             xfree (status_string);
-             xfree (options_string);
-           }
-
-         return retval;
-       }
+      status_string = target_waitstatus_to_string (status);
+      options_string = target_options_to_string (options);
+      fprintf_unfiltered (gdb_stdlog,
+                         "target_wait (%d, status, options={%s})"
+                         " = %d,   %s\n",
+                         ptid_get_pid (ptid), options_string,
+                         ptid_get_pid (retval), status_string);
+      xfree (status_string);
+      xfree (options_string);
     }
 
-  noprocess ();
+  return retval;
 }
 
 char *
@@ -2824,26 +2770,17 @@ target_resume (ptid_t ptid, int step, enum gdb_signal signal)
 
   target_dcache_invalidate ();
 
-  for (t = current_target.beneath; t != NULL; t = t->beneath)
-    {
-      if (t->to_resume != NULL)
-       {
-         t->to_resume (t, ptid, step, signal);
-         if (targetdebug)
-           fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n",
-                               ptid_get_pid (ptid),
-                               step ? "step" : "continue",
-                               gdb_signal_to_name (signal));
-
-         registers_changed_ptid (ptid);
-         set_executing (ptid, 1);
-         set_running (ptid, 1);
-         clear_inline_frame_state (ptid);
-         return;
-       }
-    }
+  current_target.to_resume (&current_target, ptid, step, signal);
+  if (targetdebug)
+    fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n",
+                       ptid_get_pid (ptid),
+                       step ? "step" : "continue",
+                       gdb_signal_to_name (signal));
 
-  noprocess ();
+  registers_changed_ptid (ptid);
+  set_executing (ptid, 1);
+  set_running (ptid, 1);
+  clear_inline_frame_state (ptid);
 }
 
 void
@@ -3231,7 +3168,7 @@ find_default_create_inferior (struct target_ops *ops,
 }
 
 static int
-find_default_can_async_p (void)
+find_default_can_async_p (struct target_ops *ignore)
 {
   struct target_ops *t;
 
@@ -3240,13 +3177,13 @@ find_default_can_async_p (void)
      configured with a native debugger, and target remote isn't
      connected yet.  */
   t = find_default_run_target (NULL);
-  if (t && t->to_can_async_p)
-    return (t->to_can_async_p) ();
+  if (t && t->to_can_async_p != delegate_can_async_p)
+    return (t->to_can_async_p) (t);
   return 0;
 }
 
 static int
-find_default_is_async_p (void)
+find_default_is_async_p (struct target_ops *ignore)
 {
   struct target_ops *t;
 
@@ -3255,8 +3192,8 @@ find_default_is_async_p (void)
      configured with a native debugger, and target remote isn't
      connected yet.  */
   t = find_default_run_target (NULL);
-  if (t && t->to_is_async_p)
-    return (t->to_is_async_p) ();
+  if (t && t->to_is_async_p != delegate_is_async_p)
+    return (t->to_is_async_p) (t);
   return 0;
 }
 
@@ -3748,6 +3685,20 @@ find_target_beneath (struct target_ops *t)
   return t->beneath;
 }
 
+/* See target.h.  */
+
+struct target_ops *
+find_target_at (enum strata stratum)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    if (t->to_stratum == stratum)
+      return t;
+
+  return NULL;
+}
+
 \f
 /* The inferior process has died.  Long live the inferior!  */
 
@@ -3846,8 +3797,6 @@ init_dummy_target (void)
   dummy_target.to_detach = 
     (void (*)(struct target_ops *, const char *, int))target_ignore;
   dummy_target.to_create_inferior = find_default_create_inferior;
-  dummy_target.to_can_async_p = find_default_can_async_p;
-  dummy_target.to_is_async_p = find_default_is_async_p;
   dummy_target.to_supports_non_stop = find_default_supports_non_stop;
   dummy_target.to_supports_disable_randomization
     = find_default_supports_disable_randomization;
@@ -3857,17 +3806,15 @@ init_dummy_target (void)
   dummy_target.to_make_corefile_notes = dummy_make_corefile_notes;
   dummy_target.to_get_bookmark = dummy_get_bookmark;
   dummy_target.to_goto_bookmark = dummy_goto_bookmark;
-  dummy_target.to_xfer_partial = default_xfer_partial;
   dummy_target.to_has_all_memory = (int (*) (struct target_ops *)) return_zero;
   dummy_target.to_has_memory = (int (*) (struct target_ops *)) return_zero;
   dummy_target.to_has_stack = (int (*) (struct target_ops *)) return_zero;
   dummy_target.to_has_registers = (int (*) (struct target_ops *)) return_zero;
   dummy_target.to_has_execution
     = (int (*) (struct target_ops *, ptid_t)) return_zero;
-  dummy_target.to_stopped_by_watchpoint = return_zero;
-  dummy_target.to_stopped_data_address =
-    (int (*) (struct target_ops *, CORE_ADDR *)) return_zero;
   dummy_target.to_magic = OPS_MAGIC;
+
+  install_dummy_methods (&dummy_target);
 }
 \f
 static void
@@ -3886,7 +3833,7 @@ target_close (struct target_ops *targ)
   if (targ->to_xclose != NULL)
     targ->to_xclose (targ);
   else if (targ->to_close != NULL)
-    targ->to_close ();
+    targ->to_close (targ);
 
   if (targetdebug)
     fprintf_unfiltered (gdb_stdlog, "target_close ()\n");
@@ -4084,20 +4031,11 @@ target_store_registers (struct regcache *regcache, int regno)
   if (!may_write_registers)
     error (_("Writing to registers is not allowed (regno %d)"), regno);
 
-  for (t = current_target.beneath; t != NULL; t = t->beneath)
+  current_target.to_store_registers (&current_target, regcache, regno);
+  if (targetdebug)
     {
-      if (t->to_store_registers != NULL)
-       {
-         t->to_store_registers (t, regcache, regno);
-         if (targetdebug)
-           {
-             debug_print_register ("target_store_registers", regcache, regno);
-           }
-         return;
-       }
+      debug_print_register ("target_store_registers", regcache, regno);
     }
-
-  noprocess ();
 }
 
 int
@@ -4232,20 +4170,6 @@ target_ranged_break_num_registers (void)
 
 /* See target.h.  */
 
-int
-target_supports_btrace (void)
-{
-  struct target_ops *t;
-
-  for (t = current_target.beneath; t != NULL; t = t->beneath)
-    if (t->to_supports_btrace != NULL)
-      return t->to_supports_btrace ();
-
-  return 0;
-}
-
-/* See target.h.  */
-
 struct btrace_target_info *
 target_enable_btrace (ptid_t ptid)
 {
@@ -4671,7 +4595,7 @@ debug_to_insert_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
 {
   int retval;
 
-  retval = forward_target_insert_breakpoint (&debug_target, gdbarch, bp_tgt);
+  retval = debug_target.to_insert_breakpoint (&debug_target, gdbarch, bp_tgt);
 
   fprintf_unfiltered (gdb_stdlog,
                      "target_insert_breakpoint (%s, xxx) = %ld\n",
@@ -4686,7 +4610,7 @@ debug_to_remove_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
 {
   int retval;
 
-  retval = forward_target_remove_breakpoint (&debug_target, gdbarch, bp_tgt);
+  retval = debug_target.to_remove_breakpoint (&debug_target, gdbarch, bp_tgt);
 
   fprintf_unfiltered (gdb_stdlog,
                      "target_remove_breakpoint (%s, xxx) = %ld\n",
@@ -4743,11 +4667,11 @@ debug_to_can_accel_watchpoint_condition (CORE_ADDR addr, int len, int rw,
 }
 
 static int
-debug_to_stopped_by_watchpoint (void)
+debug_to_stopped_by_watchpoint (struct target_ops *ops)
 {
   int retval;
 
-  retval = debug_target.to_stopped_by_watchpoint ();
+  retval = debug_target.to_stopped_by_watchpoint (&debug_target);
 
   fprintf_unfiltered (gdb_stdlog,
                      "target_stopped_by_watchpoint () = %ld\n",
This page took 0.033763 seconds and 4 git commands to generate.