From patchwork Thu Mar 29 15:27:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26509 Received: (qmail 5814 invoked by alias); 29 Mar 2018 15:34:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 5775 invoked by uid 89); 29 Mar 2018 15:34:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=NAMES, age X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.222) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Mar 2018 15:34:19 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 99D5163766F for ; Thu, 29 Mar 2018 10:27:59 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 1ZT5fHdVq7Ovo1ZT5fbpy8; Thu, 29 Mar 2018 10:27:59 -0500 Received: from 174-29-48-109.hlrn.qwest.net ([174.29.48.109]:43322 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1f1ZT5-004CXX-Dl; Thu, 29 Mar 2018 10:27:59 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 1/3] Remove free_cached_comp_units cleanups Date: Thu, 29 Mar 2018 09:27:55 -0600 Message-Id: <20180329152757.9346-2-tom@tromey.com> In-Reply-To: <20180329152757.9346-1-tom@tromey.com> References: <20180329152757.9346-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1f1ZT5-004CXX-Dl X-Source-Sender: 174-29-48-109.hlrn.qwest.net (bapiya.Home) [174.29.48.109]:43322 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes free_cached_comp_units from a cleanup function to an RAII class. gdb/ChangeLog 2018-03-29 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. --- gdb/ChangeLog | 6 ++++++ gdb/dwarf2read.c | 46 ++++++++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index dfa69d1dbb..7840496738 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. */