OSDN Git Service

* gdb.texinfo (Target Description Format): Add version attribute
[pf3gnuchains/pf3gnuchains4x.git] / gdb / gdb-events.sh
1 #!/bin/sh
2
3 # User Interface Events.
4 #
5 # Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007
6 # Free Software Foundation, Inc.
7 #
8 # Contributed by Cygnus Solutions.
9 #
10 # This file is part of GDB.
11 #
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.
16 #
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.
21 #
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.
26
27 IFS=:
28
29 read="class returntype function formal actual attrib"
30
31 function_list ()
32 {
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 '^#'
55 }
56
57 copyright ()
58 {
59   cat <<EOF
60 /* User Interface Events.
61
62    Copyright (C) 1999, 2001, 2002, 2004, 2005 Free Software Foundation,
63    Inc.
64
65    Contributed by Cygnus Solutions.
66
67    This file is part of GDB.
68
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.
73
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.
78
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.  */
83
84 /* Work in progress */
85
86 /* This file was created with the aid of \`\`gdb-events.sh''.
87
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.
92
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.  */
97
98 EOF
99 }
100
101 #
102 # The .h file
103 #
104
105 exec > new-gdb-events.h
106 copyright
107 cat <<EOF
108
109 #ifndef GDB_EVENTS_H
110 #define GDB_EVENTS_H
111 EOF
112
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. */
119 EOF
120 echo ""
121 function_list | while eval read $read
122 do
123   case "${class}" in
124     "*" )
125         echo "extern ${returntype} (*${function}_event) (${formal})${attrib};"
126         ;;
127   esac
128 done
129
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.  */
137 EOF
138 echo ""
139 function_list | while eval read $read
140 do
141   echo "typedef ${returntype} (gdb_events_${function}_ftype) (${formal});"
142 done
143
144 # gdb_events object
145 echo ""
146 echo ""
147 cat <<EOF
148 /* gdb-events: object. */
149 EOF
150 echo ""
151 echo "struct gdb_events"
152 echo "  {"
153 function_list | while eval read $read
154 do
155   echo "    gdb_events_${function}_ftype *${function}${attrib};"
156 done
157 echo "  };"
158
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.  */
166 EOF
167 function_list | while eval read $read
168 do
169   case "${class}" in
170     "*" ) continue ;;
171     "?" )
172         echo "extern int ${function}_p (void);"
173         echo "extern ${returntype} ${function}_event (${formal})${attrib};"
174         ;;
175     "f" )
176         echo "extern ${returntype} ${function}_event (${formal})${attrib};"
177         ;;
178   esac
179 done
180
181 # our set function
182 cat <<EOF
183
184 /* Install custom gdb-events hooks.  */
185 extern struct gdb_events *deprecated_set_gdb_event_hooks (struct gdb_events *vector);
186
187 /* Deliver any pending events.  */
188 extern void gdb_events_deliver (struct gdb_events *vector);
189
190 /* Clear event handlers.  */
191 extern void clear_gdb_event_hooks (void);
192 EOF
193
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
205   fi
206 else
207   echo "File missing? mv new-gdb-events.h gdb-events.h" 1>&2
208 fi
209
210
211
212 #
213 # C file
214 #
215
216 exec > new-gdb-events.c
217 copyright
218 cat <<EOF
219
220 #include "defs.h"
221 #include "gdb-events.h"
222 #include "gdbcmd.h"
223
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;
227
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)
232 {
233   fprintf_filtered (file, _("Event debugging is %s.\\n"), value);
234 }
235
236 EOF
237
238 # function bodies
239 function_list | while eval read $read
240 do
241   case "${class}" in
242     "*" ) continue ;;
243     "?" )
244 cat <<EOF
245
246 int
247 ${function}_event_p (${formal})
248 {
249   return current_event_hooks->${function};
250 }
251
252 ${returntype}
253 ${function}_event (${formal})
254 {
255   return current_events->${function} (${actual});
256 }
257 EOF
258         ;;
259      "f" )
260 cat <<EOF
261
262 void
263 ${function}_event (${formal})
264 {
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});
270 }
271 EOF
272         ;;
273   esac
274 done
275
276 # Set hooks function
277 echo ""
278 cat <<EOF
279 struct gdb_events *
280 deprecated_set_gdb_event_hooks (struct gdb_events *vector)
281 {
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;
288 EOF
289 function_list | while eval read $read
290 do
291   case "${class}" in
292     "*" )
293       echo "  ${function}_event = hooks->${function};"
294       ;;
295   esac
296 done
297 cat <<EOF
298 }
299 EOF
300
301 # Clear hooks function
302 echo ""
303 cat <<EOF
304 void
305 clear_gdb_event_hooks (void)
306 {
307   deprecated_set_gdb_event_hooks (&null_event_hooks);
308 }
309 EOF
310
311 # event type
312 echo ""
313 cat <<EOF
314 enum gdb_event
315 {
316 EOF
317 function_list | while eval read $read
318 do
319   case "${class}" in
320     "f" )
321       echo "  ${function},"
322       ;;
323   esac
324 done
325 cat <<EOF
326   nr_gdb_events
327 };
328 EOF
329
330 # event data
331 echo ""
332 function_list | while eval read $read
333 do
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 ""
343       fi
344       ;;
345   esac
346 done
347
348 # event queue
349 cat <<EOF
350 struct event
351   {
352     enum gdb_event type;
353     struct event *next;
354     union
355       {
356 EOF
357 function_list | while eval read $read
358 do
359   case "${class}" in
360     "f" )
361       if test ${actual}
362       then
363         echo "        struct ${function} ${function};"
364       fi
365       ;;
366   esac
367 done
368 cat <<EOF
369       }
370     data;
371   };
372 struct event *pending_events;
373 struct event *delivering_events;
374 EOF
375
376 # append
377 echo ""
378 cat <<EOF
379 static void
380 append (struct event *new_event)
381 {
382   struct event **event = &pending_events;
383   while ((*event) != NULL)
384     event = &((*event)->next);
385   (*event) = new_event;
386   (*event)->next = NULL;
387 }
388 EOF
389
390 # schedule a given event
391 function_list | while eval read $read
392 do
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 "}"
406       ;;
407   esac
408 done
409
410 # deliver
411 echo ""
412 cat <<EOF
413 void
414 gdb_events_deliver (struct gdb_events *vector)
415 {
416   /* Just zap any events left around from last time. */
417   while (delivering_events != NULL)
418     {
419       struct event *event = delivering_events;
420       delivering_events = event->next;
421       xfree (event);
422     }
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)
430     {
431       struct event *event = delivering_events;
432       switch (event->type)
433         {
434 EOF
435 function_list | while eval read $read
436 do
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=",
448                "
449         done
450         echo "${ass});"
451       else
452         echo "          vector->${function} ();"
453       fi
454       echo "          break;"
455       ;;
456   esac
457 done
458 cat <<EOF
459         }
460       delivering_events = event->next;
461       xfree (event);
462     }
463 }
464 EOF
465
466 # Finally the initialization
467 echo ""
468 cat <<EOF
469 void _initialize_gdb_events (void);
470 void
471 _initialize_gdb_events (void)
472 {
473   struct cmd_list_element *c;
474 EOF
475 function_list | while eval read $read
476 do
477   case "${class}" in
478     "f" )
479       echo "  queue_event_hooks.${function} = queue_${function};"
480       ;;
481   esac
482 done
483 cat <<EOF
484
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);
493 }
494 EOF
495
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
510   fi
511 else
512   echo "File missing? mv new-gdb-events.c gdb-events.c" 1>&2
513 fi