From patchwork Thu Nov 2 22:36:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 24057 Received: (qmail 7858 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-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 7322 invoked by uid 89); 2 Nov 2017 22:36:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=blow, rfa X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.185.36) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 Nov 2017 22:36:18 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 6FF24400E4EB7 for ; Thu, 2 Nov 2017 17:36:17 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id AO5xeb86lrWstAO5xeKU7o; Thu, 02 Nov 2017 17:36:17 -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 1eAO5x-003CfJ-89; Thu, 02 Nov 2017 17:36:17 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 08/13] Remove make_cleanup_free_objfile Date: Thu, 2 Nov 2017 16:36:07 -0600 Message-Id: <20171102223612.3642-9-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: 1eAO5x-003CfJ-89 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: 9 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This replaces make_cleanup_free_objfile with std::unique_ptr. gdb/ChangeLog 2017-11-02 Tom Tromey * objfiles.c (do_free_objfile_cleanup): Remove. * compile/compile-object-load.c (compile_object_load): Update. * objfiles.h (make_cleanup_free_objfile): Remove. --- gdb/ChangeLog | 6 ++++++ gdb/compile/compile-object-load.c | 13 ++++++------- gdb/objfiles.c | 12 ------------ gdb/objfiles.h | 2 -- gdb/symfile.c | 10 +++++++--- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c index 8e55d3c2c9..e69fbc6c9c 100644 --- a/gdb/compile/compile-object-load.c +++ b/gdb/compile/compile-object-load.c @@ -606,7 +606,7 @@ struct compile_module * compile_object_load (const compile_file_names &file_names, enum compile_i_scope_types scope, void *scope_data) { - struct cleanup *cleanups, *cleanups_free_objfile; + struct cleanup *cleanups; struct setup_sections_data setup_sections_data; CORE_ADDR addr, regs_addr, out_value_addr = 0; struct symbol *func_sym; @@ -656,9 +656,10 @@ compile_object_load (const compile_file_names &file_names, /* SYMFILE_VERBOSE is not passed even if FROM_TTY, user is not interested in "Reading symbols from ..." message for automatically generated file. */ - objfile = symbol_file_add_from_bfd (abfd.get (), filename.get (), - 0, NULL, 0, NULL); - cleanups_free_objfile = make_cleanup_free_objfile (objfile); + std::unique_ptr objfile_holder + (symbol_file_add_from_bfd (abfd.get (), filename.get (), + 0, NULL, 0, NULL)); + objfile = objfile_holder.get (); func_sym = lookup_global_symbol_from_objfile (objfile, GCC_FE_WRAPPER_FUNCTION, @@ -812,10 +813,8 @@ compile_object_load (const compile_file_names &file_names, paddress (target_gdbarch (), out_value_addr)); } - discard_cleanups (cleanups_free_objfile); - retval = XNEW (struct compile_module); - retval->objfile = objfile; + retval->objfile = objfile_holder.release (); retval->source_file = xstrdup (file_names.source_file ()); retval->func_sym = func_sym; retval->regs_addr = regs_addr; diff --git a/gdb/objfiles.c b/gdb/objfiles.c index d8fe88b136..edde399802 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -729,18 +729,6 @@ objfile::~objfile () htab_delete (static_links); } -static void -do_free_objfile_cleanup (void *obj) -{ - delete (struct objfile *) obj; -} - -struct cleanup * -make_cleanup_free_objfile (struct objfile *obj) -{ - return make_cleanup (do_free_objfile_cleanup, obj); -} - /* Free all the object files at once and clean up their users. */ void diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 453166a001..4f11756248 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -479,8 +479,6 @@ extern void unlink_objfile (struct objfile *); extern void free_objfile_separate_debug (struct objfile *); -extern struct cleanup *make_cleanup_free_objfile (struct objfile *); - extern void free_all_objfiles (void); extern void objfile_relocate (struct objfile *, const struct section_offsets *); diff --git a/gdb/symfile.c b/gdb/symfile.c index fb63441ac0..4077c2e31c 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -997,7 +997,8 @@ syms_from_objfile_1 (struct objfile *objfile, /* Make sure that partially constructed symbol tables will be cleaned up if an error occurs during symbol reading. */ - old_chain = make_cleanup_free_objfile (objfile); + old_chain = make_cleanup (null_cleanup, NULL); + std::unique_ptr objfile_holder (objfile); /* If ADDRS is NULL, put together a dummy address list. We now establish the convention that an addr of zero means @@ -1053,6 +1054,7 @@ syms_from_objfile_1 (struct objfile *objfile, /* Discard cleanups as symbol reading was successful. */ + objfile_holder.release (); discard_cleanups (old_chain); xfree (local_addr); } @@ -2436,9 +2438,10 @@ reread_symbols (void) /* If we get an error, blow away this objfile (not sure if that is the correct response for things like shared libraries). */ - old_cleanups = make_cleanup_free_objfile (objfile); + std::unique_ptr objfile_holder (objfile); + /* We need to do this whenever any symbols go away. */ - make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/); + old_cleanups = make_cleanup (clear_symtab_users_cleanup, 0 /*ignore*/); if (exec_bfd != NULL && filename_cmp (bfd_get_filename (objfile->obfd), @@ -2600,6 +2603,7 @@ reread_symbols (void) reinit_frame_cache (); /* Discard cleanups as symbol reading was successful. */ + objfile_holder.release (); discard_cleanups (old_cleanups); /* If the mtime has changed between the time we set new_modtime