2005-04-28 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / gdb-events.c
1 /* User Interface Events.
2
3 Copyright 1999, 2001, 2002, 2004, 2005 Free Software Foundation,
4 Inc.
5
6 Contributed by Cygnus Solutions.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23
24 /* Work in progress */
25
26 /* This file was created with the aid of ``gdb-events.sh''.
27
28 The bourn shell script ``gdb-events.sh'' creates the files
29 ``new-gdb-events.c'' and ``new-gdb-events.h and then compares
30 them against the existing ``gdb-events.[hc]''. Any differences
31 found being reported.
32
33 If editing this file, please also run gdb-events.sh and merge any
34 changes into that script. Conversely, when making sweeping changes
35 to this file, modifying gdb-events.sh and using its output may
36 prove easier. */
37
38
39 #include "defs.h"
40 #include "gdb-events.h"
41 #include "gdbcmd.h"
42
43 static struct gdb_events null_event_hooks;
44 static struct gdb_events queue_event_hooks;
45 static struct gdb_events *current_event_hooks = &null_event_hooks;
46
47 int gdb_events_debug;
48 static void
49 show_gdb_events_debug (struct ui_file *file, int from_tty,
50 struct cmd_list_element *c, const char *value)
51 {
52 fprintf_filtered (file, _("Event debugging is %s.\n"), value);
53 }
54
55
56 void
57 breakpoint_create_event (int b)
58 {
59 if (gdb_events_debug)
60 fprintf_unfiltered (gdb_stdlog, "breakpoint_create_event\n");
61 if (!current_event_hooks->breakpoint_create)
62 return;
63 current_event_hooks->breakpoint_create (b);
64 }
65
66 void
67 breakpoint_delete_event (int b)
68 {
69 if (gdb_events_debug)
70 fprintf_unfiltered (gdb_stdlog, "breakpoint_delete_event\n");
71 if (!current_event_hooks->breakpoint_delete)
72 return;
73 current_event_hooks->breakpoint_delete (b);
74 }
75
76 void
77 breakpoint_modify_event (int b)
78 {
79 if (gdb_events_debug)
80 fprintf_unfiltered (gdb_stdlog, "breakpoint_modify_event\n");
81 if (!current_event_hooks->breakpoint_modify)
82 return;
83 current_event_hooks->breakpoint_modify (b);
84 }
85
86 void
87 tracepoint_create_event (int number)
88 {
89 if (gdb_events_debug)
90 fprintf_unfiltered (gdb_stdlog, "tracepoint_create_event\n");
91 if (!current_event_hooks->tracepoint_create)
92 return;
93 current_event_hooks->tracepoint_create (number);
94 }
95
96 void
97 tracepoint_delete_event (int number)
98 {
99 if (gdb_events_debug)
100 fprintf_unfiltered (gdb_stdlog, "tracepoint_delete_event\n");
101 if (!current_event_hooks->tracepoint_delete)
102 return;
103 current_event_hooks->tracepoint_delete (number);
104 }
105
106 void
107 tracepoint_modify_event (int number)
108 {
109 if (gdb_events_debug)
110 fprintf_unfiltered (gdb_stdlog, "tracepoint_modify_event\n");
111 if (!current_event_hooks->tracepoint_modify)
112 return;
113 current_event_hooks->tracepoint_modify (number);
114 }
115
116 void
117 architecture_changed_event (void)
118 {
119 if (gdb_events_debug)
120 fprintf_unfiltered (gdb_stdlog, "architecture_changed_event\n");
121 if (!current_event_hooks->architecture_changed)
122 return;
123 current_event_hooks->architecture_changed ();
124 }
125
126 struct gdb_events *
127 deprecated_set_gdb_event_hooks (struct gdb_events *vector)
128 {
129 struct gdb_events *old_events = current_event_hooks;
130 if (vector == NULL)
131 current_event_hooks = &queue_event_hooks;
132 else
133 current_event_hooks = vector;
134 return old_events;
135 }
136
137 void
138 clear_gdb_event_hooks (void)
139 {
140 deprecated_set_gdb_event_hooks (&null_event_hooks);
141 }
142
143 enum gdb_event
144 {
145 breakpoint_create,
146 breakpoint_delete,
147 breakpoint_modify,
148 tracepoint_create,
149 tracepoint_delete,
150 tracepoint_modify,
151 architecture_changed,
152 nr_gdb_events
153 };
154
155 struct breakpoint_create
156 {
157 int b;
158 };
159
160 struct breakpoint_delete
161 {
162 int b;
163 };
164
165 struct breakpoint_modify
166 {
167 int b;
168 };
169
170 struct tracepoint_create
171 {
172 int number;
173 };
174
175 struct tracepoint_delete
176 {
177 int number;
178 };
179
180 struct tracepoint_modify
181 {
182 int number;
183 };
184
185 struct event
186 {
187 enum gdb_event type;
188 struct event *next;
189 union
190 {
191 struct breakpoint_create breakpoint_create;
192 struct breakpoint_delete breakpoint_delete;
193 struct breakpoint_modify breakpoint_modify;
194 struct tracepoint_create tracepoint_create;
195 struct tracepoint_delete tracepoint_delete;
196 struct tracepoint_modify tracepoint_modify;
197 }
198 data;
199 };
200 struct event *pending_events;
201 struct event *delivering_events;
202
203 static void
204 append (struct event *new_event)
205 {
206 struct event **event = &pending_events;
207 while ((*event) != NULL)
208 event = &((*event)->next);
209 (*event) = new_event;
210 (*event)->next = NULL;
211 }
212
213 static void
214 queue_breakpoint_create (int b)
215 {
216 struct event *event = XMALLOC (struct event);
217 event->type = breakpoint_create;
218 event->data.breakpoint_create.b = b;
219 append (event);
220 }
221
222 static void
223 queue_breakpoint_delete (int b)
224 {
225 struct event *event = XMALLOC (struct event);
226 event->type = breakpoint_delete;
227 event->data.breakpoint_delete.b = b;
228 append (event);
229 }
230
231 static void
232 queue_breakpoint_modify (int b)
233 {
234 struct event *event = XMALLOC (struct event);
235 event->type = breakpoint_modify;
236 event->data.breakpoint_modify.b = b;
237 append (event);
238 }
239
240 static void
241 queue_tracepoint_create (int number)
242 {
243 struct event *event = XMALLOC (struct event);
244 event->type = tracepoint_create;
245 event->data.tracepoint_create.number = number;
246 append (event);
247 }
248
249 static void
250 queue_tracepoint_delete (int number)
251 {
252 struct event *event = XMALLOC (struct event);
253 event->type = tracepoint_delete;
254 event->data.tracepoint_delete.number = number;
255 append (event);
256 }
257
258 static void
259 queue_tracepoint_modify (int number)
260 {
261 struct event *event = XMALLOC (struct event);
262 event->type = tracepoint_modify;
263 event->data.tracepoint_modify.number = number;
264 append (event);
265 }
266
267 static void
268 queue_architecture_changed (void)
269 {
270 struct event *event = XMALLOC (struct event);
271 event->type = architecture_changed;
272 append (event);
273 }
274
275 void
276 gdb_events_deliver (struct gdb_events *vector)
277 {
278 /* Just zap any events left around from last time. */
279 while (delivering_events != NULL)
280 {
281 struct event *event = delivering_events;
282 delivering_events = event->next;
283 xfree (event);
284 }
285 /* Process any pending events. Because one of the deliveries could
286 bail out we move everything off of the pending queue onto an
287 in-progress queue where it can, later, be cleaned up if
288 necessary. */
289 delivering_events = pending_events;
290 pending_events = NULL;
291 while (delivering_events != NULL)
292 {
293 struct event *event = delivering_events;
294 switch (event->type)
295 {
296 case breakpoint_create:
297 vector->breakpoint_create
298 (event->data.breakpoint_create.b);
299 break;
300 case breakpoint_delete:
301 vector->breakpoint_delete
302 (event->data.breakpoint_delete.b);
303 break;
304 case breakpoint_modify:
305 vector->breakpoint_modify
306 (event->data.breakpoint_modify.b);
307 break;
308 case tracepoint_create:
309 vector->tracepoint_create
310 (event->data.tracepoint_create.number);
311 break;
312 case tracepoint_delete:
313 vector->tracepoint_delete
314 (event->data.tracepoint_delete.number);
315 break;
316 case tracepoint_modify:
317 vector->tracepoint_modify
318 (event->data.tracepoint_modify.number);
319 break;
320 case architecture_changed:
321 vector->architecture_changed ();
322 break;
323 }
324 delivering_events = event->next;
325 xfree (event);
326 }
327 }
328
329 void _initialize_gdb_events (void);
330 void
331 _initialize_gdb_events (void)
332 {
333 struct cmd_list_element *c;
334 queue_event_hooks.breakpoint_create = queue_breakpoint_create;
335 queue_event_hooks.breakpoint_delete = queue_breakpoint_delete;
336 queue_event_hooks.breakpoint_modify = queue_breakpoint_modify;
337 queue_event_hooks.tracepoint_create = queue_tracepoint_create;
338 queue_event_hooks.tracepoint_delete = queue_tracepoint_delete;
339 queue_event_hooks.tracepoint_modify = queue_tracepoint_modify;
340 queue_event_hooks.architecture_changed = queue_architecture_changed;
341
342 add_setshow_zinteger_cmd ("event", class_maintenance,
343 &gdb_events_debug, _("\
344 Set event debugging."), _("\
345 Show event debugging."), _("\
346 When non-zero, event/notify debugging is enabled."),
347 NULL,
348 show_gdb_events_debug,
349 &setdebuglist, &showdebuglist);
350 }
This page took 0.036731 seconds and 4 git commands to generate.