From: Tom Tromey Date: Fri, 20 Oct 2017 15:30:48 +0000 (-0600) Subject: Replace really_free_pendings with a scoped_ class X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=33c7c59df060e9952fc2f608c3a6ff0a23ecd40d;p=binutils-gdb.git Replace really_free_pendings with a scoped_ class This introduces scoped_free_pendings, and changes users of really_free_pendings to use it instead, removing some clenaups. I tried to examine the affected code to ensure there aren't dangling cleanups in the vicinity. gdb/ChangeLog 2017-11-04 Tom Tromey * dwarf2read.c (process_full_comp_unit, process_full_type_unit): Use scoped_free_pendings. * dbxread.c (dbx_symfile_read, dbx_psymtab_to_symtab_1): Use scoped_free_pendings. * xcoffread.c (xcoff_psymtab_to_symtab_1): Use scoped_free_pendings. (xcoff_initial_scan): Likewise. * buildsym.c (reset_symtab_globals): Update comment. (scoped_free_pendings): Rename from really_free_pendings. (prepare_for_building): Update comment. (buildsym_init): Likewise. * buildsym.h (class scoped_free_pendings): New class. (really_free_pendings): Don't declare. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1f823ca533e..f7d821c1e27 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,18 @@ +2017-11-04 Tom Tromey + + * dwarf2read.c (process_full_comp_unit, process_full_type_unit): + Use scoped_free_pendings. + * dbxread.c (dbx_symfile_read, dbx_psymtab_to_symtab_1): Use + scoped_free_pendings. + * xcoffread.c (xcoff_psymtab_to_symtab_1): Use scoped_free_pendings. + (xcoff_initial_scan): Likewise. + * buildsym.c (reset_symtab_globals): Update comment. + (scoped_free_pendings): Rename from really_free_pendings. + (prepare_for_building): Update comment. + (buildsym_init): Likewise. + * buildsym.h (class scoped_free_pendings): New class. + (really_free_pendings): Don't declare. + 2017-11-03 Ulrich Weigand * doublest.c (convert_doublest_to_floatformat): Fix uninitialized diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 07bfbd50389..d07bfb3d137 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -26,11 +26,10 @@ The basic way this module is used is as follows: buildsym_init (); - cleanups = make_cleanup (really_free_pendings, NULL); + scoped_free_pendings free_pending; cust = start_symtab (...); ... read debug info ... cust = end_symtab (...); - do_cleanups (cleanups); The compunit symtab pointer ("cust") is returned from both start_symtab and end_symtab to simplify the debug info readers. @@ -42,31 +41,28 @@ Reading DWARF Type Units is another variation: buildsym_init (); - cleanups = make_cleanup (really_free_pendings, NULL); + scoped_free_pendings free_pending; cust = start_symtab (...); ... read debug info ... cust = end_expandable_symtab (...); - do_cleanups (cleanups); And then reading subsequent Type Units within the containing "Comp Unit" will use a second flow: buildsym_init (); - cleanups = make_cleanup (really_free_pendings, NULL); + scoped_free_pendings free_pending; cust = restart_symtab (...); ... read debug info ... cust = augment_type_symtab (...); - do_cleanups (cleanups); dbxread.c and xcoffread.c use another variation: buildsym_init (); - cleanups = make_cleanup (really_free_pendings, NULL); + scoped_free_pendings free_pending; cust = start_symtab (...); ... read debug info ... cust = end_symtab (...); ... start_symtab + read + end_symtab repeated ... - do_cleanups (cleanups); */ #include "defs.h" @@ -269,15 +265,13 @@ find_symbol_in_list (struct pending *list, char *name, int length) return (NULL); } -/* At end of reading syms, or in case of quit, ensure everything associated - with building symtabs is freed. This is intended to be registered as a - cleanup before doing psymtab->symtab expansion. +/* At end of reading syms, or in case of quit, ensure everything + associated with building symtabs is freed. N.B. This is *not* intended to be used when building psymtabs. Some debug info readers call this anyway, which is harmless if confusing. */ -void -really_free_pendings (void *dummy) +scoped_free_pendings::~scoped_free_pendings () { struct pending *next, *next1; @@ -1028,7 +1022,7 @@ prepare_for_building (const char *name, CORE_ADDR start_addr) context_stack_depth = 0; /* These should have been reset either by successful completion of building - a symtab, or by the really_free_pendings cleanup. */ + a symtab, or by the scoped_free_pendings destructor. */ gdb_assert (file_symbols == NULL); gdb_assert (global_symbols == NULL); gdb_assert (global_using_directives == NULL); @@ -1169,7 +1163,7 @@ watch_main_source_file_lossage (void) /* Reset state after a successful building of a symtab. This exists because dbxread.c and xcoffread.c can call start_symtab+end_symtab multiple times after one call to buildsym_init, - and before the really_free_pendings cleanup is called. + and before the scoped_free_pendings destructor is called. We keep the free_pendings list around for dbx/xcoff sake. */ static void @@ -1753,7 +1747,7 @@ buildsym_init (void) context_stack = XNEWVEC (struct context_stack, context_stack_size); } - /* Ensure the really_free_pendings cleanup was called after + /* Ensure the scoped_free_pendings destructor was called after the last time. */ gdb_assert (free_pendings == NULL); gdb_assert (pending_blocks == NULL); diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 60109a0da2e..accb1f03471 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -212,7 +212,15 @@ extern struct block *finish_block (struct symbol *symbol, extern void record_block_range (struct block *, CORE_ADDR start, CORE_ADDR end_inclusive); -extern void really_free_pendings (void *dummy); +class scoped_free_pendings +{ +public: + + scoped_free_pendings () = default; + ~scoped_free_pendings (); + + DISABLE_COPY_AND_ASSIGN (scoped_free_pendings); +}; extern void start_subfile (const char *name); diff --git a/gdb/dbxread.c b/gdb/dbxread.c index ce009628094..1618a561369 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -516,7 +516,6 @@ dbx_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) { bfd *sym_bfd; int val; - struct cleanup *back_to; sym_bfd = objfile->obfd; @@ -539,7 +538,7 @@ dbx_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) symbol_table_offset = DBX_SYMTAB_OFFSET (objfile); free_pending_blocks (); - back_to = make_cleanup (really_free_pendings, 0); + scoped_free_pendings free_pending; minimal_symbol_reader reader (objfile); @@ -551,8 +550,6 @@ dbx_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) minimal symbols for this objfile. */ reader.install (); - - do_cleanups (back_to); } /* Initialize anything that needs initializing when a completely new @@ -2186,7 +2183,6 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst, static void dbx_psymtab_to_symtab_1 (struct objfile *objfile, struct partial_symtab *pst) { - struct cleanup *old_chain; int i; if (pst->readin) @@ -2220,15 +2216,13 @@ dbx_psymtab_to_symtab_1 (struct objfile *objfile, struct partial_symtab *pst) /* Init stuff necessary for reading in symbols */ stabsread_init (); buildsym_init (); - old_chain = make_cleanup (really_free_pendings, 0); + scoped_free_pendings free_pending; file_string_table_offset = FILE_STRING_OFFSET (pst); symbol_size = SYMBOL_SIZE (pst); /* Read in this file's symbols. */ bfd_seek (objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET); read_ofile_symtab (objfile, pst); - - do_cleanups (old_chain); } pst->readin = 1; diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 686fa3f3d31..433a9272b8e 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -8317,7 +8317,7 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct gdbarch *gdbarch = get_objfile_arch (objfile); CORE_ADDR lowpc, highpc; struct compunit_symtab *cust; - struct cleanup *back_to, *delayed_list_cleanup; + struct cleanup *delayed_list_cleanup; CORE_ADDR baseaddr; struct block *static_block; CORE_ADDR addr; @@ -8325,7 +8325,7 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); buildsym_init (); - back_to = make_cleanup (really_free_pendings, NULL); + scoped_free_pendings free_pending; delayed_list_cleanup = make_cleanup (free_delayed_list, cu); cu->list_in_scope = &file_symbols; @@ -8407,8 +8407,6 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, /* Push it for inclusion processing later. */ VEC_safe_push (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, per_cu); - - do_cleanups (back_to); } /* Generate full symbol information for type unit PER_CU, whose DIEs have @@ -8421,14 +8419,14 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu, struct dwarf2_cu *cu = per_cu->cu; struct objfile *objfile = per_cu->objfile; struct compunit_symtab *cust; - struct cleanup *back_to, *delayed_list_cleanup; + struct cleanup *delayed_list_cleanup; struct signatured_type *sig_type; gdb_assert (per_cu->is_debug_types); sig_type = (struct signatured_type *) per_cu; buildsym_init (); - back_to = make_cleanup (really_free_pendings, NULL); + scoped_free_pendings free_pending; delayed_list_cleanup = make_cleanup (free_delayed_list, cu); cu->list_in_scope = &file_symbols; @@ -8483,8 +8481,6 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu, pst->compunit_symtab = cust; pst->readin = 1; } - - do_cleanups (back_to); } /* Process an imported unit DIE. */ diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index ea11b3f966c..2e4f30f2912 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -1833,7 +1833,6 @@ find_linenos (struct bfd *abfd, struct bfd_section *asect, void *vpinfo) static void xcoff_psymtab_to_symtab_1 (struct objfile *objfile, struct partial_symtab *pst) { - struct cleanup *old_chain; int i; if (!pst) @@ -1870,11 +1869,9 @@ xcoff_psymtab_to_symtab_1 (struct objfile *objfile, struct partial_symtab *pst) /* Init stuff necessary for reading in symbols. */ stabsread_init (); buildsym_init (); - old_chain = make_cleanup (really_free_pendings, 0); + scoped_free_pendings free_pending; read_xcoff_symtab (objfile, pst); - - do_cleanups (old_chain); } pst->readin = 1; @@ -2950,7 +2947,6 @@ xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags) { bfd *abfd; int val; - struct cleanup *back_to; int num_symbols; /* # of symbols */ file_ptr symtab_offset; /* symbol table and */ file_ptr stringtab_offset; /* string table file offsets */ @@ -3027,8 +3023,8 @@ xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags) init_psymbol_list (objfile, num_symbols); free_pending_blocks (); - back_to = make_cleanup (really_free_pendings, 0); + scoped_free_pendings free_pending; minimal_symbol_reader reader (objfile); /* Now that the symbol table data of the executable file are all in core, @@ -3047,8 +3043,6 @@ xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags) dwarf2_build_psymtabs (objfile); dwarf2_build_frame_info (objfile); - - do_cleanups (back_to); } static void