From 22855f3cab8948f5b4a0fdda9845ce47c8bafbc9 Mon Sep 17 00:00:00 2001 From: Paul Koning Date: Fri, 16 Oct 2015 14:06:43 -0400 Subject: remove to_data 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 * 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) : Remove. --- gdb/bfd-target.c | 50 +++++++++++++++++++++++++------------------------- gdb/target.h | 2 -- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c index 8a37696baea..01bcf440929 100644 --- a/gdb/bfd-target.c +++ b/gdb/bfd-target.c @@ -23,10 +23,13 @@ #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; } diff --git a/gdb/target.h b/gdb/target.h index fce4046f930..da04e47b770 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -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 -- cgit v1.2.1