public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH v2 20/31] Convert coffread.c to type-safe registry API
Date: Fri, 03 May 2019 23:12:00 -0000	[thread overview]
Message-ID: <20190503231231.8954-21-tom@tromey.com> (raw)
In-Reply-To: <20190503231231.8954-1-tom@tromey.com>

This changes coffread.c to use the type-safe registry API.

2019-05-01  Tom Tromey  <tom@tromey.com>

	* coffread.c (struct coff_symfile_info): Add initializers.
	(coff_objfile_data_key): Move lower.  Change type.
	(coff_symfile_init, coff_symfile_read, _initialize_coffread):
	Update.
	(coff_free_info): Remove.
---
 gdb/ChangeLog  |  8 ++++++++
 gdb/coffread.c | 38 ++++++++++++--------------------------
 2 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/gdb/coffread.c b/gdb/coffread.c
index 4354741ab64..0956f3897b4 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -43,26 +43,26 @@
 #include "psymtab.h"
 #include "build-id.h"
 
-/* Key for COFF-associated data.  */
-
-static const struct objfile_data *coff_objfile_data_key;
-
 /* The objfile we are currently reading.  */
 
 static struct objfile *coffread_objfile;
 
 struct coff_symfile_info
   {
-    file_ptr min_lineno_offset;	/* Where in file lowest line#s are.  */
-    file_ptr max_lineno_offset;	/* 1+last byte of line#s in file.  */
+    file_ptr min_lineno_offset = 0;	/* Where in file lowest line#s are.  */
+    file_ptr max_lineno_offset = 0;	/* 1+last byte of line#s in file.  */
 
-    CORE_ADDR textaddr;		/* Addr of .text section.  */
-    unsigned int textsize;	/* Size of .text section.  */
+    CORE_ADDR textaddr = 0;		/* Addr of .text section.  */
+    unsigned int textsize = 0;	/* Size of .text section.  */
     std::vector<asection *> *stabsects;	/* .stab sections.  */
-    asection *stabstrsect;	/* Section pointer for .stab section.  */
-    char *stabstrdata;
+    asection *stabstrsect = nullptr;	/* Section pointer for .stab section.  */
+    char *stabstrdata = nullptr;
   };
 
+/* Key for COFF-associated data.  */
+
+static const struct objfile_key<coff_symfile_info> coff_objfile_data_key;
+
 /* Translate an external name string into a user-visible name.  */
 #define	EXTERNAL_NAME(string, abfd) \
 	(string[0] == bfd_get_symbol_leading_char (abfd) \
@@ -485,15 +485,13 @@ static void
 coff_symfile_init (struct objfile *objfile)
 {
   struct dbx_symfile_info *dbx;
-  struct coff_symfile_info *coff;
 
   /* Allocate struct to keep track of stab reading.  */
   dbx = XCNEW (struct dbx_symfile_info);
   set_objfile_data (objfile, dbx_objfile_data_key, dbx);
 
   /* Allocate struct to keep track of the symfile.  */
-  coff = XCNEW (struct coff_symfile_info);
-  set_objfile_data (objfile, coff_objfile_data_key, coff);
+  coff_objfile_data_key.emplace (objfile);
 
   /* COFF objects may be reordered, so set OBJF_REORDERED.  If we
      find this causes a significant slowdown in gdb then we could
@@ -554,8 +552,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   int stringtab_offset;
   int stabstrsize;
   
-  info = (struct coff_symfile_info *) objfile_data (objfile,
-						    coff_objfile_data_key);
+  info = coff_objfile_data_key.get (objfile);
   symfile_bfd = abfd;		/* Kludge for swap routines.  */
 
   std::vector<asection *> stabsects;
@@ -2211,22 +2208,11 @@ static const struct sym_fns coff_sym_fns =
   &psym_functions
 };
 
-/* Free the per-objfile COFF data.  */
-
-static void
-coff_free_info (struct objfile *objfile, void *arg)
-{
-  xfree (arg);
-}
-
 void
 _initialize_coffread (void)
 {
   add_symtab_fns (bfd_target_coff_flavour, &coff_sym_fns);
 
-  coff_objfile_data_key = register_objfile_data_with_cleanup (NULL,
-							      coff_free_info);
-
   coff_register_index
     = register_symbol_register_impl (LOC_REGISTER, &coff_register_funcs);
 }
-- 
2.17.2

  parent reply	other threads:[~2019-05-03 23:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-03 23:12 [PATCH v2 00/31] Add a type-safe API to registries Tom Tromey
2019-05-03 23:12 ` [PATCH v2 01/31] Add a type-safe C++ interface to a registry Tom Tromey
2019-05-03 23:12 ` [PATCH v2 24/31] Convert mdebugread.c to type-safe registry API Tom Tromey
2019-05-03 23:12 ` [PATCH v2 19/31] Convert fbsd-tdep.c " Tom Tromey
2019-05-06 20:56   ` John Baldwin
2019-05-08 17:58     ` Tom Tromey
2019-05-08 22:06       ` Tom Tromey
2019-05-03 23:12 ` [PATCH v2 10/31] Convert symfile-debug.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 07/31] Convert objfiles.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 12/31] Convert linux-tdep.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 13/31] Convert breakpoint.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 08/31] Convert auto-load.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 18/31] Convert ada-tasks.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 04/31] Convert target dcache " Tom Tromey
2019-05-03 23:12 ` Tom Tromey [this message]
2019-05-03 23:12 ` [PATCH v2 25/31] Convert elfread.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 16/31] Convert xcoffread.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 17/31] Convert probes " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 21/31] Convert ada-lang.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 06/31] Convert break-catch-syscall.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 03/31] Convert symbol_cache " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 05/31] Convert inflow " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 15/31] Convert solib-svr4.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 23/31] Add a noop deleter Tom Tromey
2019-05-03 23:13 ` [PATCH v2 29/31] Convert objc-lang.c to type-safe registry API Tom Tromey
2019-05-03 23:13 ` [PATCH v2 26/31] Convert hppa-tdep.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 14/31] Convert remote.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 22/31] Convert nto-tdep.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 09/31] Convert dwarf2_per_objfile " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 11/31] Convert auxv.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 28/31] Convert stabsread.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 27/31] Remove mips_pdr_data Tom Tromey
2019-05-03 23:13 ` [PATCH v2 02/31] Convert main_info to type-safe registry API Tom Tromey
2019-05-03 23:31 ` [PATCH v2 31/31] Convert gdbtypes.c " Tom Tromey
2019-05-03 23:31 ` [PATCH v2 30/31] Convert dwarf2-frame.c " Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190503231231.8954-21-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).