aboutsummaryrefslogtreecommitdiff
path: root/gdb/coffread.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-08-19 11:50:44 -0600
committerTom Tromey <tom@tromey.com>2019-03-06 14:04:44 -0700
commite2a035485a80651a5dc1711fee5a811e41ab131b (patch)
tree2251bab83082ab097d40ed205e0809fb5be1d185 /gdb/coffread.c
parentb7e60d85da12a1819671473db8550c9f076e8f38 (diff)
downloadgdb-e2a035485a80651a5dc1711fee5a811e41ab131b.zip
gdb-e2a035485a80651a5dc1711fee5a811e41ab131b.tar.gz
gdb-e2a035485a80651a5dc1711fee5a811e41ab131b.tar.bz2
Remove cleanups from coffread.c
This removes the remaining cleanups from coffread.c. Tested by the buildbot and also some manual testing. This version includes the fix provided by Joel. gdb/ChangeLog 2019-03-06 Joel Brobecker <brobecker@adacore.com> Tom Tromey <tom@tromey.com> * stabsread.h (struct stab_section_list): Remove. (coffstab_build_psymtabs): Update. * dbxread.c (symbuf_sections): Now a std::vector. (sect_idx): New global. (fill_symbuf): Update. (coffstab_build_psymtabs): Change type of stabsects parameter. Update. * coffread.c (struct coff_symfile_info) <stabsects>: Now a std::vector. (linetab, linetab_offset, linetab_size, stringtab): Move earlier. (coff_locate_sections): Update. (coff_symfile_read): Remove cleanups. Update. (init_stringtab): Add storage parameter. (free_stringtab, free_stringtab_cleanup): Remove. (init_lineno): Add storage parameter. (free_linetab, free_linetab_cleanup): Remove.
Diffstat (limited to 'gdb/coffread.c')
-rw-r--r--gdb/coffread.c115
1 files changed, 34 insertions, 81 deletions
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 91a112e..b89c0e2 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -58,7 +58,7 @@ struct coff_symfile_info
CORE_ADDR textaddr; /* Addr of .text section. */
unsigned int textsize; /* Size of .text section. */
- struct stab_section_list *stabsects; /* .stab sections. */
+ std::vector<asection *> *stabsects; /* .stab sections. */
asection *stabstrsect; /* Section pointer for .stab section. */
char *stabstrdata;
};
@@ -155,6 +155,12 @@ static int type_vector_length;
#define INITIAL_TYPE_VECTOR_LENGTH 160
+static char *linetab = NULL;
+static long linetab_offset;
+static unsigned long linetab_size;
+
+static char *stringtab = NULL;
+
extern void stabsread_clear_cache (void);
static struct type *coff_read_struct_type (int, int, int,
@@ -185,21 +191,13 @@ static void patch_opaque_types (struct symtab *);
static void enter_linenos (long, int, int, struct objfile *);
-static void free_linetab (void);
-
-static void free_linetab_cleanup (void *ignore);
-
-static int init_lineno (bfd *, long, int);
+static int init_lineno (bfd *, long, int, gdb::unique_xmalloc_ptr<char> *);
static char *getsymname (struct internal_syment *);
static const char *coff_getfilename (union internal_auxent *);
-static void free_stringtab (void);
-
-static void free_stringtab_cleanup (void *ignore);
-
-static int init_stringtab (bfd *, long);
+static int init_stringtab (bfd *, long, gdb::unique_xmalloc_ptr<char> *);
static void read_one_sym (struct coff_symbol *,
struct internal_syment *,
@@ -249,21 +247,7 @@ coff_locate_sections (bfd *abfd, asection *sectp, void *csip)
if (!isdigit (*s))
break;
if (*s == '\0')
- {
- struct stab_section_list *n, **pn;
-
- n = XNEW (struct stab_section_list);
- n->section = sectp;
- n->next = NULL;
- for (pn = &csi->stabsects; *pn != NULL; pn = &(*pn)->next)
- ;
- *pn = n;
-
- /* This will be run after coffstab_build_psymtabs is called
- in coff_symfile_read, at which point we no longer need
- the information. */
- make_cleanup (xfree, n);
- }
+ csi->stabsects->push_back (sectp);
}
}
@@ -567,13 +551,16 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
unsigned int num_symbols;
int symtab_offset;
int stringtab_offset;
- struct cleanup *back_to;
int stabstrsize;
info = (struct coff_symfile_info *) objfile_data (objfile,
coff_objfile_data_key);
symfile_bfd = abfd; /* Kludge for swap routines. */
+ std::vector<asection *> stabsects;
+ scoped_restore restore_stabsects
+ = make_scoped_restore (&info->stabsects, &stabsects);
+
/* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
num_symbols = bfd_get_symcount (abfd); /* How many syms */
symtab_offset = cdata->sym_filepos; /* Symbol table file offset */
@@ -592,10 +579,10 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
/* Allocate space for raw symbol and aux entries, based on their
space requirements as reported by BFD. */
- temp_sym = (char *) xmalloc
- (cdata->local_symesz + cdata->local_auxesz);
+ gdb::def_vector<char> temp_storage (cdata->local_symesz
+ + cdata->local_auxesz);
+ temp_sym = temp_storage.data ();
temp_aux = temp_sym + cdata->local_symesz;
- back_to = make_cleanup (free_current_contents, &temp_sym);
/* We need to know whether this is a PE file, because in PE files,
unlike standard COFF files, symbol values are stored as offsets
@@ -625,22 +612,25 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
can avoid spurious error messages (and maybe run a little
faster!) by not even reading the line number table unless we have
symbols. */
+ scoped_restore restore_linetab = make_scoped_restore (&linetab);
+ gdb::unique_xmalloc_ptr<char> linetab_storage;
if (num_symbols > 0)
{
/* Read the line number table, all at once. */
bfd_map_over_sections (abfd, find_linenos, (void *) info);
- make_cleanup (free_linetab_cleanup, 0 /*ignore*/);
val = init_lineno (abfd, info->min_lineno_offset,
- info->max_lineno_offset - info->min_lineno_offset);
+ info->max_lineno_offset - info->min_lineno_offset,
+ &linetab_storage);
if (val < 0)
error (_("\"%s\": error reading line numbers."), filename);
}
/* Now read the string table, all at once. */
- make_cleanup (free_stringtab_cleanup, 0 /*ignore*/);
- val = init_stringtab (abfd, stringtab_offset);
+ scoped_restore restore_stringtab = make_scoped_restore (&stringtab);
+ gdb::unique_xmalloc_ptr<char> stringtab_storage;
+ val = init_stringtab (abfd, stringtab_offset, &stringtab_storage);
if (val < 0)
error (_("\"%s\": can't get string table"), filename);
@@ -698,7 +688,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
if (!(objfile->flags & OBJF_READNEVER))
bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
- if (info->stabsects)
+ if (!info->stabsects->empty())
{
if (!info->stabstrsect)
{
@@ -715,7 +705,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
coffstab_build_psymtabs (objfile,
info->textaddr, info->textsize,
- info->stabsects,
+ *info->stabsects,
info->stabstrsect->filepos, stabstrsize);
}
if (dwarf2_has_info (objfile, NULL))
@@ -742,8 +732,6 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
symfile_flags, objfile);
}
}
-
- do_cleanups (back_to);
}
static void
@@ -1295,17 +1283,13 @@ read_one_sym (struct coff_symbol *cs,
/* Support for string table handling. */
-static char *stringtab = NULL;
-
static int
-init_stringtab (bfd *abfd, long offset)
+init_stringtab (bfd *abfd, long offset, gdb::unique_xmalloc_ptr<char> *storage)
{
long length;
int val;
unsigned char lengthbuf[4];
- free_stringtab ();
-
/* If the file is stripped, the offset might be zero, indicating no
string table. Just return with `stringtab' set to null. */
if (offset == 0)
@@ -1322,7 +1306,8 @@ init_stringtab (bfd *abfd, long offset)
if (val != sizeof lengthbuf || length < sizeof lengthbuf)
return 0;
- stringtab = (char *) xmalloc (length);
+ storage->reset ((char *) xmalloc (length));
+ stringtab = storage->get ();
/* This is in target format (probably not very useful, and not
currently used), not host format. */
memcpy (stringtab, lengthbuf, sizeof lengthbuf);
@@ -1337,20 +1322,6 @@ init_stringtab (bfd *abfd, long offset)
return 0;
}
-static void
-free_stringtab (void)
-{
- if (stringtab)
- xfree (stringtab);
- stringtab = NULL;
-}
-
-static void
-free_stringtab_cleanup (void *ignore)
-{
- free_stringtab ();
-}
-
static char *
getsymname (struct internal_syment *symbol_entry)
{
@@ -1404,24 +1375,19 @@ coff_getfilename (union internal_auxent *aux_entry)
/* Support for line number handling. */
-static char *linetab = NULL;
-static long linetab_offset;
-static unsigned long linetab_size;
-
/* Read in all the line numbers for fast lookups later. Leave them in
external (unswapped) format in memory; we'll swap them as we enter
them into GDB's data structures. */
static int
-init_lineno (bfd *abfd, long offset, int size)
+init_lineno (bfd *abfd, long offset, int size,
+ gdb::unique_xmalloc_ptr<char> *storage)
{
int val;
linetab_offset = offset;
linetab_size = size;
- free_linetab ();
-
if (size == 0)
return 0;
@@ -1429,9 +1395,10 @@ init_lineno (bfd *abfd, long offset, int size)
return -1;
/* Allocate the desired table, plus a sentinel. */
- linetab = (char *) xmalloc (size + local_linesz);
+ storage->reset ((char *) xmalloc (size + local_linesz));
+ linetab = storage->get ();
- val = bfd_bread (linetab, size, abfd);
+ val = bfd_bread (storage->get (), size, abfd);
if (val != size)
return -1;
@@ -1441,20 +1408,6 @@ init_lineno (bfd *abfd, long offset, int size)
return 0;
}
-static void
-free_linetab (void)
-{
- if (linetab)
- xfree (linetab);
- linetab = NULL;
-}
-
-static void
-free_linetab_cleanup (void *ignore)
-{
- free_linetab ();
-}
-
#if !defined (L_LNNO32)
#define L_LNNO32(lp) ((lp)->l_lnno)
#endif