aboutsummaryrefslogtreecommitdiff
path: root/gdb/utils.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2012-04-17 21:13:20 +0000
committerDoug Evans <dje@google.com>2012-04-17 21:13:20 +0000
commitc27f5738407bad7199f3d532b3648f24508a7fd4 (patch)
tree3a0ad69a1ff223ae1034c7cd71b3253bc5b83e23 /gdb/utils.c
parente0088cfdc713f852a4e85aab36d67a91293e9ede (diff)
downloadgdb-c27f5738407bad7199f3d532b3648f24508a7fd4.zip
gdb-c27f5738407bad7199f3d532b3648f24508a7fd4.tar.gz
gdb-c27f5738407bad7199f3d532b3648f24508a7fd4.tar.bz2
* cleanups.h: New file.
* cleanups.c: New file. * Makefile.in (SFILES): Add cleanups.c. (HFILES_NO_SRCDIR): Add cleanups.h. (COMMON_OBS): Add cleanups.o. * defs.h (struct cleanup): Moved to cleanups.h. (do_cleanups,do_final_cleanups): Ditto. (discard_cleanups,discard_final_cleanups): Ditto (make_cleanup,make_cleanup_dtor,make_final_cleanup): Ditto. (save_cleanups,save_final_cleanups): Ditto. (restore_cleanups,restore_final_cleanups): Ditto. (null_cleanup): Ditto. (make_my_cleanup,make_my_cleanup2): Ditto. (discard_my_cleanups,save_my_cleanups,restore_my_cleanups): Ditto. * utils.c (cleanup_chain,final_cleanup_chain): Moved to cleanups.c. (do_cleanups,do_final_cleanups): Ditto. (discard_cleanups,discard_final_cleanups): Ditto (make_cleanup,make_cleanup_dtor,make_final_cleanup): Ditto. (save_cleanups,save_final_cleanups): Ditto. (restore_cleanups,restore_final_cleanups): Ditto. (null_cleanup): Ditto. (make_my_cleanup,make_my_cleanup2): Ditto. (discard_my_cleanups,save_my_cleanups,restore_my_cleanups): Ditto.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r--gdb/utils.c174
1 files changed, 4 insertions, 170 deletions
diff --git a/gdb/utils.c b/gdb/utils.c
index a8f9e4f..b70edd8 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -99,8 +99,6 @@ static void vfprintf_maybe_filtered (struct ui_file *, const char *,
static void fputs_maybe_filtered (const char *, struct ui_file *, int);
-static void do_my_cleanups (struct cleanup **, struct cleanup *);
-
static void prompt_for_continue (void);
static void set_screen_size (void);
@@ -110,12 +108,6 @@ static void set_width (void);
static int debug_timestamp = 0;
-/* Chain of cleanup actions established with make_cleanup,
- to be executed if an error happens. */
-
-static struct cleanup *cleanup_chain; /* cleaned up after a failed command */
-static struct cleanup *final_cleanup_chain; /* cleaned up when gdb exits */
-
/* Nonzero if we have job control. */
int job_control;
@@ -172,31 +164,11 @@ show_pagination_enabled (struct ui_file *file, int from_tty,
}
+/* Cleanup utilities.
-/* Add a new cleanup to the 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);
-}
-
-struct cleanup *
-make_cleanup_dtor (make_cleanup_ftype *function, void *arg,
- void (*dtor) (void *))
-{
- return make_my_cleanup2 (&cleanup_chain,
- function, arg, dtor);
-}
-
-struct cleanup *
-make_final_cleanup (make_cleanup_ftype *function, void *arg)
-{
- return make_my_cleanup (&final_cleanup_chain, function, arg);
-}
+ These are not defined in cleanups.c (nor declared in cleanups.h)
+ because while they use the "cleanup API" they are not part of the
+ "cleanup API". */
static void
do_freeargv (void *arg)
@@ -484,132 +456,6 @@ make_cleanup_free_so (struct so_list *so)
return make_cleanup (do_free_so, so);
}
-struct cleanup *
-make_my_cleanup2 (struct cleanup **pmy_chain, make_cleanup_ftype *function,
- void *arg, void (*free_arg) (void *))
-{
- struct cleanup *new
- = (struct cleanup *) xmalloc (sizeof (struct cleanup));
- struct cleanup *old_chain = *pmy_chain;
-
- new->next = *pmy_chain;
- new->function = function;
- new->free_arg = free_arg;
- new->arg = arg;
- *pmy_chain = new;
-
- return old_chain;
-}
-
-struct cleanup *
-make_my_cleanup (struct cleanup **pmy_chain, make_cleanup_ftype *function,
- void *arg)
-{
- return make_my_cleanup2 (pmy_chain, function, arg, NULL);
-}
-
-/* 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);
-}
-
-void
-do_final_cleanups (struct cleanup *old_chain)
-{
- do_my_cleanups (&final_cleanup_chain, old_chain);
-}
-
-static void
-do_my_cleanups (struct cleanup **pmy_chain,
- struct cleanup *old_chain)
-{
- struct cleanup *ptr;
-
- while ((ptr = *pmy_chain) != old_chain)
- {
- *pmy_chain = ptr->next; /* Do this first in case of recursion. */
- (*ptr->function) (ptr->arg);
- 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);
-}
-
-void
-discard_final_cleanups (struct cleanup *old_chain)
-{
- discard_my_cleanups (&final_cleanup_chain, old_chain);
-}
-
-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);
- }
-}
-
-/* Set the cleanup_chain to 0, and return the old cleanup chain. */
-struct cleanup *
-save_cleanups (void)
-{
- return save_my_cleanups (&cleanup_chain);
-}
-
-struct cleanup *
-save_final_cleanups (void)
-{
- return save_my_cleanups (&final_cleanup_chain);
-}
-
-struct cleanup *
-save_my_cleanups (struct cleanup **pmy_chain)
-{
- struct cleanup *old_chain = *pmy_chain;
-
- *pmy_chain = 0;
- return old_chain;
-}
-
-/* Restore the cleanup chain from a previously saved chain. */
-void
-restore_cleanups (struct cleanup *chain)
-{
- restore_my_cleanups (&cleanup_chain, chain);
-}
-
-void
-restore_final_cleanups (struct cleanup *chain)
-{
- restore_my_cleanups (&final_cleanup_chain, chain);
-}
-
-void
-restore_my_cleanups (struct cleanup **pmy_chain, struct cleanup *chain)
-{
- *pmy_chain = chain;
-}
-
/* This function is useful for cleanups.
Do
@@ -633,18 +479,6 @@ free_current_contents (void *ptr)
}
}
-/* 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. */
-
-void
-null_cleanup (void *arg)
-{
-}
-
/* If nonzero, display time usage both at startup and for each command. */
static int display_time;