2011-05-27 22:00:25 +08:00
|
|
|
/* Continuations for GDB, the GNU debugger.
|
|
|
|
|
2015-01-01 17:32:14 +08:00
|
|
|
Copyright (C) 1986-2015 Free Software Foundation, Inc.
|
2011-05-27 22:00:25 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "gdbthread.h"
|
|
|
|
#include "inferior.h"
|
2011-05-27 Pedro Alves <pedro@codesourcery.com>
* defs.h (struct continuation, continuation_ftype)
(continuation_free_arg_ftype, add_continuation)
(do_all_continuations, do_all_continuations_thread)
(discard_all_continuations, discard_all_continuations_thread)
(add_intermediate_continuation, do_all_intermediate_continuations)
(do_all_intermediate_continuations_thread)
(discard_all_intermediate_continuations)
(discard_all_intermediate_continuations_thread)
(add_inferior_continuation, do_all_inferior_continuations)
(discard_all_inferior_continuations): Move to ...
* continuations.h: ... this new file.
* breakpoint.c, continuations.c, event-top.c, inf-loop.c,
infcmd.c, inferior.c, infrun.c, interps.c: Include
continuations.h.
2011-05-28 02:28:18 +08:00
|
|
|
#include "continuations.h"
|
2011-05-27 22:00:25 +08:00
|
|
|
|
|
|
|
struct continuation
|
|
|
|
{
|
|
|
|
struct continuation *next;
|
2011-05-27 22:56:14 +08:00
|
|
|
continuation_ftype *function;
|
|
|
|
continuation_free_arg_ftype *free_arg;
|
2011-05-27 22:00:25 +08:00
|
|
|
void *arg;
|
|
|
|
};
|
|
|
|
|
2011-05-27 22:32:08 +08:00
|
|
|
/* Add a new continuation to the continuation chain. Args are
|
|
|
|
FUNCTION to run the continuation up with, and ARG to pass to
|
|
|
|
it. */
|
2011-05-27 22:00:25 +08:00
|
|
|
|
2011-05-27 22:32:08 +08:00
|
|
|
static void
|
2011-05-27 22:00:25 +08:00
|
|
|
make_continuation (struct continuation **pmy_chain,
|
2011-05-27 22:56:14 +08:00
|
|
|
continuation_ftype *function,
|
2011-05-27 22:00:25 +08:00
|
|
|
void *arg, void (*free_arg) (void *))
|
|
|
|
{
|
2015-02-28 00:33:07 +08:00
|
|
|
struct continuation *newobj = XNEW (struct continuation);
|
2011-05-27 22:00:25 +08:00
|
|
|
|
2015-02-28 00:33:07 +08:00
|
|
|
newobj->next = *pmy_chain;
|
|
|
|
newobj->function = function;
|
|
|
|
newobj->free_arg = free_arg;
|
|
|
|
newobj->arg = arg;
|
|
|
|
*pmy_chain = newobj;
|
2011-05-27 22:00:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-31 02:04:32 +08:00
|
|
|
do_my_continuations_1 (struct continuation **pmy_chain, int err)
|
2011-05-27 22:00:25 +08:00
|
|
|
{
|
|
|
|
struct continuation *ptr;
|
|
|
|
|
2011-05-27 22:32:08 +08:00
|
|
|
while ((ptr = *pmy_chain) != NULL)
|
2011-05-27 22:00:25 +08:00
|
|
|
{
|
|
|
|
*pmy_chain = ptr->next; /* Do this first in case of recursion. */
|
2011-05-31 02:04:32 +08:00
|
|
|
(*ptr->function) (ptr->arg, err);
|
2011-05-27 22:00:25 +08:00
|
|
|
if (ptr->free_arg)
|
|
|
|
(*ptr->free_arg) (ptr->arg);
|
|
|
|
xfree (ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-27 22:32:08 +08:00
|
|
|
static void
|
2011-05-31 02:04:32 +08:00
|
|
|
do_my_continuations (struct continuation **list, int err)
|
2011-05-27 22:32:08 +08:00
|
|
|
{
|
|
|
|
struct continuation *continuations;
|
|
|
|
|
|
|
|
if (*list == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
|
|
|
|
continuations = *list;
|
|
|
|
*list = NULL;
|
|
|
|
|
|
|
|
/* Work now on the list we have set aside. */
|
2011-05-31 02:04:32 +08:00
|
|
|
do_my_continuations_1 (&continuations, err);
|
2011-05-27 22:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
discard_my_continuations_1 (struct continuation **pmy_chain)
|
2011-05-27 22:00:25 +08:00
|
|
|
{
|
|
|
|
struct continuation *ptr;
|
|
|
|
|
2011-05-27 22:32:08 +08:00
|
|
|
while ((ptr = *pmy_chain) != NULL)
|
2011-05-27 22:00:25 +08:00
|
|
|
{
|
|
|
|
*pmy_chain = ptr->next;
|
|
|
|
if (ptr->free_arg)
|
|
|
|
(*ptr->free_arg) (ptr->arg);
|
|
|
|
xfree (ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-27 22:32:08 +08:00
|
|
|
static void
|
|
|
|
discard_my_continuations (struct continuation **list)
|
2011-05-27 22:00:25 +08:00
|
|
|
{
|
2011-05-27 22:32:08 +08:00
|
|
|
discard_my_continuations_1 (list);
|
|
|
|
*list = NULL;
|
2011-05-27 22:00:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a continuation to the continuation list of INFERIOR. The new
|
|
|
|
continuation will be added at the front. */
|
|
|
|
|
|
|
|
void
|
2011-05-27 22:56:14 +08:00
|
|
|
add_inferior_continuation (continuation_ftype *hook, void *args,
|
|
|
|
continuation_free_arg_ftype *free_arg)
|
2011-05-27 22:00:25 +08:00
|
|
|
{
|
|
|
|
struct inferior *inf = current_inferior ();
|
|
|
|
|
2011-05-27 22:56:14 +08:00
|
|
|
make_continuation (&inf->continuations, hook, args, free_arg);
|
2011-05-27 22:00:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Do all continuations of the current inferior. */
|
|
|
|
|
|
|
|
void
|
2011-05-31 02:04:32 +08:00
|
|
|
do_all_inferior_continuations (int err)
|
2011-05-27 22:00:25 +08:00
|
|
|
{
|
|
|
|
struct inferior *inf = current_inferior ();
|
2011-05-31 02:04:32 +08:00
|
|
|
do_my_continuations (&inf->continuations, err);
|
2011-05-27 22:00:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get rid of all the inferior-wide continuations of INF. */
|
|
|
|
|
|
|
|
void
|
|
|
|
discard_all_inferior_continuations (struct inferior *inf)
|
|
|
|
{
|
2011-05-27 22:32:08 +08:00
|
|
|
discard_my_continuations (&inf->continuations);
|
|
|
|
}
|