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