Commit | Line | Data |
---|---|---|
104c1213 JM |
1 | #!/bin/sh |
2 | ||
3 | # User Interface Events. | |
e28f816a | 4 | # Copyright 1999, 2000, 2001 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 | |
22 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
23 | ||
24 | # | |
25 | # What happens next: | |
26 | # | |
27 | ||
28 | # The gdb-events.h/gdb-events.c files this script generates are commited | |
29 | # and published. | |
30 | ||
31 | # Any UI module that is installing events is changed so that the | |
32 | # events are installed using the ``set_gdb_events()'' and | |
33 | # ``gdb_event_hooks()'' interfaces. There could prove to be an issue | |
34 | # here with respect to annotate. We might need to accomodate a hook | |
35 | # stack that allows several ui blocks to install their own events. | |
36 | ||
4b3cb714 | 37 | # Each of the variable events (as currently generated) is converted |
104c1213 JM |
38 | # to either a straight function call or a function call with a |
39 | # predicate. | |
40 | ||
41 | ||
42 | IFS=: | |
43 | ||
44 | read="class returntype function formal actual attrib" | |
45 | ||
46 | function_list () | |
47 | { | |
48 | # category: | |
49 | # # -> disable | |
50 | # * -> compatibility - pointer variable that is initialized | |
51 | # by set_gdb_events(). | |
52 | # ? -> Predicate and function proper. | |
53 | # f -> always call (must have a void returntype) | |
54 | # return-type | |
55 | # name | |
56 | # formal argument list | |
57 | # actual argument list | |
58 | # attributes | |
59 | # description | |
60 | cat <<EOF | | |
61 | f:void:breakpoint_create:int b:b | |
62 | f:void:breakpoint_delete:int b:b | |
63 | f:void:breakpoint_modify:int b:b | |
ba9fe036 KS |
64 | f:void:tracepoint_create:int number:number |
65 | f:void:tracepoint_delete:int number:number | |
66 | f:void:tracepoint_modify:int number:number | |
104c1213 JM |
67 | #*:void:annotate_starting_hook:void |
68 | #*:void:annotate_stopped_hook:void | |
69 | #*:void:annotate_signalled_hook:void | |
70 | #*:void:annotate_signal_hook:void | |
71 | #*:void:annotate_exited_hook:void | |
72 | ##*:void:print_register_hook:int | |
73 | ##*:CORE_ADDR:find_toc_address_hook:CORE_ADDR | |
74 | ##*:void:sparc_print_register_hook:int regno:regno | |
75 | #*:void:target_resume_hook:void | |
76 | #*:void:target_wait_loop_hook:void | |
77 | #*:void:init_gdb_hook:char *argv0:argv0 | |
78 | #*:void:command_loop_hook:void | |
d9fcf2fb | 79 | #*:void:fputs_unfiltered_hook:const char *linebuff,struct ui_file *stream:linebuff, stream |
104c1213 JM |
80 | #*:void:print_frame_info_listing_hook:struct symtab *s, int line, int stopline, int noerror:s, line, stopline, noerror |
81 | #*:int:query_hook:const char *query, va_list args:query, args | |
82 | #*:void:warning_hook:const char *string, va_list args:string, args | |
104c1213 JM |
83 | #*:void:target_output_hook:char *b:b |
84 | #*:void:interactive_hook:void | |
85 | #*:void:registers_changed_hook:void | |
86 | #*:void:readline_begin_hook:char *format, ...:format | |
87 | #*:char *:readline_hook:char *prompt:prompt | |
88 | #*:void:readline_end_hook:void | |
89 | #*:void:register_changed_hook:int regno:regno | |
90 | #*:void:memory_changed_hook:CORE_ADDR addr, int len:addr, len | |
91 | #*:void:context_hook:int num:num | |
92 | #*:int:target_wait_hook:int pid, struct target_waitstatus *status:pid, status | |
93 | #*:void:call_command_hook:struct cmd_list_element *c, char *cmd, int from_tty:c, cmd, from_tty | |
94 | #*:NORETURN void:error_hook:void:: ATTR_NORETURN | |
95 | #*:void:error_begin_hook:void | |
96 | ##*:int:target_architecture_hook:const struct bfd_arch_info * | |
97 | #*:void:exec_file_display_hook:char *filename:filename | |
98 | #*:void:file_changed_hook:char *filename:filename | |
99 | ##*:void:specify_exec_file_hook: | |
100 | #*:int:gdb_load_progress_hook:char *section, unsigned long num:section, num | |
101 | #*:void:pre_add_symbol_hook:char *name:name | |
102 | #*:void:post_add_symbol_hook:void | |
103 | #*:void:selected_frame_level_changed_hook:int level:level | |
104 | #*:int:gdb_loop_hook:int signo:signo | |
105 | ##*:void:solib_create_inferior_hook:void | |
106 | ##*:void:xcoff_relocate_symtab_hook:unsigned int | |
107 | EOF | |
108 | grep -v '^#' | |
109 | } | |
110 | ||
111 | copyright () | |
112 | { | |
113 | cat <<EOF | |
114 | /* User Interface Events. | |
e28f816a | 115 | Copyright 1999, 2001 Free Software Foundation, Inc. |
104c1213 JM |
116 | |
117 | Contributed by Cygnus Solutions. | |
118 | ||
afbfc876 | 119 | This file is part of GDB. |
104c1213 | 120 | |
afbfc876 AC |
121 | This program is free software; you can redistribute it and/or modify |
122 | it under the terms of the GNU General Public License as published by | |
123 | the Free Software Foundation; either version 2 of the License, or | |
124 | (at your option) any later version. | |
104c1213 | 125 | |
afbfc876 AC |
126 | This program is distributed in the hope that it will be useful, |
127 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
128 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
129 | GNU General Public License for more details. | |
104c1213 | 130 | |
afbfc876 AC |
131 | You should have received a copy of the GNU General Public License |
132 | along with this program; if not, write to the Free Software | |
133 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
104c1213 JM |
134 | |
135 | /* Work in progress */ | |
136 | ||
137 | /* This file was created with the aid of \`\`gdb-events.sh''. | |
138 | ||
139 | The bourn shell script \`\`gdb-events.sh'' creates the files | |
140 | \`\`new-gdb-events.c'' and \`\`new-gdb-events.h and then compares | |
141 | them against the existing \`\`gdb-events.[hc]''. Any differences | |
142 | found being reported. | |
143 | ||
144 | If editing this file, please also run gdb-events.sh and merge any | |
145 | changes into that script. Conversely, when making sweeping changes | |
146 | to this file, modifying gdb-events.sh and using its output may | |
147 | prove easier. */ | |
148 | ||
149 | EOF | |
150 | } | |
151 | ||
152 | # | |
153 | # The .h file | |
154 | # | |
155 | ||
156 | exec > new-gdb-events.h | |
157 | copyright | |
158 | cat <<EOF | |
159 | ||
160 | #ifndef GDB_EVENTS_H | |
161 | #define GDB_EVENTS_H | |
162 | ||
163 | #ifndef WITH_GDB_EVENTS | |
164 | #define WITH_GDB_EVENTS 1 | |
165 | #endif | |
166 | EOF | |
167 | ||
168 | # pointer declarations | |
169 | echo "" | |
170 | echo "" | |
171 | cat <<EOF | |
172 | /* COMPAT: pointer variables for old, unconverted events. | |
173 | A call to set_gdb_events() will automatically update these. */ | |
174 | EOF | |
175 | echo "" | |
176 | function_list | while eval read $read | |
177 | do | |
178 | case "${class}" in | |
179 | "*" ) | |
180 | echo "extern ${returntype} (*${function}_event) (${formal})${attrib};" | |
181 | ;; | |
182 | esac | |
183 | done | |
184 | ||
185 | # function typedef's | |
186 | echo "" | |
187 | echo "" | |
188 | cat <<EOF | |
189 | /* Type definition of all hook functions. | |
190 | Recommended pratice is to first declare each hook function using | |
191 | the below ftype and then define it. */ | |
192 | EOF | |
193 | echo "" | |
194 | function_list | while eval read $read | |
195 | do | |
196 | echo "typedef ${returntype} (gdb_events_${function}_ftype) (${formal});" | |
197 | done | |
198 | ||
199 | # gdb_events object | |
200 | echo "" | |
201 | echo "" | |
202 | cat <<EOF | |
203 | /* gdb-events: object. */ | |
204 | EOF | |
205 | echo "" | |
206 | echo "struct gdb_events" | |
207 | echo " {" | |
208 | function_list | while eval read $read | |
209 | do | |
210 | echo " gdb_events_${function}_ftype *${function}${attrib};" | |
211 | done | |
212 | echo " };" | |
213 | ||
214 | # function declarations | |
215 | echo "" | |
216 | echo "" | |
217 | cat <<EOF | |
218 | /* Interface into events functions. | |
c4093a6a JM |
219 | Where a *_p() predicate is present, it must be called before |
220 | calling the hook proper. */ | |
104c1213 JM |
221 | EOF |
222 | function_list | while eval read $read | |
223 | do | |
224 | case "${class}" in | |
225 | "*" ) continue ;; | |
226 | "?" ) | |
227 | echo "extern int ${function}_p (void);" | |
228 | echo "extern ${returntype} ${function}_event (${formal})${attrib};" | |
229 | ;; | |
230 | "f" ) | |
231 | echo "extern ${returntype} ${function}_event (${formal})${attrib};" | |
232 | ;; | |
233 | esac | |
234 | done | |
235 | ||
236 | # function macros | |
237 | echo "" | |
238 | echo "" | |
239 | cat <<EOF | |
240 | /* When GDB_EVENTS are not being used, completly disable them. */ | |
241 | EOF | |
242 | echo "" | |
243 | echo "#if !WITH_GDB_EVENTS" | |
244 | function_list | while eval read $read | |
245 | do | |
246 | case "${class}" in | |
247 | "*" ) continue ;; | |
248 | "?" ) | |
249 | echo "#define ${function}_event_p() 0" | |
250 | echo "#define ${function}_event(${actual}) 0" | |
251 | ;; | |
252 | "f" ) | |
253 | echo "#define ${function}_event(${actual}) 0" | |
254 | ;; | |
255 | esac | |
256 | done | |
257 | echo "#endif" | |
258 | ||
259 | # our set function | |
260 | cat <<EOF | |
261 | ||
262 | /* Install custom gdb-events hooks. */ | |
ed9a39eb | 263 | extern struct gdb_events *set_gdb_event_hooks (struct gdb_events *vector); |
104c1213 JM |
264 | |
265 | /* Deliver any pending events. */ | |
266 | extern void gdb_events_deliver (struct gdb_events *vector); | |
267 | ||
268 | #if !WITH_GDB_EVENTS | |
269 | #define set_gdb_events(x) 0 | |
270 | #define set_gdb_event_hooks(x) 0 | |
271 | #define gdb_events_deliver(x) 0 | |
272 | #endif | |
273 | EOF | |
274 | ||
275 | # close it off | |
276 | echo "" | |
277 | echo "#endif" | |
278 | exec 1>&2 | |
279 | #../move-if-change new-gdb-events.h gdb-events.h | |
9e791099 | 280 | if test -r gdb-events.h |
104c1213 | 281 | then |
9e791099 KS |
282 | diff -c gdb-events.h new-gdb-events.h |
283 | if [ $? = 1 ] | |
284 | then | |
285 | echo "gdb-events.h changed? cp new-gdb-events.h gdb-events.h" 1>&2 | |
286 | fi | |
287 | else | |
104c1213 | 288 | echo "File missing? mv new-gdb-events.h gdb-events.h" 1>&2 |
104c1213 JM |
289 | fi |
290 | ||
291 | ||
292 | ||
293 | # | |
294 | # C file | |
295 | # | |
296 | ||
297 | exec > new-gdb-events.c | |
298 | copyright | |
299 | cat <<EOF | |
300 | ||
301 | #include "defs.h" | |
302 | #include "gdb-events.h" | |
303 | #include "gdbcmd.h" | |
304 | ||
305 | #undef XMALLOC | |
306 | #define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE))) | |
307 | ||
308 | #if WITH_GDB_EVENTS | |
309 | static struct gdb_events null_event_hooks; | |
310 | static struct gdb_events queue_event_hooks; | |
311 | static struct gdb_events *current_event_hooks = &null_event_hooks; | |
312 | #endif | |
313 | ||
314 | int gdb_events_debug; | |
315 | EOF | |
316 | ||
317 | # global pointer variables - always have this | |
318 | #echo "" | |
319 | #function_list | while eval read $read | |
320 | #do | |
321 | # case "${class}" in | |
322 | # "*" ) | |
323 | # echo "${returntype} (*${function}_event) (${formal})${attrib} = 0;" | |
324 | # ;; | |
325 | # esac | |
326 | #done | |
327 | ||
328 | # function bodies | |
329 | echo "" | |
330 | echo "#if WITH_GDB_EVENTS" | |
331 | function_list | while eval read $read | |
332 | do | |
333 | case "${class}" in | |
334 | "*" ) continue ;; | |
335 | "?" ) | |
9e791099 KS |
336 | cat <<EOF |
337 | ||
338 | int | |
339 | ${function}_event_p (${formal}) | |
340 | { | |
341 | return current_event_hooks->${function}; | |
342 | } | |
343 | ||
344 | ${returntype} | |
345 | ${function}_event (${formal}) | |
346 | { | |
347 | return current_events->${function} (${actual}); | |
348 | } | |
349 | EOF | |
104c1213 JM |
350 | ;; |
351 | "f" ) | |
9e791099 KS |
352 | cat <<EOF |
353 | ||
354 | void | |
355 | ${function}_event (${formal}) | |
356 | { | |
357 | if (gdb_events_debug) | |
8c6ee715 | 358 | fprintf_unfiltered (gdb_stdlog, "${function}_event\n"); |
9e791099 KS |
359 | if (!current_event_hooks->${function}) |
360 | return; | |
361 | current_event_hooks->${function} (${actual}); | |
362 | } | |
363 | EOF | |
104c1213 JM |
364 | ;; |
365 | esac | |
366 | done | |
367 | echo "" | |
368 | echo "#endif" | |
369 | ||
370 | # Set hooks function | |
371 | echo "" | |
372 | cat <<EOF | |
373 | #if WITH_GDB_EVENTS | |
ed9a39eb | 374 | struct gdb_events * |
104c1213 JM |
375 | set_gdb_event_hooks (struct gdb_events *vector) |
376 | { | |
ed9a39eb | 377 | struct gdb_events *old_events = current_event_hooks; |
104c1213 JM |
378 | if (vector == NULL) |
379 | current_event_hooks = &queue_event_hooks; | |
380 | else | |
381 | current_event_hooks = vector; | |
ed9a39eb | 382 | return old_events; |
104c1213 JM |
383 | EOF |
384 | function_list | while eval read $read | |
385 | do | |
386 | case "${class}" in | |
387 | "*" ) | |
388 | echo " ${function}_event = hooks->${function};" | |
389 | ;; | |
390 | esac | |
391 | done | |
392 | cat <<EOF | |
393 | } | |
394 | #endif | |
395 | EOF | |
396 | ||
397 | # event type | |
398 | echo "" | |
399 | cat <<EOF | |
400 | enum gdb_event | |
afbfc876 | 401 | { |
104c1213 JM |
402 | EOF |
403 | function_list | while eval read $read | |
404 | do | |
405 | case "${class}" in | |
406 | "f" ) | |
afbfc876 | 407 | echo " ${function}," |
104c1213 JM |
408 | ;; |
409 | esac | |
410 | done | |
411 | cat <<EOF | |
afbfc876 AC |
412 | nr_gdb_events |
413 | }; | |
104c1213 JM |
414 | EOF |
415 | ||
416 | # event data | |
417 | echo "" | |
418 | function_list | while eval read $read | |
419 | do | |
420 | case "${class}" in | |
421 | "f" ) | |
422 | echo "struct ${function}" | |
423 | echo " {" | |
424 | echo " `echo ${formal} | tr '[,]' '[;]'`;" | |
425 | echo " };" | |
426 | echo "" | |
427 | ;; | |
428 | esac | |
429 | done | |
430 | ||
431 | # event queue | |
432 | cat <<EOF | |
433 | struct event | |
434 | { | |
435 | enum gdb_event type; | |
436 | struct event *next; | |
437 | union | |
438 | { | |
439 | EOF | |
440 | function_list | while eval read $read | |
441 | do | |
442 | case "${class}" in | |
443 | "f" ) | |
444 | echo " struct ${function} ${function};" | |
445 | ;; | |
446 | esac | |
447 | done | |
448 | cat <<EOF | |
449 | } | |
450 | data; | |
451 | }; | |
452 | struct event *pending_events; | |
453 | struct event *delivering_events; | |
454 | EOF | |
455 | ||
456 | # append | |
457 | echo "" | |
458 | cat <<EOF | |
459 | static void | |
460 | append (struct event *new_event) | |
461 | { | |
462 | struct event **event = &pending_events; | |
463 | while ((*event) != NULL) | |
464 | event = &((*event)->next); | |
465 | (*event) = new_event; | |
466 | (*event)->next = NULL; | |
467 | } | |
468 | EOF | |
469 | ||
470 | # schedule a given event | |
471 | function_list | while eval read $read | |
472 | do | |
473 | case "${class}" in | |
474 | "f" ) | |
475 | echo "" | |
476 | echo "static void" | |
477 | echo "queue_${function} (${formal})" | |
478 | echo "{" | |
479 | echo " struct event *event = XMALLOC (struct event);" | |
480 | echo " event->type = ${function};" | |
9e791099 | 481 | for arg in `echo ${actual} | tr '[,]' '[:]' | tr -d '[ ]'`; do |
104c1213 JM |
482 | echo " event->data.${function}.${arg} = ${arg};" |
483 | done | |
484 | echo " append (event);" | |
485 | echo "}" | |
486 | ;; | |
487 | esac | |
488 | done | |
489 | ||
490 | # deliver | |
491 | echo "" | |
492 | cat <<EOF | |
493 | void | |
494 | gdb_events_deliver (struct gdb_events *vector) | |
495 | { | |
496 | /* Just zap any events left around from last time. */ | |
497 | while (delivering_events != NULL) | |
498 | { | |
499 | struct event *event = delivering_events; | |
500 | delivering_events = event->next; | |
e28f816a | 501 | xfree (event); |
104c1213 JM |
502 | } |
503 | /* Process any pending events. Because one of the deliveries could | |
504 | bail out we move everything off of the pending queue onto an | |
505 | in-progress queue where it can, later, be cleaned up if | |
506 | necessary. */ | |
507 | delivering_events = pending_events; | |
508 | pending_events = NULL; | |
509 | while (delivering_events != NULL) | |
510 | { | |
511 | struct event *event = delivering_events; | |
512 | switch (event->type) | |
513 | { | |
514 | EOF | |
515 | function_list | while eval read $read | |
516 | do | |
517 | case "${class}" in | |
518 | "f" ) | |
519 | echo " case ${function}:" | |
520 | echo " vector->${function}" | |
521 | sep=" (" | |
522 | ass="" | |
9e791099 | 523 | for arg in `echo ${actual} | tr '[,]' '[:]' | tr -d '[ ]'`; do |
104c1213 JM |
524 | ass="${ass}${sep}event->data.${function}.${arg}" |
525 | sep=", | |
526 | " | |
527 | done | |
528 | echo "${ass});" | |
529 | echo " break;" | |
530 | ;; | |
531 | esac | |
532 | done | |
533 | cat <<EOF | |
534 | } | |
535 | delivering_events = event->next; | |
e28f816a | 536 | xfree (event); |
104c1213 JM |
537 | } |
538 | } | |
539 | EOF | |
540 | ||
541 | # Finally the initialization | |
542 | echo "" | |
543 | cat <<EOF | |
544 | void _initialize_gdb_events (void); | |
545 | void | |
546 | _initialize_gdb_events (void) | |
547 | { | |
afbfc876 | 548 | struct cmd_list_element *c; |
104c1213 JM |
549 | #if WITH_GDB_EVENTS |
550 | EOF | |
551 | function_list | while eval read $read | |
552 | do | |
553 | case "${class}" in | |
554 | "f" ) | |
555 | echo " queue_event_hooks.${function} = queue_${function};" | |
556 | ;; | |
557 | esac | |
558 | done | |
559 | cat <<EOF | |
560 | #endif | |
afbfc876 AC |
561 | |
562 | c = add_set_cmd ("eventdebug", class_maintenance, var_zinteger, | |
563 | (char *) (&gdb_events_debug), "Set event debugging.\n\\ | |
564 | When non-zero, event/notify debugging is enabled.", &setlist); | |
565 | deprecate_cmd (c, "set debug event"); | |
566 | deprecate_cmd (add_show_from_set (c, &showlist), "show debug event"); | |
567 | ||
568 | add_show_from_set (add_set_cmd ("event", | |
104c1213 JM |
569 | class_maintenance, |
570 | var_zinteger, | |
afbfc876 | 571 | (char *) (&gdb_events_debug), |
104c1213 | 572 | "Set event debugging.\n\\ |
afbfc876 AC |
573 | When non-zero, event/notify debugging is enabled.", &setdebuglist), |
574 | &showdebuglist); | |
104c1213 JM |
575 | } |
576 | EOF | |
577 | ||
578 | # close things off | |
579 | exec 1>&2 | |
580 | #../move-if-change new-gdb-events.c gdb-events.c | |
afbfc876 AC |
581 | # Replace any leading spaces with tabs |
582 | sed < new-gdb-events.c > tmp-gdb-events.c \ | |
583 | -e 's/\( \)* /\1 /g' | |
584 | mv tmp-gdb-events.c new-gdb-events.c | |
585 | # Move if changed? | |
9e791099 | 586 | if test -r gdb-events.c |
104c1213 | 587 | then |
9e791099 KS |
588 | diff -c gdb-events.c new-gdb-events.c |
589 | if [ $? = 1 ] | |
590 | then | |
591 | echo "gdb-events.c changed? cp new-gdb-events.c gdb-events.c" 1>&2 | |
592 | fi | |
593 | else | |
104c1213 | 594 | echo "File missing? mv new-gdb-events.c gdb-events.c" 1>&2 |
104c1213 | 595 | fi |