mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-06 23:50:09 +08:00
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.
This commit is contained in:
@ -1,3 +1,18 @@
|
|||||||
|
2008-06-10 Vladimir Prus <vladimir@codesourcery.com>
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
2008-06-09 Doug Evans <dje@google.com>
|
2008-06-09 Doug Evans <dje@google.com>
|
||||||
|
|
||||||
* remote.c (remote_wait): Include beginning of malformed packet
|
* remote.c (remote_wait): Include beginning of malformed packet
|
||||||
|
@ -1435,12 +1435,6 @@ reattach_breakpoints (int pid)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
restore_always_inserted_mode (void *p)
|
|
||||||
{
|
|
||||||
always_inserted_mode = (uintptr_t) p;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
update_breakpoints_after_exec (void)
|
update_breakpoints_after_exec (void)
|
||||||
{
|
{
|
||||||
@ -1456,8 +1450,7 @@ update_breakpoints_after_exec (void)
|
|||||||
/* The binary we used to debug is now gone, and we're updating
|
/* 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
|
breakpoints for the new binary. Until we're done, we should not
|
||||||
try to insert breakpoints. */
|
try to insert breakpoints. */
|
||||||
cleanup = make_cleanup (restore_always_inserted_mode,
|
cleanup = make_cleanup_restore_integer (&always_inserted_mode);
|
||||||
(void *) (uintptr_t) always_inserted_mode);
|
|
||||||
always_inserted_mode = 0;
|
always_inserted_mode = 0;
|
||||||
|
|
||||||
ALL_BREAKPOINTS_SAFE (b, temp)
|
ALL_BREAKPOINTS_SAFE (b, temp)
|
||||||
|
14
gdb/defs.h
14
gdb/defs.h
@ -230,12 +230,18 @@ enum return_value_convention
|
|||||||
Use make_cleanup to add an element to the cleanup chain.
|
Use make_cleanup to add an element to the cleanup chain.
|
||||||
Use do_cleanups to do all cleanup actions back to a given
|
Use do_cleanups to do all cleanup actions back to a given
|
||||||
point in the chain. Use discard_cleanups to remove cleanups
|
point in the chain. Use discard_cleanups to remove cleanups
|
||||||
from the chain back to a given point, not doing them. */
|
from the chain back to a given point, not doing them.
|
||||||
|
|
||||||
|
If the argument is pointer to allocated memory, then you need to
|
||||||
|
to additionally set the 'free_arg' member to a function that will
|
||||||
|
free that memory. This function will be called both when the cleanup
|
||||||
|
is executed and when it's discarded. */
|
||||||
|
|
||||||
struct cleanup
|
struct cleanup
|
||||||
{
|
{
|
||||||
struct cleanup *next;
|
struct cleanup *next;
|
||||||
void (*function) (void *);
|
void (*function) (void *);
|
||||||
|
void (*free_arg) (void *);
|
||||||
void *arg;
|
void *arg;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -339,11 +345,17 @@ extern struct cleanup *make_cleanup_close (int fd);
|
|||||||
|
|
||||||
extern struct cleanup *make_cleanup_bfd_close (bfd *abfd);
|
extern struct cleanup *make_cleanup_bfd_close (bfd *abfd);
|
||||||
|
|
||||||
|
extern struct cleanup *make_cleanup_restore_integer (int *variable);
|
||||||
|
|
||||||
extern struct cleanup *make_final_cleanup (make_cleanup_ftype *, void *);
|
extern struct cleanup *make_final_cleanup (make_cleanup_ftype *, void *);
|
||||||
|
|
||||||
extern struct cleanup *make_my_cleanup (struct cleanup **,
|
extern struct cleanup *make_my_cleanup (struct cleanup **,
|
||||||
make_cleanup_ftype *, void *);
|
make_cleanup_ftype *, void *);
|
||||||
|
|
||||||
|
extern struct cleanup *make_my_cleanup2 (struct cleanup **,
|
||||||
|
make_cleanup_ftype *, void *,
|
||||||
|
void (*free_arg) (void *));
|
||||||
|
|
||||||
extern struct cleanup *save_cleanups (void);
|
extern struct cleanup *save_cleanups (void);
|
||||||
extern struct cleanup *save_final_cleanups (void);
|
extern struct cleanup *save_final_cleanups (void);
|
||||||
extern struct cleanup *save_my_cleanups (struct cleanup **);
|
extern struct cleanup *save_my_cleanups (struct cleanup **);
|
||||||
|
42
gdb/utils.c
42
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);
|
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_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 *
|
struct cleanup *
|
||||||
make_my_cleanup (struct cleanup **pmy_chain, make_cleanup_ftype *function,
|
make_my_cleanup2 (struct cleanup **pmy_chain, make_cleanup_ftype *function,
|
||||||
void *arg)
|
void *arg, void (*free_arg) (void *))
|
||||||
{
|
{
|
||||||
struct cleanup *new
|
struct cleanup *new
|
||||||
= (struct cleanup *) xmalloc (sizeof (struct cleanup));
|
= (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->next = *pmy_chain;
|
||||||
new->function = function;
|
new->function = function;
|
||||||
|
new->free_arg = free_arg;
|
||||||
new->arg = arg;
|
new->arg = arg;
|
||||||
*pmy_chain = new;
|
*pmy_chain = new;
|
||||||
|
|
||||||
return old_chain;
|
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
|
/* Discard cleanups and do the actions they describe
|
||||||
until we get back to the point OLD_CHAIN in the cleanup_chain. */
|
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 */
|
*pmy_chain = ptr->next; /* Do this first incase recursion */
|
||||||
(*ptr->function) (ptr->arg);
|
(*ptr->function) (ptr->arg);
|
||||||
|
if (ptr->free_arg)
|
||||||
|
(*ptr->free_arg) (ptr->arg);
|
||||||
xfree (ptr);
|
xfree (ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -345,6 +381,8 @@ discard_my_cleanups (struct cleanup **pmy_chain,
|
|||||||
while ((ptr = *pmy_chain) != old_chain)
|
while ((ptr = *pmy_chain) != old_chain)
|
||||||
{
|
{
|
||||||
*pmy_chain = ptr->next;
|
*pmy_chain = ptr->next;
|
||||||
|
if (ptr->free_arg)
|
||||||
|
(*ptr->free_arg) (ptr->arg);
|
||||||
xfree (ptr);
|
xfree (ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user