From: Tom Tromey Date: Wed, 28 Mar 2018 21:04:30 +0000 (-0600) Subject: Remove free_cached_comp_units cleanups X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=11ed8cada64e717900117364c2fee0132c1eb099;p=binutils-gdb.git Remove free_cached_comp_units cleanups This changes free_cached_comp_units from a cleanup function to an RAII class. gdb/ChangeLog 2018-03-30 Tom Tromey * dwarf2read.c (class free_cached_comp_units): New class. (dw2_instantiate_symtab, dwarf2_build_psymtabs_hard): Use it. (free_cached_comp_units): Remove function. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 815d03d8fb4..9b4675f281b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-03-30 Tom Tromey + + * dwarf2read.c (class free_cached_comp_units): New class. + (dw2_instantiate_symtab, dwarf2_build_psymtabs_hard): Use it. + (free_cached_comp_units): Remove function. + 2018-03-30 Tom Tromey * utils.h (make_cleanup_unpush_target): Remove. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index dfa69d1dbbb..78404967380 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1821,8 +1821,6 @@ static void prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die, enum language pretend_language); -static void free_cached_comp_units (void *); - static void age_cached_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile); static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *); @@ -2172,6 +2170,30 @@ dwarf2_per_objfile::free_cached_comp_units () } } +/* A helper class that calls free_cached_comp_units on + destruction. */ + +class free_cached_comp_units +{ +public: + + explicit free_cached_comp_units (dwarf2_per_objfile *per_objfile) + : m_per_objfile (per_objfile) + { + } + + ~free_cached_comp_units () + { + m_per_objfile->free_cached_comp_units (); + } + + DISABLE_COPY_AND_ASSIGN (free_cached_comp_units); + +private: + + dwarf2_per_objfile *m_per_objfile; +}; + /* Try to locate the sections we need for DWARF 2 debugging information and return true if we have enough to do something. NAMES points to the dwarf2 section names, or is NULL if the standard @@ -2876,12 +2898,10 @@ dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) gdb_assert (dwarf2_per_objfile->using_index); if (!per_cu->v.quick->compunit_symtab) { - struct cleanup *back_to = make_cleanup (free_cached_comp_units, - dwarf2_per_objfile); + free_cached_comp_units freer (dwarf2_per_objfile); scoped_restore decrementer = increment_reading_symtab (); dw2_do_instantiate_symtab (per_cu); process_cu_includes (dwarf2_per_objfile); - do_cleanups (back_to); } return per_cu->v.quick->compunit_symtab; @@ -8434,7 +8454,6 @@ set_partial_user (struct dwarf2_per_objfile *dwarf2_per_objfile) static void dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile) { - struct cleanup *back_to; int i; struct objfile *objfile = dwarf2_per_objfile->objfile; @@ -8450,7 +8469,7 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile) /* Any cached compilation units will be linked by the per-objfile read_in_chain. Make sure to free them when we're done. */ - back_to = make_cleanup (free_cached_comp_units, dwarf2_per_objfile); + free_cached_comp_units freer (dwarf2_per_objfile); build_type_psymtabs (dwarf2_per_objfile); @@ -8491,8 +8510,6 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile) /* At this point we want to keep the address map. */ save_psymtabs_addrmap.release (); - do_cleanups (back_to); - if (dwarf_read_debug) fprintf_unfiltered (gdb_stdlog, "Done building psymtabs of %s\n", objfile_name (objfile)); @@ -25072,17 +25089,6 @@ prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die, cu->producer = dwarf2_string_attr (comp_unit_die, DW_AT_producer, cu); } -/* Free all cached compilation units. */ - -static void -free_cached_comp_units (void *data) -{ - struct dwarf2_per_objfile *dwarf2_per_objfile - = (struct dwarf2_per_objfile *) data; - - dwarf2_per_objfile->free_cached_comp_units (); -} - /* Increase the age counter on each cached compilation unit, and free any that are too old. */