--- a/gdb/utils.c +++ b/gdb/utils.c @@ -385,6 +385,35 @@ make_cleanup_restore_uinteger (unsigned return make_cleanup_restore_integer ((int *) variable); } +struct restore_ptr_closure +{ + void **variable; + void *value; +}; + +static void +restore_ptr (void *p) +{ + struct restore_ptr_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_cleanup_restore_ptr (void **variable) +{ + struct restore_ptr_closure *c = + xmalloc (sizeof (struct restore_ptr_closure)); + + c->variable = variable; + c->value = *variable; + + return make_cleanup_dtor (restore_ptr, (void *) c, xfree); +} + /* Helper for make_cleanup_unpush_target. */ static void --- a/gdb/utils.h +++ b/gdb/utils.h @@ -97,6 +97,7 @@ extern struct cleanup *make_cleanup_obst extern struct cleanup *make_cleanup_restore_integer (int *variable); extern struct cleanup *make_cleanup_restore_uinteger (unsigned int *variable); +extern struct cleanup *make_cleanup_restore_ptr (void **variable); struct target_ops; extern struct cleanup *make_cleanup_unpush_target (struct target_ops *ops);