1 /* Continuations for GDB, the GNU debugger.
3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* Local non-gdb includes. */
23 #include "continuations.h"
24 #include "gdbthread.h"
29 struct continuation *next;
30 continuation_ftype *function;
31 continuation_free_arg_ftype *free_arg;
35 /* Add a new continuation to the continuation chain. Args are
36 FUNCTION to run the continuation up with, and ARG to pass to
40 make_continuation (struct continuation **pmy_chain,
41 continuation_ftype *function,
42 void *arg, void (*free_arg) (void *))
44 struct continuation *newobj = XNEW (struct continuation);
46 newobj->next = *pmy_chain;
47 newobj->function = function;
48 newobj->free_arg = free_arg;
54 do_my_continuations_1 (struct continuation **pmy_chain, int err)
56 struct continuation *ptr;
58 while ((ptr = *pmy_chain) != NULL)
60 *pmy_chain = ptr->next; /* Do this first in case of recursion. */
61 (*ptr->function) (ptr->arg, err);
63 (*ptr->free_arg) (ptr->arg);
69 do_my_continuations (struct continuation **list, int err)
71 struct continuation *continuations;
76 /* Copy the list header into another pointer, and set the global
77 list header to null, so that the global list can change as a side
78 effect of invoking the continuations and the processing of the
79 preexisting continuations will not be affected. */
81 continuations = *list;
84 /* Work now on the list we have set aside. */
85 do_my_continuations_1 (&continuations, err);
89 discard_my_continuations_1 (struct continuation **pmy_chain)
91 struct continuation *ptr;
93 while ((ptr = *pmy_chain) != NULL)
95 *pmy_chain = ptr->next;
97 (*ptr->free_arg) (ptr->arg);
103 discard_my_continuations (struct continuation **list)
105 discard_my_continuations_1 (list);
109 /* Add a continuation to the continuation list of INFERIOR. The new
110 continuation will be added at the front. */
113 add_inferior_continuation (continuation_ftype *hook, void *args,
114 continuation_free_arg_ftype *free_arg)
116 struct inferior *inf = current_inferior ();
118 make_continuation (&inf->continuations, hook, args, free_arg);
121 /* Do all continuations of the current inferior. */
124 do_all_inferior_continuations (int err)
126 struct inferior *inf = current_inferior ();
127 do_my_continuations (&inf->continuations, err);
130 /* Get rid of all the inferior-wide continuations of INF. */
133 discard_all_inferior_continuations (struct inferior *inf)
135 discard_my_continuations (&inf->continuations);