summaryrefslogtreecommitdiff
path: root/gdb/utils.c
diff options
context:
space:
mode:
authorPedro Alves <pedro@codesourcery.com>2008-07-12 19:25:42 +0000
committerPedro Alves <pedro@codesourcery.com>2008-07-12 19:25:42 +0000
commit25689c9841bbf78589d6e3d014d1c018200c8a20 (patch)
treeb3029e8dc0b6fc8af9c7ae82af059001e22cf97e /gdb/utils.c
parent80c78add4d9210932d785257a3b591a7b228161e (diff)
downloadgdb-25689c9841bbf78589d6e3d014d1c018200c8a20.tar.gz
2008-07-12 Pedro Alves <pedro@codesourcery.com>
Rewrite continuations internals on top of cleanups and plug continuation arguments leaks. * defs.h (struct continuation): Make it opaque. (add_continuation, add_intermediate_continuation): Drop the int argument of the continuation hook argument. Add continuation_free_args argument. (do_all_continuations, do_all_intermediate_continuations): Drop the error_p argument. * utils.c (add_continuation): Drop the int argument of the continuation hook argument. Add continuation_free_args argument. Reimplement on top of cleanups. (do_all_continuations): Drop error argument. Reimplement on top of cleanups. (discard_all_continuations): Reimplement on top of cleanups. (add_intermediate_continuation): Drop the int argument of the continuation hook argument. Add continuation_free_args argument. Reimplement on top of cleanups. (do_all_intermediate_continuations): Drop error argument. Reimplement on top of cleanups. (discard_all_intermediate_continuations): Reimplement on top of cleanups. * breakpoint.c (until_break_command_continuation): Drop error argument. Add xfree as continuation argument deleter. * inf-loop.c (inferior_event_handler): On error, discard all continuations. Adjust to new do_all_intermediate_continuations and do_all_continuations interfaces. * infcmd.c (step_1_continuation): Drop error_p argument. Adjust. Pass xfree as continuation argument deleter. (finish_command_continuation): Drop error_p argument. Adjust. (finish_command_continuation_free_arg): New. (finish_command): Pass finish_command_continuation_free_arg as continuation argument deleter. Adjust to new do_all_continuations interfaces. (attach_command_continuation): Drop error_p argument. (attach_command_continuation_free_args): New. (attach_command): Pass attach_command_continuation_free_args as continuation argument deleter. * interps.c (interp_set): Adjust to new do_all_continuations interfaces. * event-top.c (stdin_event_handler): In error, also discard the intermediate continuations.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r--gdb/utils.c93
1 files changed, 35 insertions, 58 deletions
diff --git a/gdb/utils.c b/gdb/utils.c
index 7f8446bc572..2b34d3e0200 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -473,16 +473,16 @@ null_cleanup (void *arg)
/* Add a continuation to the continuation list, the global list
cmd_continuation. The new continuation will be added at the front.*/
void
-add_continuation (void (*continuation_hook) (void *, int), void *args)
+add_continuation (void (*continuation_hook) (void *), void *args,
+ void (*continuation_free_args) (void *))
{
- struct continuation *continuation_ptr;
+ struct cleanup **as_cleanup_p = (struct cleanup **) &cmd_continuation;
+ make_cleanup_ftype *continuation_hook_fn = continuation_hook;
- continuation_ptr =
- (struct continuation *) xmalloc (sizeof (struct continuation));
- continuation_ptr->continuation_hook = continuation_hook;
- continuation_ptr->args = args;
- continuation_ptr->next = cmd_continuation;
- cmd_continuation = continuation_ptr;
+ make_my_cleanup2 (as_cleanup_p,
+ continuation_hook_fn,
+ args,
+ continuation_free_args);
}
/* Walk down the cmd_continuation list, and execute all the
@@ -494,26 +494,20 @@ add_continuation (void (*continuation_hook) (void *, int), void *args)
and do the continuations from there on, instead of using the
global beginning of list as our iteration pointer. */
void
-do_all_continuations (int error)
+do_all_continuations (void)
{
- struct continuation *continuation_ptr;
- struct continuation *saved_continuation;
+ struct cleanup *continuation_ptr;
/* Copy the list header into another pointer, and set the global
list header to null, so that the global list can change as a side
- effect of invoking the continuations and the processing of
- the preexisting continuations will not be affected. */
- continuation_ptr = cmd_continuation;
+ effect of invoking the continuations and the processing of the
+ preexisting continuations will not be affected. */
+
+ continuation_ptr = (struct cleanup *) cmd_continuation;
cmd_continuation = NULL;
/* Work now on the list we have set aside. */
- while (continuation_ptr)
- {
- (continuation_ptr->continuation_hook) (continuation_ptr->args, error);
- saved_continuation = continuation_ptr;
- continuation_ptr = continuation_ptr->next;
- xfree (saved_continuation);
- }
+ do_my_cleanups (&continuation_ptr, NULL);
}
/* Walk down the cmd_continuation list, and get rid of all the
@@ -521,14 +515,8 @@ do_all_continuations (int error)
void
discard_all_continuations (void)
{
- struct continuation *continuation_ptr;
-
- while (cmd_continuation)
- {
- continuation_ptr = cmd_continuation;
- cmd_continuation = continuation_ptr->next;
- xfree (continuation_ptr);
- }
+ struct cleanup **continuation_ptr = (struct cleanup **) &cmd_continuation;
+ discard_my_cleanups (continuation_ptr, NULL);
}
/* Add a continuation to the continuation list, the global list
@@ -536,16 +524,16 @@ discard_all_continuations (void)
the front. */
void
add_intermediate_continuation (void (*continuation_hook)
- (void *, int), void *args)
+ (void *), void *args,
+ void (*continuation_free_args) (void *))
{
- struct continuation *continuation_ptr;
+ struct cleanup **as_cleanup_p = (struct cleanup **) &intermediate_continuation;
+ make_cleanup_ftype *continuation_hook_fn = continuation_hook;
- continuation_ptr =
- (struct continuation *) xmalloc (sizeof (struct continuation));
- continuation_ptr->continuation_hook = continuation_hook;
- continuation_ptr->args = args;
- continuation_ptr->next = intermediate_continuation;
- intermediate_continuation = continuation_ptr;
+ make_my_cleanup2 (as_cleanup_p,
+ continuation_hook_fn,
+ args,
+ continuation_free_args);
}
/* Walk down the cmd_continuation list, and execute all the
@@ -557,26 +545,20 @@ add_intermediate_continuation (void (*continuation_hook)
and do the continuations from there on, instead of using the
global beginning of list as our iteration pointer.*/
void
-do_all_intermediate_continuations (int error)
+do_all_intermediate_continuations (void)
{
- struct continuation *continuation_ptr;
- struct continuation *saved_continuation;
+ struct cleanup *continuation_ptr;
/* Copy the list header into another pointer, and set the global
list header to null, so that the global list can change as a side
- effect of invoking the continuations and the processing of
- the preexisting continuations will not be affected. */
- continuation_ptr = intermediate_continuation;
+ effect of invoking the continuations and the processing of the
+ preexisting continuations will not be affected. */
+
+ continuation_ptr = (struct cleanup *) intermediate_continuation;
intermediate_continuation = NULL;
/* Work now on the list we have set aside. */
- while (continuation_ptr)
- {
- (continuation_ptr->continuation_hook) (continuation_ptr->args, error);
- saved_continuation = continuation_ptr;
- continuation_ptr = continuation_ptr->next;
- xfree (saved_continuation);
- }
+ do_my_cleanups (&continuation_ptr, NULL);
}
/* Walk down the cmd_continuation list, and get rid of all the
@@ -584,14 +566,9 @@ do_all_intermediate_continuations (int error)
void
discard_all_intermediate_continuations (void)
{
- struct continuation *continuation_ptr;
-
- while (intermediate_continuation)
- {
- continuation_ptr = intermediate_continuation;
- intermediate_continuation = continuation_ptr->next;
- xfree (continuation_ptr);
- }
+ struct cleanup **continuation_ptr
+ = (struct cleanup **) &intermediate_continuation;
+ discard_my_cleanups (continuation_ptr, NULL);
}