aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-05-01 15:09:25 -0600
committerTom Tromey <tom@tromey.com>2019-05-08 16:01:52 -0600
commit246994051b6659bf9f4c89b5d5ede86717c5bbef (patch)
tree9fdeeed3a25382470c5dadb0cf30efa942ea001c
parentd4e05d2fea956e65618fc12c57fb81e8788ef07d (diff)
downloadfsf-binutils-gdb-246994051b6659bf9f4c89b5d5ede86717c5bbef.zip
fsf-binutils-gdb-246994051b6659bf9f4c89b5d5ede86717c5bbef.tar.gz
fsf-binutils-gdb-246994051b6659bf9f4c89b5d5ede86717c5bbef.tar.bz2
Convert coffread.c to type-safe registry API
This changes coffread.c to use the type-safe registry API. gdb/ChangeLog 2019-05-08 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.
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/coffread.c38
2 files changed, 20 insertions, 26 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9bc8f99..5677e33 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
2019-05-08 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.
+
+2019-05-08 Tom Tromey <tom@tromey.com>
+
* fbsd-tdep.c (struct fbsd_pspace_data): Add initializers.
(fbsd_pspace_data_handle): Move lower. Change type.
(get_fbsd_pspace_data): Update.
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 4354741..0956f38 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);
}