[RFC v2 18/38] convert to_detach

Tom Tromey tromey@redhat.com
Thu Feb 6 21:42:00 GMT 2014


2014-02-06  Tom Tromey  <tromey@redhat.com>

	* target-delegates.c: Rebuild.
	* target.c (target_detach): Unconditionally delegate.
	(init_dummy_target): Don't initialize to_detach.
	* target.h (struct target_ops) <to_detach>: Use
	TARGET_DEFAULT_IGNORE.

convert to_attach

2014-02-06  Tom Tromey  <tromey@redhat.com>

	* target-delegates.c: Rebuild.
	* target.c (init_dummy_target): Don't initialize to_attach.
	(target_attach): Unconditionally delegate.
	* target.h (struct target_ops) <to_attach>: Use
	TARGET_DEFAULT_FUNC.

convert to_rcmd

2014-02-06  Tom Tromey  <tromey@redhat.com>

	* target-delegates.c: Rebuild.
	* target.c (update_current_target): Don't inherit or default
	to_rcmd.
	(default_rcmd): New function.
	(do_monitor_command): Unconditionally delegate.
	* target.h (struct target_ops) <to_rmcd>: Use
	TARGET_DEFAULT_FUNC.

convert to_post_attach

2014-02-06  Tom Tromey  <tromey@redhat.com>

	* target-delegates.c: Rebuild.
	* target.c (update_current_target): Don't inherit or default
	to_post_attach.
	* target.h (struct target_ops) <to_post_attach>: Use
	TARGET_DEFAULT_IGNORE.

convert to_prepare_to_store

2014-02-06  Tom Tromey  <tromey@redhat.com>

	* target-delegates.c: Rebuild.
	* target.c (update_current_target): Don't inherit or default
	to_store.
	* target.h (struct target_ops) <to_store>: Use
	TARGET_DEFAULT_NORETURN.

convert to_files_info

2014-02-06  Tom Tromey  <tromey@redhat.com>

	* target-delegates.c: Rebuild.
	* target.c (update_current_target): Don't inherit or default
	to_files_info.
	* target.h (struct target_ops) <to_files_info>: Use
	TARGET_DEFAULT_IGNORE.

convert to_can_use_hw_breakpoint

2014-02-06  Tom Tromey  <tromey@redhat.com>

	* target-delegates.c: Rebuild.
	* target.c (update_current_target): Don't inherit or default
	to_can_use_hw_breakpoint.
	* target.h (struct target_ops) <to_can_use_hw_breakpoint>: Use
	TARGET_DEFAULT_RETURN.

convert to_insert_hw_breakpoint

2014-02-06  Tom Tromey  <tromey@redhat.com>

	* target-delegates.c: Rebuild.
	* target.c (update_current_target): Don't inherit or default
	to_insert_hw_breakpoint.
	* target.h (struct target_ops) <to_insert_hw_breakpoint>: Use
	TARGET_DEFAULT_RETURN.

convert to_remove_hw_breakpoint

2014-02-06  Tom Tromey  <tromey@redhat.com>

	* target-delegates.c: Rebuild.
	* target.c (update_current_target): Don't inherit or default
	to_remove_hw_breakpoint.
	* target.h (struct target_ops) <to_remove_hw_breakpoint>: Use
	TARGET_DEFAULT_RETURN.

convert to_insert_watchpoint

2014-02-06  Tom Tromey  <tromey@redhat.com>

	* target-delegates.c: Rebuild.
	* target.c (update_current_target): Don't inherit or default
	to_insert_watchpoint.
	* target.h (struct target_ops) <to_insert_watchpoint>: Use
	TARGET_DEFAULT_RETURN.
---
 gdb/ChangeLog          |  82 ++++++++++++++++++++++++++++
 gdb/target-delegates.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/target.c           |  98 ++++++++-------------------------
 gdb/target.h           |  30 ++++++----
 4 files changed, 271 insertions(+), 84 deletions(-)

diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index a7877cc..6e26824 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -4,6 +4,37 @@
 /* To regenerate this file, run:*/
 /*      make-target-delegates target.h > target-delegates.c */
 static void
+delegate_attach (struct target_ops *self, char *arg1, int arg2)
+{
+  self = self->beneath;
+  self->to_attach (self, arg1, arg2);
+}
+
+static void
+delegate_post_attach (struct target_ops *self, int arg1)
+{
+  self = self->beneath;
+  self->to_post_attach (self, arg1);
+}
+
+static void
+tdefault_post_attach (struct target_ops *self, int arg1)
+{
+}
+
+static void
+delegate_detach (struct target_ops *self, const char *arg1, int arg2)
+{
+  self = self->beneath;
+  self->to_detach (self, arg1, arg2);
+}
+
+static void
+tdefault_detach (struct target_ops *self, const char *arg1, int arg2)
+{
+}
+
+static void
 delegate_resume (struct target_ops *self, ptid_t arg1, int arg2, enum gdb_signal arg3)
 {
   self = self->beneath;
@@ -42,6 +73,31 @@ tdefault_store_registers (struct target_ops *self, struct regcache *arg1, int ar
   noprocess ();
 }
 
+static void
+delegate_prepare_to_store (struct target_ops *self, struct regcache *arg1)
+{
+  self = self->beneath;
+  self->to_prepare_to_store (self, arg1);
+}
+
+static void
+tdefault_prepare_to_store (struct target_ops *self, struct regcache *arg1)
+{
+  noprocess ();
+}
+
+static void
+delegate_files_info (struct target_ops *self)
+{
+  self = self->beneath;
+  self->to_files_info (self);
+}
+
+static void
+tdefault_files_info (struct target_ops *self)
+{
+}
+
 static int
 delegate_insert_breakpoint (struct target_ops *self, struct gdbarch *arg1, struct bp_target_info *arg2)
 {
@@ -57,6 +113,58 @@ delegate_remove_breakpoint (struct target_ops *self, struct gdbarch *arg1, struc
 }
 
 static int
+delegate_can_use_hw_breakpoint (struct target_ops *self, int arg1, int arg2, int arg3)
+{
+  self = self->beneath;
+  return self->to_can_use_hw_breakpoint (self, arg1, arg2, arg3);
+}
+
+static int
+tdefault_can_use_hw_breakpoint (struct target_ops *self, int arg1, int arg2, int arg3)
+{
+  return 0;
+}
+
+static int
+delegate_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *arg1, struct bp_target_info *arg2)
+{
+  self = self->beneath;
+  return self->to_insert_hw_breakpoint (self, arg1, arg2);
+}
+
+static int
+tdefault_insert_hw_breakpoint (struct target_ops *self, struct gdbarch *arg1, struct bp_target_info *arg2)
+{
+  return -1;
+}
+
+static int
+delegate_remove_hw_breakpoint (struct target_ops *self, struct gdbarch *arg1, struct bp_target_info *arg2)
+{
+  self = self->beneath;
+  return self->to_remove_hw_breakpoint (self, arg1, arg2);
+}
+
+static int
+tdefault_remove_hw_breakpoint (struct target_ops *self, struct gdbarch *arg1, struct bp_target_info *arg2)
+{
+  return -1;
+}
+
+static int
+delegate_insert_watchpoint (struct target_ops *self, CORE_ADDR arg1, int arg2, int arg3, struct expression *arg4)
+{
+  self = self->beneath;
+  return self->to_insert_watchpoint (self, arg1, arg2, arg3, arg4);
+}
+
+static int
+tdefault_insert_watchpoint (struct target_ops *self, CORE_ADDR arg1, int arg2, int arg3, struct expression *arg4)
+{
+  return -1;
+}
+
+static int
 delegate_stopped_by_watchpoint (struct target_ops *self)
 {
   self = self->beneath;
@@ -82,6 +190,13 @@ tdefault_stopped_data_address (struct target_ops *self, CORE_ADDR *arg1)
   return 0;
 }
 
+static void
+delegate_rcmd (struct target_ops *self, char *arg1, struct ui_file *arg2)
+{
+  self = self->beneath;
+  self->to_rcmd (self, arg1, arg2);
+}
+
 static int
 delegate_can_async_p (struct target_ops *self)
 {
@@ -138,20 +253,40 @@ tdefault_supports_btrace (struct target_ops *self)
 static void
 install_delegators (struct target_ops *ops)
 {
+  if (ops->to_attach == NULL)
+    ops->to_attach = delegate_attach;
+  if (ops->to_post_attach == NULL)
+    ops->to_post_attach = delegate_post_attach;
+  if (ops->to_detach == NULL)
+    ops->to_detach = delegate_detach;
   if (ops->to_resume == NULL)
     ops->to_resume = delegate_resume;
   if (ops->to_wait == NULL)
     ops->to_wait = delegate_wait;
   if (ops->to_store_registers == NULL)
     ops->to_store_registers = delegate_store_registers;
+  if (ops->to_prepare_to_store == NULL)
+    ops->to_prepare_to_store = delegate_prepare_to_store;
+  if (ops->to_files_info == NULL)
+    ops->to_files_info = delegate_files_info;
   if (ops->to_insert_breakpoint == NULL)
     ops->to_insert_breakpoint = delegate_insert_breakpoint;
   if (ops->to_remove_breakpoint == NULL)
     ops->to_remove_breakpoint = delegate_remove_breakpoint;
+  if (ops->to_can_use_hw_breakpoint == NULL)
+    ops->to_can_use_hw_breakpoint = delegate_can_use_hw_breakpoint;
+  if (ops->to_insert_hw_breakpoint == NULL)
+    ops->to_insert_hw_breakpoint = delegate_insert_hw_breakpoint;
+  if (ops->to_remove_hw_breakpoint == NULL)
+    ops->to_remove_hw_breakpoint = delegate_remove_hw_breakpoint;
+  if (ops->to_insert_watchpoint == NULL)
+    ops->to_insert_watchpoint = delegate_insert_watchpoint;
   if (ops->to_stopped_by_watchpoint == NULL)
     ops->to_stopped_by_watchpoint = delegate_stopped_by_watchpoint;
   if (ops->to_stopped_data_address == NULL)
     ops->to_stopped_data_address = delegate_stopped_data_address;
+  if (ops->to_rcmd == NULL)
+    ops->to_rcmd = delegate_rcmd;
   if (ops->to_can_async_p == NULL)
     ops->to_can_async_p = delegate_can_async_p;
   if (ops->to_is_async_p == NULL)
@@ -167,13 +302,23 @@ install_delegators (struct target_ops *ops)
 static void
 install_dummy_methods (struct target_ops *ops)
 {
+  ops->to_attach = find_default_attach;
+  ops->to_post_attach = tdefault_post_attach;
+  ops->to_detach = tdefault_detach;
   ops->to_resume = tdefault_resume;
   ops->to_wait = tdefault_wait;
   ops->to_store_registers = tdefault_store_registers;
+  ops->to_prepare_to_store = tdefault_prepare_to_store;
+  ops->to_files_info = tdefault_files_info;
   ops->to_insert_breakpoint = memory_insert_breakpoint;
   ops->to_remove_breakpoint = memory_remove_breakpoint;
+  ops->to_can_use_hw_breakpoint = tdefault_can_use_hw_breakpoint;
+  ops->to_insert_hw_breakpoint = tdefault_insert_hw_breakpoint;
+  ops->to_remove_hw_breakpoint = tdefault_remove_hw_breakpoint;
+  ops->to_insert_watchpoint = tdefault_insert_watchpoint;
   ops->to_stopped_by_watchpoint = tdefault_stopped_by_watchpoint;
   ops->to_stopped_data_address = tdefault_stopped_data_address;
+  ops->to_rcmd = default_rcmd;
   ops->to_can_async_p = find_default_can_async_p;
   ops->to_is_async_p = find_default_is_async_p;
   ops->to_async = tdefault_async;
diff --git a/gdb/target.c b/gdb/target.c
index 6bfaa58..559ae5f 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -55,6 +55,8 @@ static int default_watchpoint_addr_within_range (struct target_ops *,
 static int default_region_ok_for_hw_watchpoint (struct target_ops *,
 						CORE_ADDR, int);
 
+static void default_rcmd (struct target_ops *, char *, struct ui_file *);
+
 static void tcomplain (void) ATTRIBUTE_NORETURN;
 
 static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *);
@@ -589,7 +591,7 @@ update_current_target (void)
       /* Do not inherit to_open.  */
       /* Do not inherit to_close.  */
       /* Do not inherit to_attach.  */
-      INHERIT (to_post_attach, t);
+      /* Do not inherit to_post_attach.  */
       INHERIT (to_attach_no_wait, t);
       /* Do not inherit to_detach.  */
       /* Do not inherit to_disconnect.  */
@@ -597,16 +599,16 @@ update_current_target (void)
       /* Do not inherit to_wait.  */
       /* Do not inherit to_fetch_registers.  */
       /* Do not inherit to_store_registers.  */
-      INHERIT (to_prepare_to_store, t);
+      /* Do not inherit to_prepare_to_store.  */
       INHERIT (deprecated_xfer_memory, t);
-      INHERIT (to_files_info, t);
+      /* Do not inherit to_files_info.  */
       /* Do not inherit to_insert_breakpoint.  */
       /* Do not inherit to_remove_breakpoint.  */
-      INHERIT (to_can_use_hw_breakpoint, t);
-      INHERIT (to_insert_hw_breakpoint, t);
-      INHERIT (to_remove_hw_breakpoint, t);
+      /* Do not inherit to_can_use_hw_breakpoint.  */
+      /* Do not inherit to_insert_hw_breakpoint.  */
+      /* Do not inherit to_remove_hw_breakpoint.  */
       /* Do not inherit to_ranged_break_num_registers.  */
-      INHERIT (to_insert_watchpoint, t);
+      /* Do not inherit to_insert_watchpoint.  */
       INHERIT (to_remove_watchpoint, t);
       /* Do not inherit to_insert_mask_watchpoint.  */
       /* Do not inherit to_remove_mask_watchpoint.  */
@@ -648,7 +650,7 @@ update_current_target (void)
       INHERIT (to_thread_name, t);
       INHERIT (to_stop, t);
       /* Do not inherit to_xfer_partial.  */
-      INHERIT (to_rcmd, t);
+      /* Do not inherit to_rcmd.  */
       INHERIT (to_pid_to_exec_file, t);
       INHERIT (to_log_command, t);
       INHERIT (to_stratum, t);
@@ -728,34 +730,10 @@ update_current_target (void)
   de_fault (to_close,
 	    (void (*) (struct target_ops *))
 	    target_ignore);
-  de_fault (to_post_attach,
-	    (void (*) (struct target_ops *, int))
-	    target_ignore);
-  de_fault (to_prepare_to_store,
-	    (void (*) (struct target_ops *, struct regcache *))
-	    noprocess);
   de_fault (deprecated_xfer_memory,
 	    (int (*) (CORE_ADDR, gdb_byte *, int, int,
 		      struct mem_attrib *, struct target_ops *))
 	    nomemory);
-  de_fault (to_files_info,
-	    (void (*) (struct target_ops *))
-	    target_ignore);
-  de_fault (to_can_use_hw_breakpoint,
-	    (int (*) (struct target_ops *, int, int, int))
-	    return_zero);
-  de_fault (to_insert_hw_breakpoint,
-	    (int (*) (struct target_ops *, struct gdbarch *,
-		      struct bp_target_info *))
-	    return_minus_one);
-  de_fault (to_remove_hw_breakpoint,
-	    (int (*) (struct target_ops *, struct gdbarch *,
-		      struct bp_target_info *))
-	    return_minus_one);
-  de_fault (to_insert_watchpoint,
-	    (int (*) (struct target_ops *, CORE_ADDR, int, int,
-		      struct expression *))
-	    return_minus_one);
   de_fault (to_remove_watchpoint,
 	    (int (*) (struct target_ops *, CORE_ADDR, int, int,
 		      struct expression *))
@@ -827,9 +805,6 @@ update_current_target (void)
   de_fault (to_stop,
 	    (void (*) (struct target_ops *, ptid_t))
 	    target_ignore);
-  de_fault (to_rcmd,
-	    (void (*) (struct target_ops *, char *, struct ui_file *))
-	    tcomplain);
   de_fault (to_pid_to_exec_file,
 	    (char *(*) (struct target_ops *, int))
 	    return_null);
@@ -2629,19 +2604,10 @@ target_detach (const char *args, int from_tty)
 
   prepare_for_detach ();
 
-  for (t = current_target.beneath; t != NULL; t = t->beneath)
-    {
-      if (t->to_detach != NULL)
-	{
-	  t->to_detach (t, args, from_tty);
-	  if (targetdebug)
-	    fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n",
-				args, from_tty);
-	  return;
-	}
-    }
-
-  internal_error (__FILE__, __LINE__, _("could not find a target to detach"));
+  current_target.to_detach (&current_target, args, from_tty);
+  if (targetdebug)
+    fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n",
+			args, from_tty);
 }
 
 void
@@ -3754,9 +3720,6 @@ init_dummy_target (void)
   dummy_target.to_shortname = "None";
   dummy_target.to_longname = "None";
   dummy_target.to_doc = "";
-  dummy_target.to_attach = find_default_attach;
-  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_supports_non_stop = find_default_supports_non_stop;
   dummy_target.to_supports_disable_randomization
@@ -3803,22 +3766,10 @@ target_close (struct target_ops *targ)
 void
 target_attach (char *args, int from_tty)
 {
-  struct target_ops *t;
-
-  for (t = current_target.beneath; t != NULL; t = t->beneath)
-    {
-      if (t->to_attach != NULL)	
-	{
-	  t->to_attach (t, args, from_tty);
-	  if (targetdebug)
-	    fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n",
-				args, from_tty);
-	  return;
-	}
-    }
-
-  internal_error (__FILE__, __LINE__,
-		  _("could not find a target to attach"));
+  current_target.to_attach (&current_target, args, from_tty);
+  if (targetdebug)
+    fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n",
+			args, from_tty);
 }
 
 int
