From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7807 invoked by alias); 2 Nov 2017 22:36:24 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 7202 invoked by uid 89); 2 Nov 2017 22:36:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_STOCKGEN,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=pst, cust, repeated, inclusion X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (192.185.146.7) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 Nov 2017 22:36:16 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 0EEAA5C40 for ; Thu, 2 Nov 2017 17:36:15 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id AO5veIky6pOTvAO5ve4KmD; Thu, 02 Nov 2017 17:36:15 -0500 Received: from 71-218-90-63.hlrn.qwest.net ([71.218.90.63]:58978 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eAO5u-003CfJ-Qk; Thu, 02 Nov 2017 17:36:14 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 01/13] Replace really_free_pendings with a scoped_ class Date: Thu, 02 Nov 2017 22:36:00 -0000 Message-Id: <20171102223612.3642-2-tom@tromey.com> In-Reply-To: <20171102223612.3642-1-tom@tromey.com> References: <20171102223612.3642-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1eAO5u-003CfJ-Qk X-Source-Sender: 71-218-90-63.hlrn.qwest.net (bapiya.Home) [71.218.90.63]:58978 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2017-11/txt/msg00052.txt.bz2 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-02 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. --- gdb/ChangeLog | 15 +++++++++++++++ gdb/buildsym.c | 26 ++++++++++---------------- gdb/buildsym.h | 10 +++++++++- gdb/dbxread.c | 10 ++-------- gdb/dwarf2read.c | 12 ++++-------- gdb/xcoffread.c | 10 ++-------- 6 files changed, 42 insertions(+), 41 deletions(-) diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 07bfbd5038..d07bfb3d13 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 60109a0da2..accb1f0347 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 ce00962809..1618a56136 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 686fa3f3d3..433a9272b8 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 ea11b3f966..2e4f30f291 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 -- 2.13.6