aboutsummaryrefslogtreecommitdiff
path: root/gdb/utils.c
diff options
context:
space:
mode:
authorVladimir Prus <vladimir@codesourcery.com>2008-06-10 09:29:15 +0000
committerVladimir Prus <vladimir@codesourcery.com>2008-06-10 09:29:15 +0000
commit0b080f5982d636d473d4fb9e62ef1ee00b28fdbc (patch)
tree1bcc2168a81286fcb2ed029576c282e77c3c8736 /gdb/utils.c
parent3201a343ca2a328894f3d0384082eed9b757cf03 (diff)
downloadgdb-0b080f5982d636d473d4fb9e62ef1ee00b28fdbc.zip
gdb-0b080f5982d636d473d4fb9e62ef1ee00b28fdbc.tar.gz
gdb-0b080f5982d636d473d4fb9e62ef1ee00b28fdbc.tar.bz2
Introduce common cleanup for restoring integers.
* defs.h (make_cleanup_restore_integer): New declaration. (struct cleanup): New field free_arg. (make_my_cleanup_2): New. * utils.c (restore_integer_closure, restore_integer) (make_cleanup_restore_integer): New. (make_my_cleanup): Initialize the free_arg field and renamed to make_my_cleanup_2. (do_my_cleanups): Call free_arg. (discard_cleanups): Call free_arg. * breakpoint.c (restore_always_inserted_mode): Remove. (update_breakpoints_after_exec): Use make_cleanup_restore_integer.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r--gdb/utils.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/gdb/utils.c b/gdb/utils.c
index 76ea6b1..cdea5a6 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -277,10 +277,36 @@ make_cleanup_free_section_addr_info (struct section_addr_info *addrs)
return make_my_cleanup (&cleanup_chain, do_free_section_addr_info, addrs);
}
+struct restore_integer_closure
+{
+ int *variable;
+ int value;
+};
+
+static void
+restore_integer (void *p)
+{
+ struct restore_integer_closure *closure = p;
+ *(closure->variable) = closure->value;
+}
+/* Remember the current value of *VARIABLE and make it restored when the cleanup
+ is run. */
struct cleanup *
-make_my_cleanup (struct cleanup **pmy_chain, make_cleanup_ftype *function,
- void *arg)
+make_cleanup_restore_integer (int *variable)
+{
+ struct restore_integer_closure *c =
+ xmalloc (sizeof (struct restore_integer_closure));
+ c->variable = variable;
+ c->value = *variable;
+
+ return make_my_cleanup2 (&cleanup_chain, restore_integer, (void *)c,
+ xfree);
+}
+
+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));
@@ -288,12 +314,20 @@ make_my_cleanup (struct cleanup **pmy_chain, make_cleanup_ftype *function,
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. */
@@ -318,6 +352,8 @@ do_my_cleanups (struct cleanup **pmy_chain,
{
*pmy_chain = ptr->next; /* Do this first incase recursion */
(*ptr->function) (ptr->arg);
+ if (ptr->free_arg)
+ (*ptr->free_arg) (ptr->arg);
xfree (ptr);
}
}
@@ -345,6 +381,8 @@ discard_my_cleanups (struct cleanup **pmy_chain,
while ((ptr = *pmy_chain) != old_chain)
{
*pmy_chain = ptr->next;
+ if (ptr->free_arg)
+ (*ptr->free_arg) (ptr->arg);
xfree (ptr);
}
}