]>
Commit | Line | Data |
---|---|---|
104c1213 JM |
1 | /* User Interface Events. |
2 | Copyright 1999 Free Software Foundation, Inc. | |
3 | ||
4 | Contributed by Cygnus Solutions. | |
5 | ||
afbfc876 | 6 | This file is part of GDB. |
104c1213 | 7 | |
afbfc876 AC |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
104c1213 | 12 | |
afbfc876 AC |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
104c1213 | 17 | |
afbfc876 AC |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
104c1213 JM |
21 | |
22 | /* Work in progress */ | |
23 | ||
24 | /* This file was created with the aid of ``gdb-events.sh''. | |
25 | ||
26 | The bourn shell script ``gdb-events.sh'' creates the files | |
27 | ``new-gdb-events.c'' and ``new-gdb-events.h and then compares | |
28 | them against the existing ``gdb-events.[hc]''. Any differences | |
29 | found being reported. | |
30 | ||
31 | If editing this file, please also run gdb-events.sh and merge any | |
32 | changes into that script. Conversely, when making sweeping changes | |
33 | to this file, modifying gdb-events.sh and using its output may | |
34 | prove easier. */ | |
35 | ||
36 | ||
37 | #include "defs.h" | |
38 | #include "gdb-events.h" | |
39 | #include "gdbcmd.h" | |
40 | ||
41 | #undef XMALLOC | |
42 | #define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE))) | |
43 | ||
44 | #if WITH_GDB_EVENTS | |
45 | static struct gdb_events null_event_hooks; | |
46 | static struct gdb_events queue_event_hooks; | |
47 | static struct gdb_events *current_event_hooks = &null_event_hooks; | |
48 | #endif | |
49 | ||
50 | int gdb_events_debug; | |
51 | ||
52 | #if WITH_GDB_EVENTS | |
53 | ||
54 | void | |
55 | breakpoint_create_event (int b) | |
56 | { | |
57 | if (gdb_events_debug) | |
58 | fprintf_unfiltered (gdb_stdlog, "breakpoint_create_event\n"); | |
59 | if (!current_event_hooks->breakpoint_create) | |
60 | return; | |
61 | current_event_hooks->breakpoint_create (b); | |
62 | } | |
63 | ||
64 | void | |
65 | breakpoint_delete_event (int b) | |
66 | { | |
67 | if (gdb_events_debug) | |
68 | fprintf_unfiltered (gdb_stdlog, "breakpoint_delete_event\n"); | |
69 | if (!current_event_hooks->breakpoint_delete) | |
70 | return; | |
71 | current_event_hooks->breakpoint_delete (b); | |
72 | } | |
73 | ||
74 | void | |
75 | breakpoint_modify_event (int b) | |
76 | { | |
77 | if (gdb_events_debug) | |
78 | fprintf_unfiltered (gdb_stdlog, "breakpoint_modify_event\n"); | |
79 | if (!current_event_hooks->breakpoint_modify) | |
80 | return; | |
81 | current_event_hooks->breakpoint_modify (b); | |
82 | } | |
83 | ||
84 | #endif | |
85 | ||
86 | #if WITH_GDB_EVENTS | |
ed9a39eb | 87 | struct gdb_events * |
104c1213 JM |
88 | set_gdb_event_hooks (struct gdb_events *vector) |
89 | { | |
ed9a39eb | 90 | struct gdb_events *old_events = current_event_hooks; |
104c1213 JM |
91 | if (vector == NULL) |
92 | current_event_hooks = &queue_event_hooks; | |
93 | else | |
94 | current_event_hooks = vector; | |
ed9a39eb | 95 | return old_events; |
104c1213 JM |
96 | } |
97 | #endif | |
98 | ||
99 | enum gdb_event | |
afbfc876 AC |
100 | { |
101 | breakpoint_create, | |
102 | breakpoint_delete, | |
103 | breakpoint_modify, | |
104 | nr_gdb_events | |
105 | }; | |
104c1213 JM |
106 | |
107 | struct breakpoint_create | |
108 | { | |
109 | int b; | |
110 | }; | |
111 | ||
112 | struct breakpoint_delete | |
113 | { | |
114 | int b; | |
115 | }; | |
116 | ||
117 | struct breakpoint_modify | |
118 | { | |
119 | int b; | |
120 | }; | |
121 | ||
122 | struct event | |
123 | { | |
124 | enum gdb_event type; | |
125 | struct event *next; | |
126 | union | |
127 | { | |
afbfc876 AC |
128 | struct breakpoint_create breakpoint_create; |
129 | struct breakpoint_delete breakpoint_delete; | |
130 | struct breakpoint_modify breakpoint_modify; | |
104c1213 JM |
131 | } |
132 | data; | |
133 | }; | |
134 | struct event *pending_events; | |
135 | struct event *delivering_events; | |
136 | ||
137 | static void | |
138 | append (struct event *new_event) | |
139 | { | |
140 | struct event **event = &pending_events; | |
141 | while ((*event) != NULL) | |
142 | event = &((*event)->next); | |
143 | (*event) = new_event; | |
144 | (*event)->next = NULL; | |
145 | } | |
146 | ||
147 | static void | |
148 | queue_breakpoint_create (int b) | |
149 | { | |
150 | struct event *event = XMALLOC (struct event); | |
151 | event->type = breakpoint_create; | |
152 | event->data.breakpoint_create.b = b; | |
153 | append (event); | |
154 | } | |
155 | ||
156 | static void | |
157 | queue_breakpoint_delete (int b) | |
158 | { | |
159 | struct event *event = XMALLOC (struct event); | |
160 | event->type = breakpoint_delete; | |
161 | event->data.breakpoint_delete.b = b; | |
162 | append (event); | |
163 | } | |
164 | ||
165 | static void | |
166 | queue_breakpoint_modify (int b) | |
167 | { | |
168 | struct event *event = XMALLOC (struct event); | |
169 | event->type = breakpoint_modify; | |
170 | event->data.breakpoint_modify.b = b; | |
171 | append (event); | |
172 | } | |
173 | ||
174 | void | |
175 | gdb_events_deliver (struct gdb_events *vector) | |
176 | { | |
177 | /* Just zap any events left around from last time. */ | |
178 | while (delivering_events != NULL) | |
179 | { | |
180 | struct event *event = delivering_events; | |
181 | delivering_events = event->next; | |
182 | free (event); | |
183 | } | |
184 | /* Process any pending events. Because one of the deliveries could | |
185 | bail out we move everything off of the pending queue onto an | |
186 | in-progress queue where it can, later, be cleaned up if | |
187 | necessary. */ | |
188 | delivering_events = pending_events; | |
189 | pending_events = NULL; | |
190 | while (delivering_events != NULL) | |
191 | { | |
192 | struct event *event = delivering_events; | |
193 | switch (event->type) | |
afbfc876 AC |
194 | { |
195 | case breakpoint_create: | |
196 | vector->breakpoint_create | |
197 | (event->data.breakpoint_create.b); | |
198 | break; | |
199 | case breakpoint_delete: | |
200 | vector->breakpoint_delete | |
201 | (event->data.breakpoint_delete.b); | |
202 | break; | |
203 | case breakpoint_modify: | |
204 | vector->breakpoint_modify | |
205 | (event->data.breakpoint_modify.b); | |
206 | break; | |
207 | } | |
104c1213 JM |
208 | delivering_events = event->next; |
209 | free (event); | |
210 | } | |
211 | } | |
212 | ||
213 | void _initialize_gdb_events (void); | |
214 | void | |
215 | _initialize_gdb_events (void) | |
216 | { | |
5d161b24 | 217 | struct cmd_list_element *c; |
104c1213 JM |
218 | #if WITH_GDB_EVENTS |
219 | queue_event_hooks.breakpoint_create = queue_breakpoint_create; | |
220 | queue_event_hooks.breakpoint_delete = queue_breakpoint_delete; | |
221 | queue_event_hooks.breakpoint_modify = queue_breakpoint_modify; | |
afbfc876 | 222 | #endif |
5d161b24 | 223 | |
afbfc876 AC |
224 | c = add_set_cmd ("eventdebug", class_maintenance, var_zinteger, |
225 | (char *) (&gdb_events_debug), "Set event debugging.\n\ | |
5d161b24 | 226 | When non-zero, event/notify debugging is enabled.", &setlist); |
afbfc876 AC |
227 | deprecate_cmd (c, "set debug event"); |
228 | deprecate_cmd (add_show_from_set (c, &showlist), "show debug event"); | |
5d161b24 DB |
229 | |
230 | add_show_from_set (add_set_cmd ("event", | |
afbfc876 AC |
231 | class_maintenance, |
232 | var_zinteger, | |
233 | (char *) (&gdb_events_debug), | |
234 | "Set event debugging.\n\ | |
5d161b24 | 235 | When non-zero, event/notify debugging is enabled.", &setdebuglist), |
afbfc876 | 236 | &showdebuglist); |
104c1213 | 237 | } |