From fe7b42e5843ef82f97959e0e18122c164449a8ea Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 24 Jan 2019 09:56:49 -0700 Subject: Remove basic cleanup code 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. 2019-03-06 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(-) (limited to 'gdb') diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 38ce62f..a311b82 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,29 @@ 2019-03-06 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. + +2019-03-06 Tom Tromey + * remote.c (remote_target::remote_parse_stop_reply): Use unique_xmalloc_ptr. diff --git a/gdb/common/cleanups.c b/gdb/common/cleanups.c index 086371a..121720d 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,31 +103,12 @@ 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) { return make_my_cleanup (&final_cleanup_chain, function, 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 f49bcb4..e676076 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 5e86c7b..4e67e89 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 8c07ffa..cff6686 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 e14dd06..97ffc3f 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 22e6f7e..4065df7 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) { -- cgit v1.1