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