@@ -5017,16 +4968,15 @@ stack of targets currently in use (including the exec-file,\n\
 core-file, and process, if any), as well as the symbol file name.";
 
 static void
+default_rcmd (struct target_ops *self, char *command, struct ui_file *output)
+{
+  error (_("\"monitor\" command not supported by this target."));
+}
+
+static void
 do_monitor_command (char *cmd,
 		 int from_tty)
 {
-  if ((current_target.to_rcmd
-       == (void (*) (struct target_ops *, char *, struct ui_file *)) tcomplain)
-      || (current_target.to_rcmd == debug_to_rcmd
-	  && (debug_target.to_rcmd
-	      == (void (*) (struct target_ops *,
-			    char *, struct ui_file *)) tcomplain)))
-    error (_("\"monitor\" command not supported by this target."));
   target_rcmd (cmd, gdb_stdtarg);
 }
 
diff --git a/gdb/target.h b/gdb/target.h
index 9fdd506..ad552a9 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -394,9 +394,12 @@ struct target_ops
        to xfree everything (including the "struct target_ops").  */
     void (*to_xclose) (struct target_ops *targ);
     void (*to_close) (struct target_ops *);
-    void (*to_attach) (struct target_ops *ops, char *, int);
-    void (*to_post_attach) (struct target_ops *, int);
-    void (*to_detach) (struct target_ops *ops, const char *, int);
+    void (*to_attach) (struct target_ops *ops, char *, int)
+      TARGET_DEFAULT_FUNC (find_default_attach);
+    void (*to_post_attach) (struct target_ops *, int)
+      TARGET_DEFAULT_IGNORE ();
+    void (*to_detach) (struct target_ops *ops, const char *, int)
+      TARGET_DEFAULT_IGNORE ();
     void (*to_disconnect) (struct target_ops *, char *, int);
     void (*to_resume) (struct target_ops *, ptid_t, int, enum gdb_signal)
       TARGET_DEFAULT_NORETURN (noprocess ());
