Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / gdb-events.sh
blob35279a75081d53cf47a0e921d84cb837a79d296a
1 #!/bin/sh
3 # User Interface Events.
5 # Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Free Software
6 # Foundation, Inc.
8 # Contributed by Cygnus Solutions.
10 # This file is part of GDB.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 # Boston, MA 02110-1301, USA.
27 IFS=:
29 read="class returntype function formal actual attrib"
31 function_list ()
33 # category:
34 # # -> disable
35 # * -> compatibility - pointer variable that is initialized
36 # by set_gdb_events().
37 # ? -> Predicate and function proper.
38 # f -> always call (must have a void returntype)
39 # return-type
40 # name
41 # formal argument list
42 # actual argument list
43 # attributes
44 # description
45 cat <<EOF |
46 f:void:breakpoint_create:int b:b
47 f:void:breakpoint_delete:int b:b
48 f:void:breakpoint_modify:int b:b
49 f:void:tracepoint_create:int number:number
50 f:void:tracepoint_delete:int number:number
51 f:void:tracepoint_modify:int number:number
52 f:void:architecture_changed:void
53 EOF
54 grep -v '^#'
57 copyright ()
59 cat <<EOF
60 /* User Interface Events.
62 Copyright (C) 1999, 2001, 2002, 2004, 2005 Free Software Foundation,
63 Inc.
65 Contributed by Cygnus Solutions.
67 This file is part of GDB.
69 This program is free software; you can redistribute it and/or modify
70 it under the terms of the GNU General Public License as published by
71 the Free Software Foundation; either version 2 of the License, or
72 (at your option) any later version.
74 This program is distributed in the hope that it will be useful,
75 but WITHOUT ANY WARRANTY; without even the implied warranty of
76 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
77 GNU General Public License for more details.
79 You should have received a copy of the GNU General Public License
80 along with this program; if not, write to the Free Software
81 Foundation, Inc., 51 Franklin Street, Fifth Floor,
82 Boston, MA 02110-1301, USA. */
84 /* Work in progress */
86 /* This file was created with the aid of \`\`gdb-events.sh''.
88 The bourn shell script \`\`gdb-events.sh'' creates the files
89 \`\`new-gdb-events.c'' and \`\`new-gdb-events.h and then compares
90 them against the existing \`\`gdb-events.[hc]''. Any differences
91 found being reported.
93 If editing this file, please also run gdb-events.sh and merge any
94 changes into that script. Conversely, when making sweeping changes
95 to this file, modifying gdb-events.sh and using its output may
96 prove easier. */
98 EOF
102 # The .h file
105 exec > new-gdb-events.h
106 copyright
107 cat <<EOF
109 #ifndef GDB_EVENTS_H
110 #define GDB_EVENTS_H
113 # pointer declarations
114 echo ""
115 echo ""
116 cat <<EOF
117 /* COMPAT: pointer variables for old, unconverted events.
118 A call to set_gdb_events() will automatically update these. */
120 echo ""
121 function_list | while eval read $read
123 case "${class}" in
124 "*" )
125 echo "extern ${returntype} (*${function}_event) (${formal})${attrib};"
127 esac
128 done
130 # function typedef's
131 echo ""
132 echo ""
133 cat <<EOF
134 /* Type definition of all hook functions. Recommended pratice is to
135 first declare each hook function using the below ftype and then
136 define it. */
138 echo ""
139 function_list | while eval read $read
141 echo "typedef ${returntype} (gdb_events_${function}_ftype) (${formal});"
142 done
144 # gdb_events object
145 echo ""
146 echo ""
147 cat <<EOF
148 /* gdb-events: object. */
150 echo ""
151 echo "struct gdb_events"
152 echo " {"
153 function_list | while eval read $read
155 echo " gdb_events_${function}_ftype *${function}${attrib};"
156 done
157 echo " };"
159 # function declarations
160 echo ""
161 echo ""
162 cat <<EOF
163 /* Interface into events functions.
164 Where a *_p() predicate is present, it must be called before
165 calling the hook proper. */
167 function_list | while eval read $read
169 case "${class}" in
170 "*" ) continue ;;
171 "?" )
172 echo "extern int ${function}_p (void);"
173 echo "extern ${returntype} ${function}_event (${formal})${attrib};"
175 "f" )
176 echo "extern ${returntype} ${function}_event (${formal})${attrib};"
178 esac
179 done
181 # our set function
182 cat <<EOF
184 /* Install custom gdb-events hooks. */
185 extern struct gdb_events *deprecated_set_gdb_event_hooks (struct gdb_events *vector);
187 /* Deliver any pending events. */
188 extern void gdb_events_deliver (struct gdb_events *vector);
190 /* Clear event handlers. */
191 extern void clear_gdb_event_hooks (void);
194 # close it off
195 echo ""
196 echo "#endif"
197 exec 1>&2
198 #../move-if-change new-gdb-events.h gdb-events.h
199 if test -r gdb-events.h
200 then
201 diff -c gdb-events.h new-gdb-events.h
202 if [ $? = 1 ]
203 then
204 echo "gdb-events.h changed? cp new-gdb-events.h gdb-events.h" 1>&2
206 else
207 echo "File missing? mv new-gdb-events.h gdb-events.h" 1>&2
213 # C file
216 exec > new-gdb-events.c
217 copyright
218 cat <<EOF
220 #include "defs.h"
221 #include "gdb-events.h"
222 #include "gdbcmd.h"
224 static struct gdb_events null_event_hooks;
225 static struct gdb_events queue_event_hooks;
226 static struct gdb_events *current_event_hooks = &null_event_hooks;
228 int gdb_events_debug;
229 static void
230 show_gdb_events_debug (struct ui_file *file, int from_tty,
231 struct cmd_list_element *c, const char *value)
233 fprintf_filtered (file, _("Event debugging is %s.\\n"), value);
238 # function bodies
239 function_list | while eval read $read
241 case "${class}" in
242 "*" ) continue ;;
243 "?" )
244 cat <<EOF
247 ${function}_event_p (${formal})
249 return current_event_hooks->${function};
252 ${returntype}
253 ${function}_event (${formal})
255 return current_events->${function} (${actual});
259 "f" )
260 cat <<EOF
262 void
263 ${function}_event (${formal})
265 if (gdb_events_debug)
266 fprintf_unfiltered (gdb_stdlog, "${function}_event\n");
267 if (!current_event_hooks->${function})
268 return;
269 current_event_hooks->${function} (${actual});
273 esac
274 done
276 # Set hooks function
277 echo ""
278 cat <<EOF
279 struct gdb_events *
280 deprecated_set_gdb_event_hooks (struct gdb_events *vector)
282 struct gdb_events *old_events = current_event_hooks;
283 if (vector == NULL)
284 current_event_hooks = &queue_event_hooks;
285 else
286 current_event_hooks = vector;
287 return old_events;
289 function_list | while eval read $read
291 case "${class}" in
292 "*" )
293 echo " ${function}_event = hooks->${function};"
295 esac
296 done
297 cat <<EOF
301 # Clear hooks function
302 echo ""
303 cat <<EOF
304 void
305 clear_gdb_event_hooks (void)
307 deprecated_set_gdb_event_hooks (&null_event_hooks);
311 # event type
312 echo ""
313 cat <<EOF
314 enum gdb_event
317 function_list | while eval read $read
319 case "${class}" in
320 "f" )
321 echo " ${function},"
323 esac
324 done
325 cat <<EOF
326 nr_gdb_events
330 # event data
331 echo ""
332 function_list | while eval read $read
334 case "${class}" in
335 "f" )
336 if test ${actual}
337 then
338 echo "struct ${function}"
339 echo " {"
340 echo " `echo ${formal} | tr '[,]' '[;]'`;"
341 echo " };"
342 echo ""
345 esac
346 done
348 # event queue
349 cat <<EOF
350 struct event
352 enum gdb_event type;
353 struct event *next;
354 union
357 function_list | while eval read $read
359 case "${class}" in
360 "f" )
361 if test ${actual}
362 then
363 echo " struct ${function} ${function};"
366 esac
367 done
368 cat <<EOF
370 data;
372 struct event *pending_events;
373 struct event *delivering_events;
376 # append
377 echo ""
378 cat <<EOF
379 static void
380 append (struct event *new_event)
382 struct event **event = &pending_events;
383 while ((*event) != NULL)
384 event = &((*event)->next);
385 (*event) = new_event;
386 (*event)->next = NULL;
390 # schedule a given event
391 function_list | while eval read $read
393 case "${class}" in
394 "f" )
395 echo ""
396 echo "static void"
397 echo "queue_${function} (${formal})"
398 echo "{"
399 echo " struct event *event = XMALLOC (struct event);"
400 echo " event->type = ${function};"
401 for arg in `echo ${actual} | tr '[,]' '[:]' | tr -d '[ ]'`; do
402 echo " event->data.${function}.${arg} = ${arg};"
403 done
404 echo " append (event);"
405 echo "}"
407 esac
408 done
410 # deliver
411 echo ""
412 cat <<EOF
413 void
414 gdb_events_deliver (struct gdb_events *vector)
416 /* Just zap any events left around from last time. */
417 while (delivering_events != NULL)
419 struct event *event = delivering_events;
420 delivering_events = event->next;
421 xfree (event);
423 /* Process any pending events. Because one of the deliveries could
424 bail out we move everything off of the pending queue onto an
425 in-progress queue where it can, later, be cleaned up if
426 necessary. */
427 delivering_events = pending_events;
428 pending_events = NULL;
429 while (delivering_events != NULL)
431 struct event *event = delivering_events;
432 switch (event->type)
435 function_list | while eval read $read
437 case "${class}" in
438 "f" )
439 echo " case ${function}:"
440 if test ${actual}
441 then
442 echo " vector->${function}"
443 sep=" ("
444 ass=""
445 for arg in `echo ${actual} | tr '[,]' '[:]' | tr -d '[ ]'`; do
446 ass="${ass}${sep}event->data.${function}.${arg}"
447 sep=",
449 done
450 echo "${ass});"
451 else
452 echo " vector->${function} ();"
454 echo " break;"
456 esac
457 done
458 cat <<EOF
460 delivering_events = event->next;
461 xfree (event);
466 # Finally the initialization
467 echo ""
468 cat <<EOF
469 void _initialize_gdb_events (void);
470 void
471 _initialize_gdb_events (void)
473 struct cmd_list_element *c;
475 function_list | while eval read $read
477 case "${class}" in
478 "f" )
479 echo " queue_event_hooks.${function} = queue_${function};"
481 esac
482 done
483 cat <<EOF
485 add_setshow_zinteger_cmd ("event", class_maintenance,
486 &gdb_events_debug, _("\\
487 Set event debugging."), _("\\
488 Show event debugging."), _("\\
489 When non-zero, event/notify debugging is enabled."),
490 NULL,
491 show_gdb_events_debug,
492 &setdebuglist, &showdebuglist);
496 # close things off
497 exec 1>&2
498 #../move-if-change new-gdb-events.c gdb-events.c
499 # Replace any leading spaces with tabs
500 sed < new-gdb-events.c > tmp-gdb-events.c \
501 -e 's/\( \)* /\1 /g'
502 mv tmp-gdb-events.c new-gdb-events.c
503 # Move if changed?
504 if test -r gdb-events.c
505 then
506 diff -c gdb-events.c new-gdb-events.c
507 if [ $? = 1 ]
508 then
509 echo "gdb-events.c changed? cp new-gdb-events.c gdb-events.c" 1>&2
511 else
512 echo "File missing? mv new-gdb-events.c gdb-events.c" 1>&2