commit caf21ec5b9503db75f40d58de005d393da9c10af Author: Vladimir Prus Date: Tue Apr 29 21:31:59 2008 +0400 Introduce common cleanup for restoring integers. * defs.h (make_cleanup_restore_integer): New declaration. * utils.c (restore_integer_closure, restore_integer) (make_cleanup_restore_integer): New. * breakpoint.c (restore_always_inserted_mode): Remove. (update_breakpoints_after_exec): Use make_cleanup_restore_integer. diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 4180ea1..af92d47 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1456,12 +1456,6 @@ reattach_breakpoints (int pid) return 0; } -static void -restore_always_inserted_mode (void *p) -{ - always_inserted_mode = (uintptr_t) p; -} - void update_breakpoints_after_exec (void) { @@ -1477,9 +1471,7 @@ update_breakpoints_after_exec (void) /* The binary we used to debug is now gone, and we're updating breakpoints for the new binary. Until we're done, we should not try to insert breakpoints. */ - cleanup = make_cleanup (restore_always_inserted_mode, - (void *) (uintptr_t) always_inserted_mode); - always_inserted_mode = 0; + cleanup = make_cleanup_restore_integer (&always_inserted_mode, 0); ALL_BREAKPOINTS_SAFE (b, temp) { diff --git a/gdb/defs.h b/gdb/defs.h index 0fa0e6c..7966967 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -345,6 +345,8 @@ extern struct cleanup *make_cleanup_close (int fd); extern struct cleanup *make_cleanup_bfd_close (bfd *abfd); +extern struct cleanup *make_cleanup_restore_integer (int *variable, int value); + extern struct cleanup *make_final_cleanup (make_cleanup_ftype *, void *); extern struct cleanup *make_my_cleanup (struct cleanup **, diff --git a/gdb/utils.c b/gdb/utils.c index d9953a0..fa8e455 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -277,6 +277,33 @@ 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; + xfree (closure); +} + +/* Assign VALUE to *VARIABLE and arranges for the old value to + be restored via cleanup. */ +struct cleanup * +make_cleanup_restore_integer (int *variable, int value) +{ + struct restore_integer_closure *c = + xmalloc (sizeof (struct restore_integer_closure)); + struct cleanup *cleanup = make_cleanup (restore_integer, (void *) c); + c->variable = variable; + c->value = *variable; + *variable = value; + return cleanup; +} struct cleanup * make_my_cleanup (struct cleanup **pmy_chain, make_cleanup_ftype *function,