*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / gdb-events.sh
CommitLineData
104c1213
JM
1#!/bin/sh
2
3# User Interface Events.
11dced61 4#
197e01b6 5# Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Free Software
11dced61 6# Foundation, Inc.
104c1213
JM
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
197e01b6
EZ
24# Foundation, Inc., 51 Franklin Street, Fifth Floor,
25# Boston, MA 02110-1301, USA.
104c1213 26
104c1213
JM
27IFS=:
28
29read="class returntype function formal actual attrib"
30
31function_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 |
46f:void:breakpoint_create:int b:b
47f:void:breakpoint_delete:int b:b
48f:void:breakpoint_modify:int b:b
ba9fe036
KS
49f:void:tracepoint_create:int number:number
50f:void:tracepoint_delete:int number:number
51f:void:tracepoint_modify:int number:number
67c2c32c 52f:void:architecture_changed:void
104c1213
JM
53EOF
54 grep -v '^#'
55}
56
57copyright ()
58{
59 cat <<EOF
60/* User Interface Events.
349c5d5f 61
197e01b6 62 Copyright (C) 1999, 2001, 2002, 2004, 2005 Free Software Foundation,
11dced61 63 Inc.
104c1213
JM
64
65 Contributed by Cygnus Solutions.
66
afbfc876 67 This file is part of GDB.
104c1213 68
afbfc876
AC
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.
104c1213 73
afbfc876
AC
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.
104c1213 78
afbfc876
AC
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
197e01b6
EZ
81 Foundation, Inc., 51 Franklin Street, Fifth Floor,
82 Boston, MA 02110-1301, USA. */
104c1213
JM
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
30867156 96 prove easier. */
104c1213
JM
97
98EOF
99}
100
101#
102# The .h file
103#
104
105exec > new-gdb-events.h
106copyright
107cat <<EOF
108
109#ifndef GDB_EVENTS_H
110#define GDB_EVENTS_H
104c1213
JM
111EOF
112
113# pointer declarations
114echo ""
115echo ""
116cat <<EOF
117/* COMPAT: pointer variables for old, unconverted events.
118 A call to set_gdb_events() will automatically update these. */
119EOF
120echo ""
121function_list | while eval read $read
122do
123 case "${class}" in
124 "*" )
125 echo "extern ${returntype} (*${function}_event) (${formal})${attrib};"
126 ;;
127 esac
128done
129
130# function typedef's
131echo ""
132echo ""
133cat <<EOF
30867156
MS
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. */
104c1213
JM
137EOF
138echo ""
139function_list | while eval read $read
140do
141 echo "typedef ${returntype} (gdb_events_${function}_ftype) (${formal});"
142done
143
144# gdb_events object
145echo ""
146echo ""
147cat <<EOF
148/* gdb-events: object. */
149EOF
150echo ""
151echo "struct gdb_events"
152echo " {"
153function_list | while eval read $read
154do
155 echo " gdb_events_${function}_ftype *${function}${attrib};"
156done
157echo " };"
158
159# function declarations
160echo ""
161echo ""
162cat <<EOF
163/* Interface into events functions.
c4093a6a 164 Where a *_p() predicate is present, it must be called before
30867156 165 calling the hook proper. */
104c1213
JM
166EOF
167function_list | while eval read $read
168do
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
179done
180
104c1213
JM
181# our set function
182cat <<EOF
183
30867156 184/* Install custom gdb-events hooks. */
2726dafc 185extern struct gdb_events *deprecated_set_gdb_event_hooks (struct gdb_events *vector);
104c1213 186
30867156 187/* Deliver any pending events. */
104c1213
JM
188extern void gdb_events_deliver (struct gdb_events *vector);
189
30867156 190/* Clear event handlers. */
63d022e0 191extern void clear_gdb_event_hooks (void);
104c1213
JM
192EOF
193
194# close it off
195echo ""
196echo "#endif"
197exec 1>&2
198#../move-if-change new-gdb-events.h gdb-events.h
9e791099 199if test -r gdb-events.h
104c1213 200then
9e791099
KS
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
206else
104c1213 207 echo "File missing? mv new-gdb-events.h gdb-events.h" 1>&2
104c1213
JM
208fi
209
210
211
212#
213# C file
214#
215
216exec > new-gdb-events.c
217copyright
218cat <<EOF
219
220#include "defs.h"
221#include "gdb-events.h"
222#include "gdbcmd.h"
223
104c1213
JM
224static struct gdb_events null_event_hooks;
225static struct gdb_events queue_event_hooks;
226static struct gdb_events *current_event_hooks = &null_event_hooks;
104c1213
JM
227
228int gdb_events_debug;
920d2a44
AC
229static void
230show_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
104c1213
JM
236EOF
237
104c1213 238# function bodies
104c1213
JM
239function_list | while eval read $read
240do
241 case "${class}" in
242 "*" ) continue ;;
243 "?" )
9e791099
KS
244cat <<EOF
245
246int
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}
257EOF
104c1213
JM
258 ;;
259 "f" )
9e791099
KS
260cat <<EOF
261
262void
263${function}_event (${formal})
264{
265 if (gdb_events_debug)
8c6ee715 266 fprintf_unfiltered (gdb_stdlog, "${function}_event\n");
9e791099
KS
267 if (!current_event_hooks->${function})
268 return;
269 current_event_hooks->${function} (${actual});
270}
271EOF
104c1213
JM
272 ;;
273 esac
274done
104c1213
JM
275
276# Set hooks function
277echo ""
278cat <<EOF
ed9a39eb 279struct gdb_events *
2726dafc 280deprecated_set_gdb_event_hooks (struct gdb_events *vector)
104c1213 281{
ed9a39eb 282 struct gdb_events *old_events = current_event_hooks;
104c1213
JM
283 if (vector == NULL)
284 current_event_hooks = &queue_event_hooks;
285 else
286 current_event_hooks = vector;
ed9a39eb 287 return old_events;
104c1213
JM
288EOF
289function_list | while eval read $read
290do
291 case "${class}" in
292 "*" )
293 echo " ${function}_event = hooks->${function};"
294 ;;
295 esac
296done
297cat <<EOF
298}
104c1213
JM
299EOF
300
63d022e0
KS
301# Clear hooks function
302echo ""
303cat <<EOF
63d022e0
KS
304void
305clear_gdb_event_hooks (void)
306{
2726dafc 307 deprecated_set_gdb_event_hooks (&null_event_hooks);
63d022e0 308}
63d022e0
KS
309EOF
310
104c1213
JM
311# event type
312echo ""
313cat <<EOF
314enum gdb_event
afbfc876 315{
104c1213
JM
316EOF
317function_list | while eval read $read
318do
319 case "${class}" in
320 "f" )
afbfc876 321 echo " ${function},"
104c1213
JM
322 ;;
323 esac
324done
325cat <<EOF
afbfc876
AC
326 nr_gdb_events
327};
104c1213
JM
328EOF
329
330# event data
331echo ""
332function_list | while eval read $read
333do
334 case "${class}" in
335 "f" )
fd969be2
KS
336 if test ${actual}
337 then
338 echo "struct ${function}"
339 echo " {"
340 echo " `echo ${formal} | tr '[,]' '[;]'`;"
341 echo " };"
342 echo ""
343 fi
104c1213
JM
344 ;;
345 esac
346done
347
348# event queue
349cat <<EOF
350struct event
351 {
352 enum gdb_event type;
353 struct event *next;
354 union
355 {
356EOF
357function_list | while eval read $read
358do
359 case "${class}" in
360 "f" )
fd969be2
KS
361 if test ${actual}
362 then
363 echo " struct ${function} ${function};"
364 fi
104c1213
JM
365 ;;
366 esac
367done
368cat <<EOF
369 }
370 data;
371 };
372struct event *pending_events;
373struct event *delivering_events;
374EOF
375
376# append
377echo ""
378cat <<EOF
379static void
380append (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}
388EOF
389
390# schedule a given event
391function_list | while eval read $read
392do
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};"
9e791099 401 for arg in `echo ${actual} | tr '[,]' '[:]' | tr -d '[ ]'`; do
104c1213
JM
402 echo " event->data.${function}.${arg} = ${arg};"
403 done
404 echo " append (event);"
405 echo "}"
406 ;;
407 esac
408done
409
410# deliver
411echo ""
412cat <<EOF
413void
414gdb_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;
e28f816a 421 xfree (event);
104c1213
JM
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 {
434EOF
435function_list | while eval read $read
436do
437 case "${class}" in
438 "f" )
439 echo " case ${function}:"
fd969be2
KS
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
104c1213
JM
454 echo " break;"
455 ;;
456 esac
457done
458cat <<EOF
459 }
460 delivering_events = event->next;
e28f816a 461 xfree (event);
104c1213
JM
462 }
463}
464EOF
465
466# Finally the initialization
467echo ""
468cat <<EOF
469void _initialize_gdb_events (void);
470void
471_initialize_gdb_events (void)
472{
afbfc876 473 struct cmd_list_element *c;
104c1213
JM
474EOF
475function_list | while eval read $read
476do
477 case "${class}" in
478 "f" )
479 echo " queue_event_hooks.${function} = queue_${function};"
480 ;;
481 esac
482done
483cat <<EOF
afbfc876 484
85c07804
AC
485 add_setshow_zinteger_cmd ("event", class_maintenance,
486 &gdb_events_debug, _("\\
487Set event debugging."), _("\\
488Show event debugging."), _("\\
489When non-zero, event/notify debugging is enabled."),
490 NULL,
920d2a44 491 show_gdb_events_debug,
85c07804 492 &setdebuglist, &showdebuglist);
104c1213
JM
493}
494EOF
495
496# close things off
497exec 1>&2
498#../move-if-change new-gdb-events.c gdb-events.c
afbfc876
AC
499# Replace any leading spaces with tabs
500sed < new-gdb-events.c > tmp-gdb-events.c \
501 -e 's/\( \)* /\1 /g'
502mv tmp-gdb-events.c new-gdb-events.c
503# Move if changed?
9e791099 504if test -r gdb-events.c
104c1213 505then
9e791099
KS
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
511else
104c1213 512 echo "File missing? mv new-gdb-events.c gdb-events.c" 1>&2
104c1213 513fi
This page took 0.456961 seconds and 4 git commands to generate.