]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
remove to_data
authorPaul Koning <paul_koning@dell.com>
Fri, 16 Oct 2015 18:06:43 +0000 (14:06 -0400)
committerPaul Koning <paul_koning@dell.com>
Fri, 16 Oct 2015 18:06:43 +0000 (14:06 -0400)
There's no reason to have to_data.

On the one hand, a to_xclose target can readily subclass target_ops.
This is simple and clean.

On the other hand, a to_close target can't really use to_data in the
multi-target future, because such a target is inherently not
multi-capable.

So, this patch removes the field and fixes up its sole user.

2014-07-29  Tom Tromey  <tromey@redhat.com>

* bfd-target.c (struct target_bfd_ops): Rename from
target_bfd_data.  Add "base" field.
(target_bfd_xfer_partial, target_bfd_get_section_table)
(target_bfd_xclose, target_bfd_reopen): Update.
* target.h (struct target_ops) <to_data>: Remove.

gdb/bfd-target.c
gdb/target.h

index 8a37696baeadee42154319711d6b9ccebfaeda12..01bcf44092966efd13fde56fb4f9e65710d32ffb 100644 (file)
 #include "exec.h"
 #include "gdb_bfd.h"
 
-/* The object that is stored in the target_ops->to_data field has this
-   type.  */
-struct target_bfd_data
+/* A subclass of target_ops that stores some extra data for use by the
+   BFD target.  */
+struct target_bfd_ops
 {
+  /* The base class.  */
+  struct target_ops base;
+
   /* The BFD we're wrapping.  */
   struct bfd *bfd;
 
@@ -48,7 +51,7 @@ target_bfd_xfer_partial (struct target_ops *ops,
     {
     case TARGET_OBJECT_MEMORY:
       {
-       struct target_bfd_data *data = (struct target_bfd_data *) ops->to_data;
+       struct target_bfd_ops *data = (struct target_bfd_ops *) ops;
        return section_table_xfer_memory_partial (readbuf, writebuf,
                                                  offset, len, xfered_len,
                                                  data->table.sections,
@@ -63,42 +66,39 @@ target_bfd_xfer_partial (struct target_ops *ops,
 static struct target_section_table *
 target_bfd_get_section_table (struct target_ops *ops)
 {
-  struct target_bfd_data *data = (struct target_bfd_data *) ops->to_data;
+  struct target_bfd_ops *data = (struct target_bfd_ops *) ops;
   return &data->table;
 }
 
 static void
 target_bfd_xclose (struct target_ops *t)
 {
-  struct target_bfd_data *data = (struct target_bfd_data *) t->to_data;
+  struct target_bfd_ops *data = (struct target_bfd_ops *) t;
 
   gdb_bfd_unref (data->bfd);
   xfree (data->table.sections);
   xfree (data);
-  xfree (t);
 }
 
 struct target_ops *
 target_bfd_reopen (struct bfd *abfd)
 {
-  struct target_ops *t;
-  struct target_bfd_data *data;
+  struct target_bfd_ops *t;
+
+  t = XCNEW (struct target_bfd_ops);
 
-  data = XCNEW (struct target_bfd_data);
-  data->bfd = abfd;
+  t->bfd = abfd;
   gdb_bfd_ref (abfd);
-  build_section_table (abfd, &data->table.sections, &data->table.sections_end);
-
-  t = XCNEW (struct target_ops);
-  t->to_shortname = "bfd";
-  t->to_longname = _("BFD backed target");
-  t->to_doc = _("You should never see this");
-  t->to_get_section_table = target_bfd_get_section_table;
-  t->to_xfer_partial = target_bfd_xfer_partial;
-  t->to_xclose = target_bfd_xclose;
-  t->to_data = data;
-  t->to_magic = OPS_MAGIC;
-  t->to_identity = t;
-
-  return t;
+  build_section_table (abfd, &t->table.sections, &t->table.sections_end);
+
+  t->base.to_shortname = "bfd";
+  t->base.to_longname = _("BFD backed target");
+  t->base.to_doc = _("You should never see this");
+  t->base.to_get_section_table = target_bfd_get_section_table;
+  t->base.to_xfer_partial = target_bfd_xfer_partial;
+  t->base.to_xclose = target_bfd_xclose;
+  t->base.to_magic = OPS_MAGIC;
+  t->base.to_identity = &t->base;
+
+  return &t->base;
 }
index fce4046f9308976c76f99bc0c4b563d8bfb335c8..da04e47b7708281c6f0d6a26fae5c3e5a015f67a 100644 (file)
@@ -430,8 +430,6 @@ struct target_ops
     const char *to_doc;                /* Documentation.  Does not include trailing
                                   newline, and starts with a one-line descrip-
                                   tion (probably similar to to_longname).  */
-    /* Per-target scratch pad.  */
-    void *to_data;
     /* The open routine takes the rest of the parameters from the
        command, and (if successful) pushes a new target onto the
        stack.  Targets should supply this routine, if only to provide