GDB (xrefs)
/tmp/gdb-7.10/gdb/continuations.c
Go to the documentation of this file.
1 /* Continuations for GDB, the GNU debugger.
2 
3  Copyright (C) 1986-2015 Free Software Foundation, Inc.
4 
5  This file is part of GDB.
6 
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.
11 
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.
16 
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/>. */
19 
20 #include "defs.h"
21 #include "gdbthread.h"
22 #include "inferior.h"
23 #include "continuations.h"
24 
26 {
27  struct continuation *next;
28  continuation_ftype *function;
30  void *arg;
31 };
32 
33 /* Add a new continuation to the continuation chain. Args are
34  FUNCTION to run the continuation up with, and ARG to pass to
35  it. */
36 
37 static void
38 make_continuation (struct continuation **pmy_chain,
39  continuation_ftype *function,
40  void *arg, void (*free_arg) (void *))
41 {
42  struct continuation *newobj = XNEW (struct continuation);
43 
44  newobj->next = *pmy_chain;
45  newobj->function = function;
46  newobj->free_arg = free_arg;
47  newobj->arg = arg;
48  *pmy_chain = newobj;
49 }
50 
51 static void
52 do_my_continuations_1 (struct continuation **pmy_chain, int err)
53 {
54  struct continuation *ptr;
55 
56  while ((ptr = *pmy_chain) != NULL)
57  {
58  *pmy_chain = ptr->next; /* Do this first in case of recursion. */
59  (*ptr->function) (ptr->arg, err);
60  if (ptr->free_arg)
61  (*ptr->free_arg) (ptr->arg);
62  xfree (ptr);
63  }
64 }
65 
66 static void
67 do_my_continuations (struct continuation **list, int err)
68 {
69  struct continuation *continuations;
70 
71  if (*list == NULL)
72  return;
73 
74  /* Copy the list header into another pointer, and set the global
75  list header to null, so that the global list can change as a side
76  effect of invoking the continuations and the processing of the
77  preexisting continuations will not be affected. */
78 
79  continuations = *list;
80  *list = NULL;
81 
82  /* Work now on the list we have set aside. */
83  do_my_continuations_1 (&continuations, err);
84 }
85 
86 static void
88 {
89  struct continuation *ptr;
90 
91  while ((ptr = *pmy_chain) != NULL)
92  {
93  *pmy_chain = ptr->next;
94  if (ptr->free_arg)
95  (*ptr->free_arg) (ptr->arg);
96  xfree (ptr);
97  }
98 }
99 
100 static void
102 {
104  *list = NULL;
105 }
106 
107 /* Add a continuation to the continuation list of INFERIOR. The new
108  continuation will be added at the front. */
109 
110 void
113 {
114  struct inferior *inf = current_inferior ();
115 
116  make_continuation (&inf->continuations, hook, args, free_arg);
117 }
118 
119 /* Do all continuations of the current inferior. */
120 
121 void
123 {
124  struct inferior *inf = current_inferior ();
125  do_my_continuations (&inf->continuations, err);
126 }
127 
128 /* Get rid of all the inferior-wide continuations of INF. */
129 
130 void
132 {
134 }
135 
136 /* Add a continuation to the continuation list of THREAD. The new
137  continuation will be added at the front. */
138 
139 void
141  continuation_ftype *hook, void *args,
142  continuation_free_arg_ftype *free_arg)
143 {
144  make_continuation (&thread->continuations, hook, args, free_arg);
145 }
146 
147 static void
149 {
150  ptid_t *ptid_p = arg;
151 
152  switch_to_thread (*ptid_p);
153 }
154 
155 /* Walk down the continuation list of PTID, and execute all the
156  continuations. There is a problem though. In some cases new
157  continuations may be added while we are in the middle of this loop.
158  If this happens they will be added in the front, and done before we
159  have a chance of exhausting those that were already there. We need
160  to then save the beginning of the list in a pointer and do the
161  continuations from there on, instead of using the global beginning
162  of list as our iteration pointer. */
163 
164 static void
166  struct continuation **continuations_p,
167  int err)
168 {
169  struct cleanup *old_chain;
171 
172  if (*continuations_p == NULL)
173  return;
174 
175  current_thread = inferior_ptid;
176 
177  /* Restore selected thread on exit. Don't try to restore the frame
178  as well, because:
179 
180  - When running continuations, the selected frame is always #0.
181 
182  - The continuations may trigger symbol file loads, which may
183  change the frame layout (frame ids change), which would trigger
184  a warning if we used make_cleanup_restore_current_thread. */
185 
186  old_chain = make_cleanup (restore_thread_cleanup, &current_thread);
187 
188  /* Let the continuation see this thread as selected. */
189  switch_to_thread (ptid);
190 
191  do_my_continuations (continuations_p, err);
192 
193  do_cleanups (old_chain);
194 }
195 
196 /* Callback for iterate over threads. */
197 
198 static int
200 {
201  int err = * (int *) data;
202  do_all_continuations_ptid (thread->ptid, &thread->continuations, err);
203  return 0;
204 }
205 
206 /* Do all continuations of thread THREAD. */
207 
208 void
210 {
212 }
213 
214 /* Do all continuations of all threads. */
215 
216 void
218 {
220 }
221 
222 /* Callback for iterate over threads. */
223 
224 static int
226  void *data)
227 {
229  return 0;
230 }
231 
232 /* Get rid of all the continuations of THREAD. */
233 
234 void
236 {
238 }
239 
240 /* Get rid of all the continuations of all threads. */
241 
242 void
244 {
246 }
247 
248 
249 /* Add a continuation to the intermediate continuation list of THREAD.
250  The new continuation will be added at the front. */
251 
252 void
254  continuation_ftype *hook,
255  void *args,
257 {
259  args, free_arg);
260 }
261 
262 /* Walk down the cmd_continuation list, and execute all the
263  continuations. There is a problem though. In some cases new
264  continuations may be added while we are in the middle of this
265  loop. If this happens they will be added in the front, and done
266  before we have a chance of exhausting those that were already
267  there. We need to then save the beginning of the list in a pointer
268  and do the continuations from there on, instead of using the
269  global beginning of list as our iteration pointer. */
270 
271 static int
273  void *data)
274 {
275  int err = * (int *) data;
276 
278  &thread->intermediate_continuations, err);
279  return 0;
280 }
281 
282 /* Do all intermediate continuations of thread THREAD. */
283 
284 void
286 {
288 }
289 
290 /* Do all intermediate continuations of all threads. */
291 
292 void
294 {
296  &err);
297 }
298 
299 /* Callback for iterate over threads. */
300 
301 static int
303  void *data)
304 {
306  return 0;
307 }
308 
309 /* Get rid of all the intermediate continuations of THREAD. */
310 
311 void
313 {
315 }
316 
317 /* Get rid of all the intermediate continuations of all threads. */
318 
319 void
321 {
323  NULL);
324 }
struct continuation * continuations
Definition: inferior.h:367
void do_all_intermediate_continuations_thread(struct thread_info *thread, int err)
void discard_all_intermediate_continuations(void)
void do_all_intermediate_continuations(int err)
static void discard_my_continuations_1(struct continuation **pmy_chain)
Definition: continuations.c:87
struct continuation * next
Definition: continuations.c:27
static void do_my_continuations(struct continuation **list, int err)
Definition: continuations.c:67
void xfree(void *)
Definition: common-utils.c:97
void(* free_arg)(void *)
Definition: cleanups.c:42
void( continuation_ftype)(void *arg, int err)
Definition: continuations.h:41
char * args
Definition: inferior.h:320
void switch_to_thread(ptid_t ptid)
Definition: thread.c:1185
void( continuation_free_arg_ftype)(void *)
Definition: continuations.h:46
Definition: ptid.h:35
struct thread_info * iterate_over_threads(thread_callback_func, void *)
Definition: thread.c:419
static int discard_all_intermediate_continuations_thread_callback(struct thread_info *thread, void *data)
continuation_free_arg_ftype * free_arg
Definition: continuations.c:29
void discard_all_inferior_continuations(struct inferior *inf)
void discard_all_intermediate_continuations_thread(struct thread_info *thread)
void do_all_continuations_thread(struct thread_info *thread, int err)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t err
Definition: gnu-nat.c:1816
static void restore_thread_cleanup(void *arg)
static int discard_all_continuations_thread_callback(struct thread_info *thread, void *data)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
Definition: cleanups.c:117
Definition: gnu-nat.c:163
static int do_all_continuations_thread_callback(struct thread_info *thread, void *data)
static int do_all_intermediate_continuations_thread_callback(struct thread_info *thread, void *data)
struct continuation * continuations
Definition: gdbthread.h:244
static void make_continuation(struct continuation **pmy_chain, continuation_ftype *function, void *arg, void(*free_arg)(void *))
Definition: continuations.c:38
ptid_t ptid
Definition: gdbthread.h:169
ptid_t inferior_ptid
Definition: infcmd.c:124
struct continuation * intermediate_continuations
Definition: gdbthread.h:249
void do_all_inferior_continuations(int err)
static void do_my_continuations_1(struct continuation **pmy_chain, int err)
Definition: continuations.c:52
void add_intermediate_continuation(struct thread_info *thread, continuation_ftype *hook, void *args, continuation_free_arg_ftype *free_arg)
struct inferior * current_inferior(void)
Definition: inferior.c:57
static void discard_my_continuations(struct continuation **list)
void discard_all_continuations_thread(struct thread_info *thread)
continuation_ftype * function
Definition: continuations.c:28
void discard_all_continuations(void)
static windows_thread_info * current_thread
Definition: windows-nat.c:201
static void do_all_continuations_ptid(ptid_t ptid, struct continuation **continuations_p, int err)
void add_inferior_continuation(continuation_ftype *hook, void *args, continuation_free_arg_ftype *free_arg)
void do_all_continuations(int err)
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:175
void add_continuation(struct thread_info *thread, continuation_ftype *hook, void *args, continuation_free_arg_ftype *free_arg)