Commit | Line | Data |
---|---|---|
104c1213 JM |
1 | #!/bin/sh |
2 | ||
3 | # User Interface Events. | |
9564ee9f | 4 | # Copyright 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. |
104c1213 JM |
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 | |
30867156 MS |
22 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
23 | # USA. | |
104c1213 | 24 | |
104c1213 JM |
25 | IFS=: |
26 | ||
27 | read="class returntype function formal actual attrib" | |
28 | ||
29 | function_list () | |
30 | { | |
31 | # category: | |
32 | # # -> disable | |
33 | # * -> compatibility - pointer variable that is initialized | |
34 | # by set_gdb_events(). | |
35 | # ? -> Predicate and function proper. | |
36 | # f -> always call (must have a void returntype) | |
37 | # return-type | |
38 | # name | |
39 | # formal argument list | |
40 | # actual argument list | |
41 | # attributes | |
42 | # description | |
43 | cat <<EOF | | |
44 | f:void:breakpoint_create:int b:b | |
45 | f:void:breakpoint_delete:int b:b | |
46 | f:void:breakpoint_modify:int b:b | |
ba9fe036 KS |
47 | f:void:tracepoint_create:int number:number |
48 | f:void:tracepoint_delete:int number:number | |
49 | f:void:tracepoint_modify:int number:number | |
67c2c32c | 50 | f:void:architecture_changed:void |
104c1213 JM |
51 | EOF |
52 | grep -v '^#' | |
53 | } | |
54 | ||
55 | copyright () | |
56 | { | |
57 | cat <<EOF | |
58 | /* User Interface Events. | |
349c5d5f | 59 | |
711cc5cd | 60 | Copyright 1999, 2001, 2002, 2004 Free Software Foundation, Inc. |
104c1213 JM |
61 | |
62 | Contributed by Cygnus Solutions. | |
63 | ||
afbfc876 | 64 | This file is part of GDB. |
104c1213 | 65 | |
afbfc876 AC |
66 | This program is free software; you can redistribute it and/or modify |
67 | it under the terms of the GNU General Public License as published by | |
68 | the Free Software Foundation; either version 2 of the License, or | |
69 | (at your option) any later version. | |
104c1213 | 70 | |
afbfc876 AC |
71 | This program is distributed in the hope that it will be useful, |
72 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
73 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
74 | GNU General Public License for more details. | |
104c1213 | 75 | |
afbfc876 AC |
76 | You should have received a copy of the GNU General Public License |
77 | along with this program; if not, write to the Free Software | |
78 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
104c1213 JM |
79 | |
80 | /* Work in progress */ | |
81 | ||
82 | /* This file was created with the aid of \`\`gdb-events.sh''. | |
83 | ||
84 | The bourn shell script \`\`gdb-events.sh'' creates the files | |
85 | \`\`new-gdb-events.c'' and \`\`new-gdb-events.h and then compares | |
86 | them against the existing \`\`gdb-events.[hc]''. Any differences | |
87 | found being reported. | |
88 | ||
89 | If editing this file, please also run gdb-events.sh and merge any | |
90 | changes into that script. Conversely, when making sweeping changes | |
91 | to this file, modifying gdb-events.sh and using its output may | |
30867156 | 92 | prove easier. */ |
104c1213 JM |
93 | |
94 | EOF | |
95 | } | |
96 | ||
97 | # | |
98 | # The .h file | |
99 | # | |
100 | ||
101 | exec > new-gdb-events.h | |
102 | copyright | |
103 | cat <<EOF | |
104 | ||
105 | #ifndef GDB_EVENTS_H | |
106 | #define GDB_EVENTS_H | |
104c1213 JM |
107 | EOF |
108 | ||
109 | # pointer declarations | |
110 | echo "" | |
111 | echo "" | |
112 | cat <<EOF | |
113 | /* COMPAT: pointer variables for old, unconverted events. | |
114 | A call to set_gdb_events() will automatically update these. */ | |
115 | EOF | |
116 | echo "" | |
117 | function_list | while eval read $read | |
118 | do | |
119 | case "${class}" in | |
120 | "*" ) | |
121 | echo "extern ${returntype} (*${function}_event) (${formal})${attrib};" | |
122 | ;; | |
123 | esac | |
124 | done | |
125 | ||
126 | # function typedef's | |
127 | echo "" | |
128 | echo "" | |
129 | cat <<EOF | |
30867156 MS |
130 | /* Type definition of all hook functions. Recommended pratice is to |
131 | first declare each hook function using the below ftype and then | |
132 | define it. */ | |
104c1213 JM |
133 | EOF |
134 | echo "" | |
135 | function_list | while eval read $read | |
136 | do | |
137 | echo "typedef ${returntype} (gdb_events_${function}_ftype) (${formal});" | |
138 | done | |
139 | ||
140 | # gdb_events object | |
141 | echo "" | |
142 | echo "" | |
143 | cat <<EOF | |
144 | /* gdb-events: object. */ | |
145 | EOF | |
146 | echo "" | |
147 | echo "struct gdb_events" | |
148 | echo " {" | |
149 | function_list | while eval read $read | |
150 | do | |
151 | echo " gdb_events_${function}_ftype *${function}${attrib};" | |
152 | done | |
153 | echo " };" | |
154 | ||
155 | # function declarations | |
156 | echo "" | |
157 | echo "" | |
158 | cat <<EOF | |
159 | /* Interface into events functions. | |
c4093a6a | 160 | Where a *_p() predicate is present, it must be called before |
30867156 | 161 | calling the hook proper. */ |
104c1213 JM |
162 | EOF |
163 | function_list | while eval read $read | |
164 | do | |
165 | case "${class}" in | |
166 | "*" ) continue ;; | |
167 | "?" ) | |
168 | echo "extern int ${function}_p (void);" | |
169 | echo "extern ${returntype} ${function}_event (${formal})${attrib};" | |
170 | ;; | |
171 | "f" ) | |
172 | echo "extern ${returntype} ${function}_event (${formal})${attrib};" | |
173 | ;; | |
174 | esac | |
175 | done | |
176 | ||
104c1213 JM |
177 | # our set function |
178 | cat <<EOF | |
179 | ||
30867156 | 180 | /* Install custom gdb-events hooks. */ |
2726dafc | 181 | extern struct gdb_events *deprecated_set_gdb_event_hooks (struct gdb_events *vector); |
104c1213 | 182 | |
30867156 | 183 | /* Deliver any pending events. */ |
104c1213 JM |
184 | extern void gdb_events_deliver (struct gdb_events *vector); |
185 | ||
30867156 | 186 | /* Clear event handlers. */ |
63d022e0 | 187 | extern void clear_gdb_event_hooks (void); |
104c1213 JM |
188 | EOF |
189 | ||
190 | # close it off | |
191 | echo "" | |
192 | echo "#endif" | |
193 | exec 1>&2 | |
194 | #../move-if-change new-gdb-events.h gdb-events.h | |
9e791099 | 195 | if test -r gdb-events.h |
104c1213 | 196 | then |
9e791099 KS |
197 | diff -c gdb-events.h new-gdb-events.h |
198 | if [ $? = 1 ] | |
199 | then | |
200 | echo "gdb-events.h changed? cp new-gdb-events.h gdb-events.h" 1>&2 | |
201 | fi | |
202 | else | |
104c1213 | 203 | echo "File missing? mv new-gdb-events.h gdb-events.h" 1>&2 |
104c1213 JM |
204 | fi |
205 | ||
206 | ||
207 | ||
208 | # | |
209 | # C file | |
210 | # | |
211 | ||
212 | exec > new-gdb-events.c | |
213 | copyright | |
214 | cat <<EOF | |
215 | ||
216 | #include "defs.h" | |
217 | #include "gdb-events.h" | |
218 | #include "gdbcmd.h" | |
219 | ||
104c1213 JM |
220 | static struct gdb_events null_event_hooks; |
221 | static struct gdb_events queue_event_hooks; | |
222 | static struct gdb_events *current_event_hooks = &null_event_hooks; | |
104c1213 JM |
223 | |
224 | int gdb_events_debug; | |
225 | EOF | |
226 | ||
104c1213 | 227 | # function bodies |
104c1213 JM |
228 | function_list | while eval read $read |
229 | do | |
230 | case "${class}" in | |
231 | "*" ) continue ;; | |
232 | "?" ) | |
9e791099 KS |
233 | cat <<EOF |
234 | ||
235 | int | |
236 | ${function}_event_p (${formal}) | |
237 | { | |
238 | return current_event_hooks->${function}; | |
239 | } | |
240 | ||
241 | ${returntype} | |
242 | ${function}_event (${formal}) | |
243 | { | |
244 | return current_events->${function} (${actual}); | |
245 | } | |
246 | EOF | |
104c1213 JM |
247 | ;; |
248 | "f" ) | |
9e791099 KS |
249 | cat <<EOF |
250 | ||
251 | void | |
252 | ${function}_event (${formal}) | |
253 | { | |
254 | if (gdb_events_debug) | |
8c6ee715 | 255 | fprintf_unfiltered (gdb_stdlog, "${function}_event\n"); |
9e791099 KS |
256 | if (!current_event_hooks->${function}) |
257 | return; | |
258 | current_event_hooks->${function} (${actual}); | |
259 | } | |
260 | EOF | |
104c1213 JM |
261 | ;; |
262 | esac | |
263 | done | |
104c1213 JM |
264 | |
265 | # Set hooks function | |
266 | echo "" | |
267 | cat <<EOF | |
ed9a39eb | 268 | struct gdb_events * |
2726dafc | 269 | deprecated_set_gdb_event_hooks (struct gdb_events *vector) |
104c1213 | 270 | { |
ed9a39eb | 271 | struct gdb_events *old_events = current_event_hooks; |
104c1213 JM |
272 | if (vector == NULL) |
273 | current_event_hooks = &queue_event_hooks; | |
274 | else | |
275 | current_event_hooks = vector; | |
ed9a39eb | 276 | return old_events; |
104c1213 JM |
277 | EOF |
278 | function_list | while eval read $read | |
279 | do | |
280 | case "${class}" in | |
281 | "*" ) | |
282 | echo " ${function}_event = hooks->${function};" | |
283 | ;; | |
284 | esac | |
285 | done | |
286 | cat <<EOF | |
287 | } | |
104c1213 JM |
288 | EOF |
289 | ||
63d022e0 KS |
290 | # Clear hooks function |
291 | echo "" | |
292 | cat <<EOF | |
63d022e0 KS |
293 | void |
294 | clear_gdb_event_hooks (void) | |
295 | { | |
2726dafc | 296 | deprecated_set_gdb_event_hooks (&null_event_hooks); |
63d022e0 | 297 | } |
63d022e0 KS |
298 | EOF |
299 | ||
104c1213 JM |
300 | # event type |
301 | echo "" | |
302 | cat <<EOF | |
303 | enum gdb_event | |
afbfc876 | 304 | { |
104c1213 JM |
305 | EOF |
306 | function_list | while eval read $read | |
307 | do | |
308 | case "${class}" in | |
309 | "f" ) | |
afbfc876 | 310 | echo " ${function}," |
104c1213 JM |
311 | ;; |
312 | esac | |
313 | done | |
314 | cat <<EOF | |
afbfc876 AC |
315 | nr_gdb_events |
316 | }; | |
104c1213 JM |
317 | EOF |
318 | ||
319 | # event data | |
320 | echo "" | |
321 | function_list | while eval read $read | |
322 | do | |
323 | case "${class}" in | |
324 | "f" ) | |
fd969be2 KS |
325 | if test ${actual} |
326 | then | |
327 | echo "struct ${function}" | |
328 | echo " {" | |
329 | echo " `echo ${formal} | tr '[,]' '[;]'`;" | |
330 | echo " };" | |
331 | echo "" | |
332 | fi | |
104c1213 JM |
333 | ;; |
334 | esac | |
335 | done | |
336 | ||
337 | # event queue | |
338 | cat <<EOF | |
339 | struct event | |
340 | { | |
341 | enum gdb_event type; | |
342 | struct event *next; | |
343 | union | |
344 | { | |
345 | EOF | |
346 | function_list | while eval read $read | |
347 | do | |
348 | case "${class}" in | |
349 | "f" ) | |
fd969be2 KS |
350 | if test ${actual} |
351 | then | |
352 | echo " struct ${function} ${function};" | |
353 | fi | |
104c1213 JM |
354 | ;; |
355 | esac | |
356 | done | |
357 | cat <<EOF | |
358 | } | |
359 | data; | |
360 | }; | |
361 | struct event *pending_events; | |
362 | struct event *delivering_events; | |
363 | EOF | |
364 | ||
365 | # append | |
366 | echo "" | |
367 | cat <<EOF | |
368 | static void | |
369 | append (struct event *new_event) | |
370 | { | |
371 | struct event **event = &pending_events; | |
372 | while ((*event) != NULL) | |
373 | event = &((*event)->next); | |
374 | (*event) = new_event; | |
375 | (*event)->next = NULL; | |
376 | } | |
377 | EOF | |
378 | ||
379 | # schedule a given event | |
380 | function_list | while eval read $read | |
381 | do | |
382 | case "${class}" in | |
383 | "f" ) | |
384 | echo "" | |
385 | echo "static void" | |
386 | echo "queue_${function} (${formal})" | |
387 | echo "{" | |
388 | echo " struct event *event = XMALLOC (struct event);" | |
389 | echo " event->type = ${function};" | |
9e791099 | 390 | for arg in `echo ${actual} | tr '[,]' '[:]' | tr -d '[ ]'`; do |
104c1213 JM |
391 | echo " event->data.${function}.${arg} = ${arg};" |
392 | done | |
393 | echo " append (event);" | |
394 | echo "}" | |
395 | ;; | |
396 | esac | |
397 | done | |
398 | ||
399 | # deliver | |
400 | echo "" | |
401 | cat <<EOF | |
402 | void | |
403 | gdb_events_deliver (struct gdb_events *vector) | |
404 | { | |
405 | /* Just zap any events left around from last time. */ | |
406 | while (delivering_events != NULL) | |
407 | { | |
408 | struct event *event = delivering_events; | |
409 | delivering_events = event->next; | |
e28f816a | 410 | xfree (event); |
104c1213 JM |
411 | } |
412 | /* Process any pending events. Because one of the deliveries could | |
413 | bail out we move everything off of the pending queue onto an | |
414 | in-progress queue where it can, later, be cleaned up if | |
415 | necessary. */ | |
416 | delivering_events = pending_events; | |
417 | pending_events = NULL; | |
418 | while (delivering_events != NULL) | |
419 | { | |
420 | struct event *event = delivering_events; | |
421 | switch (event->type) | |
422 | { | |
423 | EOF | |
424 | function_list | while eval read $read | |
425 | do | |
426 | case "${class}" in | |
427 | "f" ) | |
428 | echo " case ${function}:" | |
fd969be2 KS |
429 | if test ${actual} |
430 | then | |
431 | echo " vector->${function}" | |
432 | sep=" (" | |
433 | ass="" | |
434 | for arg in `echo ${actual} | tr '[,]' '[:]' | tr -d '[ ]'`; do | |
435 | ass="${ass}${sep}event->data.${function}.${arg}" | |
436 | sep=", | |
437 | " | |
438 | done | |
439 | echo "${ass});" | |
440 | else | |
441 | echo " vector->${function} ();" | |
442 | fi | |
104c1213 JM |
443 | echo " break;" |
444 | ;; | |
445 | esac | |
446 | done | |
447 | cat <<EOF | |
448 | } | |
449 | delivering_events = event->next; | |
e28f816a | 450 | xfree (event); |
104c1213 JM |
451 | } |
452 | } | |
453 | EOF | |
454 | ||
455 | # Finally the initialization | |
456 | echo "" | |
457 | cat <<EOF | |
458 | void _initialize_gdb_events (void); | |
459 | void | |
460 | _initialize_gdb_events (void) | |
461 | { | |
afbfc876 | 462 | struct cmd_list_element *c; |
104c1213 JM |
463 | EOF |
464 | function_list | while eval read $read | |
465 | do | |
466 | case "${class}" in | |
467 | "f" ) | |
468 | echo " queue_event_hooks.${function} = queue_${function};" | |
469 | ;; | |
470 | esac | |
471 | done | |
472 | cat <<EOF | |
afbfc876 AC |
473 | |
474 | c = add_set_cmd ("eventdebug", class_maintenance, var_zinteger, | |
475 | (char *) (&gdb_events_debug), "Set event debugging.\n\\ | |
476 | When non-zero, event/notify debugging is enabled.", &setlist); | |
477 | deprecate_cmd (c, "set debug event"); | |
cb1a6d5f AC |
478 | deprecate_cmd (deprecated_add_show_from_set (c, &showlist), |
479 | "show debug event"); | |
480 | ||
30867156 MS |
481 | deprecated_add_show_from_set (add_set_cmd ("event", |
482 | class_maintenance, | |
483 | var_zinteger, | |
484 | (char *) (&gdb_events_debug), | |
485 | "Set event debugging.\n\\ | |
afbfc876 | 486 | When non-zero, event/notify debugging is enabled.", &setdebuglist), |
30867156 | 487 | &showdebuglist); |
104c1213 JM |
488 | } |
489 | EOF | |
490 | ||
491 | # close things off | |
492 | exec 1>&2 | |
493 | #../move-if-change new-gdb-events.c gdb-events.c | |
afbfc876 AC |
494 | # Replace any leading spaces with tabs |
495 | sed < new-gdb-events.c > tmp-gdb-events.c \ | |
496 | -e 's/\( \)* /\1 /g' | |
497 | mv tmp-gdb-events.c new-gdb-events.c | |
498 | # Move if changed? | |
9e791099 | 499 | if test -r gdb-events.c |
104c1213 | 500 | then |
9e791099 KS |
501 | diff -c gdb-events.c new-gdb-events.c |
502 | if [ $? = 1 ] | |
503 | then | |
504 | echo "gdb-events.c changed? cp new-gdb-events.c gdb-events.c" 1>&2 | |
505 | fi | |
506 | else | |
104c1213 | 507 | echo "File missing? mv new-gdb-events.c gdb-events.c" 1>&2 |
104c1213 | 508 | fi |