@@ -406,7 +409,8 @@ struct target_ops
     void (*to_fetch_registers) (struct target_ops *, struct regcache *, int);
     void (*to_store_registers) (struct target_ops *, struct regcache *, int)
       TARGET_DEFAULT_NORETURN (noprocess ());
-    void (*to_prepare_to_store) (struct target_ops *, struct regcache *);
+    void (*to_prepare_to_store) (struct target_ops *, struct regcache *)
+      TARGET_DEFAULT_NORETURN (noprocess ());
 
     /* Transfer LEN bytes of memory between GDB address MYADDR and
        target address MEMADDR.  If WRITE, transfer them to the target, else
@@ -434,26 +438,31 @@ struct target_ops
 				   struct mem_attrib *attrib,
 				   struct target_ops *target);
 
-    void (*to_files_info) (struct target_ops *);
+    void (*to_files_info) (struct target_ops *)
+      TARGET_DEFAULT_IGNORE ();
     int (*to_insert_breakpoint) (struct target_ops *, struct gdbarch *,
 				 struct bp_target_info *)
       TARGET_DEFAULT_FUNC (memory_insert_breakpoint);
     int (*to_remove_breakpoint) (struct target_ops *, struct gdbarch *,
 				 struct bp_target_info *)
       TARGET_DEFAULT_FUNC (memory_remove_breakpoint);
-    int (*to_can_use_hw_breakpoint) (struct target_ops *, int, int, int);
+    int (*to_can_use_hw_breakpoint) (struct target_ops *, int, int, int)
+      TARGET_DEFAULT_RETURN (0);
     int (*to_ranged_break_num_registers) (struct target_ops *);
     int (*to_insert_hw_breakpoint) (struct target_ops *,
-				    struct gdbarch *, struct bp_target_info *);
+				    struct gdbarch *, struct bp_target_info *)
+      TARGET_DEFAULT_RETURN (-1);
     int (*to_remove_hw_breakpoint) (struct target_ops *,
-				    struct gdbarch *, struct bp_target_info *);
+				    struct gdbarch *, struct bp_target_info *)
+      TARGET_DEFAULT_RETURN (-1);
 
     /* Documentation of what the two routines below are expected to do is
        provided with the corresponding target_* macros.  */
     int (*to_remove_watchpoint) (struct target_ops *,
 				 CORE_ADDR, int, int, struct expression *);
     int (*to_insert_watchpoint) (struct target_ops *,
-				 CORE_ADDR, int, int, struct expression *);
+				 CORE_ADDR, int, int, struct expression *)
+      TARGET_DEFAULT_RETURN (-1);
 
     int (*to_insert_mask_watchpoint) (struct target_ops *,
 				      CORE_ADDR, CORE_ADDR, int);
@@ -517,7 +526,8 @@ struct target_ops
     char *(*to_thread_name) (struct target_ops *, struct thread_info *);
     void (*to_stop) (struct target_ops *, ptid_t);
     void (*to_rcmd) (struct target_ops *,
-		     char *command, struct ui_file *output);
+		     char *command, struct ui_file *output)
+      TARGET_DEFAULT_FUNC (default_rcmd);
     char *(*to_pid_to_exec_file) (struct target_ops *, int pid);
     void (*to_log_command) (struct target_ops *, const char *);
     struct target_section_table *(*to_get_section_table) (struct target_ops *);
-- 
1.8.1.4



More information about the Gdb-patches mailing list