From patchwork Wed Feb 27 20:18:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31668 Received: (qmail 122304 invoked by alias); 27 Feb 2019 20:19:53 -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 121905 invoked by uid 89); 27 Feb 2019 20:19:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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=ordinary, behaved, threw X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.234) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 27 Feb 2019 20:19:47 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 464E82804E for ; Wed, 27 Feb 2019 14:18:56 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id z5fMgYLkX4FKpz5fMgqALk; Wed, 27 Feb 2019 14:18:56 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=WV4URQ+pyfHktqPuS4VZGm7TXki6tDnHRZI8D2g2XuU=; b=SeYZTDHzKYWyypzJWe1GKifUBD tM1FMmSOQxn1HwGn5d3ftY1SaJFXEUsTfKSgDi+pquszT2CVN64f86hy4jSec3018iIWWlhUqCl3a SJusdm5nexpONUy8UtpJIBeiF; Received: from 75-166-85-218.hlrn.qwest.net ([75.166.85.218]:36364 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gz5fM-004Fi1-2O; Wed, 27 Feb 2019 14:18:56 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 12/22] Remove basic cleanup code Date: Wed, 27 Feb 2019 13:18:39 -0700 Message-Id: <20190227201849.32210-13-tom@tromey.com> In-Reply-To: <20190227201849.32210-1-tom@tromey.com> References: <20190227201849.32210-1-tom@tromey.com> This removes the basic cleanup code: make_cleanups, do_cleanups, discard_cleanups, and friends. This code is no longer needed, as nothing in gdb makes an ordinary cleanup. Final cleanups are still needed. gdb/ChangeLog 2019-02-27 Tom Tromey * top.c (quit_force): Update. * main.c (captured_command_loop): Update. * common/new-op.c (operator new): Update. * common/common-exceptions.c (struct catcher) : Remove member. (exceptions_state_mc_init): Update. (exception_try_scope_entry): Return nullptr. (exception_try_scope_exit, exception_rethrow) (throw_exception_sjlj, throw_exception_cxx): Update. * common/cleanups.h (make_cleanup, make_cleanup_dtor) (all_cleanups, do_cleanups, discard_cleanups) (discard_final_cleanups, save_cleanups, save_final_cleanups) (restore_cleanups, restore_final_cleanups): Don't declare. (do_final_cleanups): Remove parameter. * common/cleanups.c (cleanup_chain, make_cleanup) (make_cleanup_dtor, all_cleanups, do_cleanups) (discard_my_cleanups, discard_cleanups) (discard_final_cleanups, save_my_cleanups, save_cleanups) (save_final_cleanups, restore_my_cleanups, restore_cleanups) (null_cleanup): Remove. (do_final_cleanups): Remove parameter. --- gdb/ChangeLog | 24 +++++ gdb/common/cleanups.c | 160 +-------------------------------- gdb/common/cleanups.h | 32 +------ gdb/common/common-exceptions.c | 20 +---- gdb/common/new-op.c | 2 - gdb/main.c | 8 -- gdb/top.c | 2 +- 7 files changed, 31 insertions(+), 217 deletions(-) diff --git a/gdb/common/cleanups.c b/gdb/common/cleanups.c index 086371a7c96..121720d3c0f 100644 --- a/gdb/common/cleanups.c +++ b/gdb/common/cleanups.c @@ -58,10 +58,6 @@ static const struct cleanup sentinel_cleanup = { 0, 0, 0, 0 }; /* Handy macro to use when referring to sentinel_cleanup. */ #define SENTINEL_CLEANUP ((struct cleanup *) &sentinel_cleanup) -/* Chain of cleanup actions established with make_cleanup, - to be executed if an error happens. */ -static struct cleanup *cleanup_chain = SENTINEL_CLEANUP; - /* Chain of cleanup actions established with make_final_cleanup, to be executed when gdb exits. */ static struct cleanup *final_cleanup_chain = SENTINEL_CLEANUP; @@ -107,30 +103,11 @@ make_my_cleanup (struct cleanup **pmy_chain, make_cleanup_ftype *function, return make_my_cleanup2 (pmy_chain, function, arg, NULL); } -/* Add a new cleanup to the cleanup_chain, +/* Add a new cleanup to the final cleanup_chain, and return the previous chain pointer to be passed later to do_cleanups or discard_cleanups. Args are FUNCTION to clean up with, and ARG to pass to it. */ -struct cleanup * -make_cleanup (make_cleanup_ftype *function, void *arg) -{ - return make_my_cleanup (&cleanup_chain, function, arg); -} - -/* Same as make_cleanup except also includes DTOR, a destructor to free ARG. - DTOR is invoked when the cleanup is performed or when it is discarded. */ - -struct cleanup * -make_cleanup_dtor (make_cleanup_ftype *function, void *arg, - make_cleanup_dtor_ftype *dtor) -{ - return make_my_cleanup2 (&cleanup_chain, - function, arg, dtor); -} - -/* Same as make_cleanup except the cleanup is added to final_cleanup_chain. */ - struct cleanup * make_final_cleanup (make_cleanup_ftype *function, void *arg) { @@ -158,139 +135,10 @@ do_my_cleanups (struct cleanup **pmy_chain, } } -/* Return a value that can be passed to do_cleanups, do_final_cleanups to - indicate perform all cleanups. */ - -struct cleanup * -all_cleanups (void) -{ - return SENTINEL_CLEANUP; -} - -/* Discard cleanups and do the actions they describe - until we get back to the point OLD_CHAIN in the cleanup_chain. */ - -void -do_cleanups (struct cleanup *old_chain) -{ - do_my_cleanups (&cleanup_chain, old_chain); -} - -/* Discard cleanups and do the actions they describe - until we get back to the point OLD_CHAIN in the final_cleanup_chain. */ - -void -do_final_cleanups (struct cleanup *old_chain) -{ - do_my_cleanups (&final_cleanup_chain, old_chain); -} - -/* Main worker routine to discard cleanups. - PMY_CHAIN is a pointer to either cleanup_chain or final_cleanup_chain. - OLD_CHAIN is the result of a "make" cleanup routine. - Cleanups are discarded until we get back to the old end of the chain. */ - -static void -discard_my_cleanups (struct cleanup **pmy_chain, - struct cleanup *old_chain) -{ - struct cleanup *ptr; - - while ((ptr = *pmy_chain) != old_chain) - { - *pmy_chain = ptr->next; - if (ptr->free_arg) - (*ptr->free_arg) (ptr->arg); - xfree (ptr); - } -} - -/* Discard cleanups, not doing the actions they describe, - until we get back to the point OLD_CHAIN in the cleanup chain. */ - -void -discard_cleanups (struct cleanup *old_chain) -{ - discard_my_cleanups (&cleanup_chain, old_chain); -} - -/* Discard final cleanups, not doing the actions they describe, - until we get back to the point OLD_CHAIN in the final cleanup chain. */ - -void -discard_final_cleanups (struct cleanup *old_chain) -{ - discard_my_cleanups (&final_cleanup_chain, old_chain); -} - -/* Main worker routine to save cleanups. - PMY_CHAIN is a pointer to either cleanup_chain or final_cleanup_chain. - The chain is emptied and the result is a pointer to the old chain. */ - -static struct cleanup * -save_my_cleanups (struct cleanup **pmy_chain) -{ - struct cleanup *old_chain = *pmy_chain; - - *pmy_chain = SENTINEL_CLEANUP; - return old_chain; -} - -/* Set the cleanup_chain to 0, and return the old cleanup_chain. */ - -struct cleanup * -save_cleanups (void) -{ - return save_my_cleanups (&cleanup_chain); -} - -/* Set the final_cleanup_chain to 0, and return the old - final_cleanup_chain. */ - -struct cleanup * -save_final_cleanups (void) -{ - return save_my_cleanups (&final_cleanup_chain); -} - -/* Main worker routine to save cleanups. - PMY_CHAIN is a pointer to either cleanup_chain or final_cleanup_chain. - The chain is restored from CHAIN. */ - -static void -restore_my_cleanups (struct cleanup **pmy_chain, struct cleanup *chain) -{ - if (*pmy_chain != SENTINEL_CLEANUP) - internal_warning (__FILE__, __LINE__, - _("restore_my_cleanups has found a stale cleanup")); - - *pmy_chain = chain; -} - -/* Restore the cleanup chain from a previously saved chain. */ - -void -restore_cleanups (struct cleanup *chain) -{ - restore_my_cleanups (&cleanup_chain, chain); -} - -/* Restore the final cleanup chain from a previously saved chain. */ - -void -restore_final_cleanups (struct cleanup *chain) -{ - restore_my_cleanups (&final_cleanup_chain, chain); -} - -/* Provide a known function that does nothing, to use as a base for - a possibly long chain of cleanups. This is useful where we - use the cleanup chain for handling normal cleanups as well as dealing - with cleanups that need to be done as a result of a call to error(). - In such cases, we may not be certain where the first cleanup is, unless - we have a do-nothing one to always use as the base. */ +/* Discard final cleanups and do the actions they describe. */ void -null_cleanup (void *arg) +do_final_cleanups () { + do_my_cleanups (&final_cleanup_chain, SENTINEL_CLEANUP); } diff --git a/gdb/common/cleanups.h b/gdb/common/cleanups.h index f49bcb40d14..e676076a16d 100644 --- a/gdb/common/cleanups.h +++ b/gdb/common/cleanups.h @@ -32,38 +32,8 @@ typedef void (make_cleanup_ftype) (void *); /* Function type for the dtor in make_cleanup_dtor. */ typedef void (make_cleanup_dtor_ftype) (void *); -/* WARNING: The result of the "make cleanup" routines is not the intuitive - choice of being a handle on the just-created cleanup. Instead it is an - opaque handle of the cleanup mechanism and represents all cleanups created - from that point onwards. - The result is guaranteed to be non-NULL though. */ - -extern struct cleanup *make_cleanup (make_cleanup_ftype *, void *); - -extern struct cleanup *make_cleanup_dtor (make_cleanup_ftype *, void *, - make_cleanup_dtor_ftype *); - extern struct cleanup *make_final_cleanup (make_cleanup_ftype *, void *); -/* A special value to pass to do_cleanups and do_final_cleanups - to tell them to do all cleanups. */ -extern struct cleanup *all_cleanups (void); - -extern void do_cleanups (struct cleanup *); -extern void do_final_cleanups (struct cleanup *); - -extern void discard_cleanups (struct cleanup *); -extern void discard_final_cleanups (struct cleanup *); - -extern struct cleanup *save_cleanups (void); -extern struct cleanup *save_final_cleanups (void); - -extern void restore_cleanups (struct cleanup *); -extern void restore_final_cleanups (struct cleanup *); - -/* A no-op cleanup. - This is useful when you want to establish a known reference point - to pass to do_cleanups. */ -extern void null_cleanup (void *); +extern void do_final_cleanups (); #endif /* COMMON_CLEANUPS_H */ diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c index 5e86c7b4260..4e67e898bda 100644 --- a/gdb/common/common-exceptions.c +++ b/gdb/common/common-exceptions.c @@ -47,7 +47,6 @@ struct catcher jmp_buf buf; /* Status buffer belonging to the exception handler. */ struct gdb_exception exception; - struct cleanup *saved_cleanup_chain; /* Back link. */ struct catcher *prev; }; @@ -83,10 +82,6 @@ exceptions_state_mc_init (void) /* Start with no exception. */ new_catcher->exception = exception_none; - /* Prevent error/quit during FUNC from calling cleanups established - prior to here. */ - new_catcher->saved_cleanup_chain = save_cleanups (); - /* Push this new catcher on the top. */ new_catcher->prev = current_catcher; current_catcher = new_catcher; @@ -102,11 +97,6 @@ catcher_pop (void) current_catcher = old_catcher->prev; - /* Restore the cleanup chain, the error/quit messages, and the uiout - builder, to their original states. */ - - restore_cleanups (old_catcher->saved_cleanup_chain); - xfree (old_catcher); } @@ -228,7 +218,7 @@ void * exception_try_scope_entry (void) { ++try_scope_depth; - return (void *) save_cleanups (); + return nullptr; } /* Called on exit of a TRY scope, either normal exit or exception @@ -237,7 +227,6 @@ exception_try_scope_entry (void) void exception_try_scope_exit (void *saved_state) { - restore_cleanups ((struct cleanup *) saved_state); --try_scope_depth; } @@ -248,9 +237,6 @@ exception_try_scope_exit (void *saved_state) void exception_rethrow (void) { - /* Run this scope's cleanups before re-throwing to the next - outermost scope. */ - do_cleanups (all_cleanups ()); throw; } @@ -269,8 +255,6 @@ gdb_exception_sliced_copy (struct gdb_exception *to, const struct gdb_exception void throw_exception_sjlj (struct gdb_exception exception) { - do_cleanups (all_cleanups ()); - /* Jump to the nearest CATCH_SJLJ block, communicating REASON to that call via setjmp's return value. Note that REASON can't be zero, by definition in common-exceptions.h. */ @@ -286,8 +270,6 @@ throw_exception_sjlj (struct gdb_exception exception) static ATTRIBUTE_NORETURN void throw_exception_cxx (struct gdb_exception exception) { - do_cleanups (all_cleanups ()); - if (exception.reason == RETURN_QUIT) { gdb_exception_RETURN_MASK_QUIT ex; diff --git a/gdb/common/new-op.c b/gdb/common/new-op.c index 8c07ffac23b..cff6686ef12 100644 --- a/gdb/common/new-op.c +++ b/gdb/common/new-op.c @@ -66,8 +66,6 @@ operator new (std::size_t sz) } CATCH (ex, RETURN_MASK_ALL) { - do_cleanups (all_cleanups ()); - throw gdb_quit_bad_alloc (ex); } END_CATCH diff --git a/gdb/main.c b/gdb/main.c index e14dd06fa8c..97ffc3fba48 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -330,14 +330,6 @@ captured_command_loop () /* Now it's time to start the event loop. */ start_event_loop (); - /* FIXME: cagney/1999-11-05: A correct command_loop() implementaton - would clean things up (restoring the cleanup chain) to the state - they were just prior to the call. Technically, this means that - the do_cleanups() below is redundant. Unfortunately, many FUNCs - are not that well behaved. do_cleanups should either be replaced - with a do_cleanups call (to cover the problem) or an assertion - check to detect bad FUNCs code. */ - do_cleanups (all_cleanups ()); /* If the command_loop returned, normally (rather than threw an error) we try to quit. If the quit is aborted, our caller catches the signal and restarts the command loop. */ diff --git a/gdb/top.c b/gdb/top.c index 22e6f7e29ab..4065df70815 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1675,7 +1675,7 @@ quit_force (int *exit_arg, int from_tty) /* Do any final cleanups before exiting. */ TRY { - do_final_cleanups (all_cleanups ()); + do_final_cleanups (); } CATCH (ex, RETURN_MASK_ALL) {