* gdb-events.sh (function_list): Add tracepoint_create,
[binutils-gdb.git] / gdb / gdb-events.sh
1 #!/bin/sh
2
3 # User Interface Events.
4 # Copyright 1999, 2000, 2001 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 converted
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 f:void:tracepoint_create:int number:number
65 f:void:tracepoint_delete:int number:number
66 f:void:tracepoint_modify:int number:number
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
79 #*:void:fputs_unfiltered_hook:const char *linebuff,struct ui_file *stream:linebuff, stream
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
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.
115 Copyright 1999, 2001 Free Software Foundation, Inc.
116
117 Contributed by Cygnus Solutions.
118
119 This file is part of GDB.
120
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.
125
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.
130
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. */
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.
219 Where a *_p() predicate is present, it must be called before
220 calling the hook proper. */
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. */
263 extern struct gdb_events *set_gdb_event_hooks (struct gdb_events *vector);
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
280 if ! test -r gdb-events.h
281 then
282 echo "File missing? mv new-gdb-events.h gdb-events.h" 1>&2
283 elif ! diff -c gdb-events.h new-gdb-events.h
284 then
285 echo "gdb-events.h changed? cp new-gdb-events.h gdb-events.h" 1>&2
286 fi
287
288
289
290 #
291 # C file
292 #
293
294 exec > new-gdb-events.c
295 copyright
296 cat <<EOF
297
298 #include "defs.h"
299 #include "gdb-events.h"
300 #include "gdbcmd.h"
301
302 #undef XMALLOC
303 #define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
304
305 #if WITH_GDB_EVENTS
306 static struct gdb_events null_event_hooks;
307 static struct gdb_events queue_event_hooks;
308 static struct gdb_events *current_event_hooks = &null_event_hooks;
309 #endif
310
311 int gdb_events_debug;
312 EOF
313
314 # global pointer variables - always have this
315 #echo ""
316 #function_list | while eval read $read
317 #do
318 # case "${class}" in
319 # "*" )
320 # echo "${returntype} (*${function}_event) (${formal})${attrib} = 0;"
321 # ;;
322 # esac
323 #done
324
325 # function bodies
326 echo ""
327 echo "#if WITH_GDB_EVENTS"
328 function_list | while eval read $read
329 do
330 case "${class}" in
331 "*" ) continue ;;
332 "?" )
333 echo ""
334 echo "int"
335 echo "${function}_event_p (${formal})"
336 echo "{"
337 echo " return current_event_hooks->${function};"
338 echo "}"
339 echo ""
340 echo "${returntype}"
341 echo "${function}_event (${formal})"
342 echo "{"
343 echo " return current_events->${function} (${actual});"
344 echo "}"
345 ;;
346 "f" )
347 echo ""
348 echo "void"
349 echo "${function}_event (${formal})"
350 echo "{"
351 echo " if (gdb_events_debug)"
352 echo " fprintf_unfiltered (gdb_stdlog, \"${function}_event\\n\");"
353 echo " if (!current_event_hooks->${function})"
354 echo " return;"
355 echo " current_event_hooks->${function} (${actual});"
356 echo "}"
357 ;;
358 esac
359 done
360 echo ""
361 echo "#endif"
362
363 # Set hooks function
364 echo ""
365 cat <<EOF
366 #if WITH_GDB_EVENTS
367 struct gdb_events *
368 set_gdb_event_hooks (struct gdb_events *vector)
369 {
370 struct gdb_events *old_events = current_event_hooks;
371 if (vector == NULL)
372 current_event_hooks = &queue_event_hooks;
373 else
374 current_event_hooks = vector;
375 return old_events;
376 EOF
377 function_list | while eval read $read
378 do
379 case "${class}" in
380 "*" )
381 echo " ${function}_event = hooks->${function};"
382 ;;
383 esac
384 done
385 cat <<EOF
386 }
387 #endif
388 EOF
389
390 # event type
391 echo ""
392 cat <<EOF
393 enum gdb_event
394 {
395 EOF
396 function_list | while eval read $read
397 do
398 case "${class}" in
399 "f" )
400 echo " ${function},"
401 ;;
402 esac
403 done
404 cat <<EOF
405 nr_gdb_events
406 };
407 EOF
408
409 # event data
410 echo ""
411 function_list | while eval read $read
412 do
413 case "${class}" in
414 "f" )
415 echo "struct ${function}"
416 echo " {"
417 echo " `echo ${formal} | tr '[,]' '[;]'`;"
418 echo " };"
419 echo ""
420 ;;
421 esac
422 done
423
424 # event queue
425 cat <<EOF
426 struct event
427 {
428 enum gdb_event type;
429 struct event *next;
430 union
431 {
432 EOF
433 function_list | while eval read $read
434 do
435 case "${class}" in
436 "f" )
437 echo " struct ${function} ${function};"
438 ;;
439 esac
440 done
441 cat <<EOF
442 }
443 data;
444 };
445 struct event *pending_events;
446 struct event *delivering_events;
447 EOF
448
449 # append
450 echo ""
451 cat <<EOF
452 static void
453 append (struct event *new_event)
454 {
455 struct event **event = &pending_events;
456 while ((*event) != NULL)
457 event = &((*event)->next);
458 (*event) = new_event;
459 (*event)->next = NULL;
460 }
461 EOF
462
463 # schedule a given event
464 function_list | while eval read $read
465 do
466 case "${class}" in
467 "f" )
468 echo ""
469 echo "static void"
470 echo "queue_${function} (${formal})"
471 echo "{"
472 echo " struct event *event = XMALLOC (struct event);"
473 echo " event->type = ${function};"
474 for arg in `echo ${actual} | tr '[,]' '[ ]'`; do
475 echo " event->data.${function}.${arg} = ${arg};"
476 done
477 echo " append (event);"
478 echo "}"
479 ;;
480 esac
481 done
482
483 # deliver
484 echo ""
485 cat <<EOF
486 void
487 gdb_events_deliver (struct gdb_events *vector)
488 {
489 /* Just zap any events left around from last time. */
490 while (delivering_events != NULL)
491 {
492 struct event *event = delivering_events;
493 delivering_events = event->next;
494 xfree (event);
495 }
496 /* Process any pending events. Because one of the deliveries could
497 bail out we move everything off of the pending queue onto an
498 in-progress queue where it can, later, be cleaned up if
499 necessary. */
500 delivering_events = pending_events;
501 pending_events = NULL;
502 while (delivering_events != NULL)
503 {
504 struct event *event = delivering_events;
505 switch (event->type)
506 {
507 EOF
508 function_list | while eval read $read
509 do
510 case "${class}" in
511 "f" )
512 echo " case ${function}:"
513 echo " vector->${function}"
514 sep=" ("
515 ass=""
516 for arg in `echo ${actual} | tr '[,]' '[ ]'`; do
517 ass="${ass}${sep}event->data.${function}.${arg}"
518 sep=",
519 "
520 done
521 echo "${ass});"
522 echo " break;"
523 ;;
524 esac
525 done
526 cat <<EOF
527 }
528 delivering_events = event->next;
529 xfree (event);
530 }
531 }
532 EOF
533
534 # Finally the initialization
535 echo ""
536 cat <<EOF
537 void _initialize_gdb_events (void);
538 void
539 _initialize_gdb_events (void)
540 {
541 struct cmd_list_element *c;
542 #if WITH_GDB_EVENTS
543 EOF
544 function_list | while eval read $read
545 do
546 case "${class}" in
547 "f" )
548 echo " queue_event_hooks.${function} = queue_${function};"
549 ;;
550 esac
551 done
552 cat <<EOF
553 #endif
554
555 c = add_set_cmd ("eventdebug", class_maintenance, var_zinteger,
556 (char *) (&gdb_events_debug), "Set event debugging.\n\\
557 When non-zero, event/notify debugging is enabled.", &setlist);
558 deprecate_cmd (c, "set debug event");
559 deprecate_cmd (add_show_from_set (c, &showlist), "show debug event");
560
561 add_show_from_set (add_set_cmd ("event",
562 class_maintenance,
563 var_zinteger,
564 (char *) (&gdb_events_debug),
565 "Set event debugging.\n\\
566 When non-zero, event/notify debugging is enabled.", &setdebuglist),
567 &showdebuglist);
568 }
569 EOF
570
571 # close things off
572 exec 1>&2
573 #../move-if-change new-gdb-events.c gdb-events.c
574 # Replace any leading spaces with tabs
575 sed < new-gdb-events.c > tmp-gdb-events.c \
576 -e 's/\( \)* /\1 /g'
577 mv tmp-gdb-events.c new-gdb-events.c
578 # Move if changed?
579 if ! test -r gdb-events.c
580 then
581 echo "File missing? mv new-gdb-events.c gdb-events.c" 1>&2
582 elif ! diff -c gdb-events.c new-gdb-events.c
583 then
584 echo "gdb-events.c changed? cp new-gdb-events.c gdb-events.c" 1>&2
585 fi