2004-04-29 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / gdb-events.sh
CommitLineData
104c1213
JM
1#!/bin/sh
2
3# User Interface Events.
9564ee9f 4# Copyright 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
104c1213
JM
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
104c1213
JM
24IFS=:
25
26read="class returntype function formal actual attrib"
27
28function_list ()
29{
30 # category:
31 # # -> disable
32 # * -> compatibility - pointer variable that is initialized
33 # by set_gdb_events().
34 # ? -> Predicate and function proper.
35 # f -> always call (must have a void returntype)
36 # return-type
37 # name
38 # formal argument list
39 # actual argument list
40 # attributes
41 # description
42 cat <<EOF |
43f:void:breakpoint_create:int b:b
44f:void:breakpoint_delete:int b:b
45f:void:breakpoint_modify:int b:b
ba9fe036
KS
46f:void:tracepoint_create:int number:number
47f:void:tracepoint_delete:int number:number
48f:void:tracepoint_modify:int number:number
67c2c32c 49f:void:architecture_changed:void
e23792cc 50f:void:target_changed:void
55970da6 51f:void:selected_frame_level_changed:int level:level
28ee05e9 52f:void:selected_thread_changed:int thread_num:thread_num
104c1213
JM
53EOF
54 grep -v '^#'
55}
56
57copyright ()
58{
59 cat <<EOF
60/* User Interface Events.
349c5d5f 61
711cc5cd 62 Copyright 1999, 2001, 2002, 2004 Free Software Foundation, Inc.
104c1213
JM
63
64 Contributed by Cygnus Solutions.
65
afbfc876 66 This file is part of GDB.
104c1213 67
afbfc876
AC
68 This program is free software; you can redistribute it and/or modify
69 it under the terms of the GNU General Public License as published by
70 the Free Software Foundation; either version 2 of the License, or
71 (at your option) any later version.
104c1213 72
afbfc876
AC
73 This program is distributed in the hope that it will be useful,
74 but WITHOUT ANY WARRANTY; without even the implied warranty of
75 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
76 GNU General Public License for more details.
104c1213 77
afbfc876
AC
78 You should have received a copy of the GNU General Public License
79 along with this program; if not, write to the Free Software
80 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
104c1213
JM
81
82/* Work in progress */
83
84/* This file was created with the aid of \`\`gdb-events.sh''.
85
86 The bourn shell script \`\`gdb-events.sh'' creates the files
87 \`\`new-gdb-events.c'' and \`\`new-gdb-events.h and then compares
88 them against the existing \`\`gdb-events.[hc]''. Any differences
89 found being reported.
90
91 If editing this file, please also run gdb-events.sh and merge any
92 changes into that script. Conversely, when making sweeping changes
93 to this file, modifying gdb-events.sh and using its output may
94 prove easier. */
95
96EOF
97}
98
99#
100# The .h file
101#
102
103exec > new-gdb-events.h
104copyright
105cat <<EOF
106
107#ifndef GDB_EVENTS_H
108#define GDB_EVENTS_H
104c1213
JM
109EOF
110
111# pointer declarations
112echo ""
113echo ""
114cat <<EOF
115/* COMPAT: pointer variables for old, unconverted events.
116 A call to set_gdb_events() will automatically update these. */
117EOF
118echo ""
119function_list | while eval read $read
120do
121 case "${class}" in
122 "*" )
123 echo "extern ${returntype} (*${function}_event) (${formal})${attrib};"
124 ;;
125 esac
126done
127
128# function typedef's
129echo ""
130echo ""
131cat <<EOF
132/* Type definition of all hook functions.
133 Recommended pratice is to first declare each hook function using
134 the below ftype and then define it. */
135EOF
136echo ""
137function_list | while eval read $read
138do
139 echo "typedef ${returntype} (gdb_events_${function}_ftype) (${formal});"
140done
141
142# gdb_events object
143echo ""
144echo ""
145cat <<EOF
146/* gdb-events: object. */
147EOF
148echo ""
149echo "struct gdb_events"
150echo " {"
151function_list | while eval read $read
152do
153 echo " gdb_events_${function}_ftype *${function}${attrib};"
154done
155echo " };"
156
157# function declarations
158echo ""
159echo ""
160cat <<EOF
161/* Interface into events functions.
c4093a6a
JM
162 Where a *_p() predicate is present, it must be called before
163 calling the hook proper. */
104c1213
JM
164EOF
165function_list | while eval read $read
166do
167 case "${class}" in
168 "*" ) continue ;;
169 "?" )
170 echo "extern int ${function}_p (void);"
171 echo "extern ${returntype} ${function}_event (${formal})${attrib};"
172 ;;
173 "f" )
174 echo "extern ${returntype} ${function}_event (${formal})${attrib};"
175 ;;
176 esac
177done
178
104c1213
JM
179# our set function
180cat <<EOF
181
182/* Install custom gdb-events hooks. */
ed9a39eb 183extern struct gdb_events *set_gdb_event_hooks (struct gdb_events *vector);
104c1213
JM
184
185/* Deliver any pending events. */
186extern void gdb_events_deliver (struct gdb_events *vector);
187
63d022e0
KS
188/* Clear event handlers */
189extern void clear_gdb_event_hooks (void);
104c1213
JM
190EOF
191
192# close it off
193echo ""
194echo "#endif"
195exec 1>&2
196#../move-if-change new-gdb-events.h gdb-events.h
9e791099 197if test -r gdb-events.h
104c1213 198then
9e791099
KS
199 diff -c gdb-events.h new-gdb-events.h
200 if [ $? = 1 ]
201 then
202 echo "gdb-events.h changed? cp new-gdb-events.h gdb-events.h" 1>&2
203 fi
204else
104c1213 205 echo "File missing? mv new-gdb-events.h gdb-events.h" 1>&2
104c1213
JM
206fi
207
208
209
210#
211# C file
212#
213
214exec > new-gdb-events.c
215copyright
216cat <<EOF
217
218#include "defs.h"
219#include "gdb-events.h"
220#include "gdbcmd.h"
221
104c1213
JM
222static struct gdb_events null_event_hooks;
223static struct gdb_events queue_event_hooks;
224static struct gdb_events *current_event_hooks = &null_event_hooks;
104c1213
JM
225
226int gdb_events_debug;
227EOF
228
104c1213 229# function bodies
104c1213
JM
230function_list | while eval read $read
231do
232 case "${class}" in
233 "*" ) continue ;;
234 "?" )
9e791099
KS
235cat <<EOF
236
237int
238${function}_event_p (${formal})
239{
240 return current_event_hooks->${function};
241}
242
243${returntype}
244${function}_event (${formal})
245{
246 return current_events->${function} (${actual});
247}
248EOF
104c1213
JM
249 ;;
250 "f" )
9e791099
KS
251cat <<EOF
252
253void
254${function}_event (${formal})
255{
256 if (gdb_events_debug)
8c6ee715 257 fprintf_unfiltered (gdb_stdlog, "${function}_event\n");
9e791099
KS
258 if (!current_event_hooks->${function})
259 return;
260 current_event_hooks->${function} (${actual});
261}
262EOF
104c1213
JM
263 ;;
264 esac
265done
104c1213
JM
266
267# Set hooks function
268echo ""
269cat <<EOF
ed9a39eb 270struct gdb_events *
104c1213
JM
271set_gdb_event_hooks (struct gdb_events *vector)
272{
ed9a39eb 273 struct gdb_events *old_events = current_event_hooks;
104c1213
JM
274 if (vector == NULL)
275 current_event_hooks = &queue_event_hooks;
276 else
277 current_event_hooks = vector;
ed9a39eb 278 return old_events;
104c1213
JM
279EOF
280function_list | while eval read $read
281do
282 case "${class}" in
283 "*" )
284 echo " ${function}_event = hooks->${function};"
285 ;;
286 esac
287done
288cat <<EOF
289}
104c1213
JM
290EOF
291
63d022e0
KS
292# Clear hooks function
293echo ""
294cat <<EOF
63d022e0
KS
295void
296clear_gdb_event_hooks (void)
297{
298 set_gdb_event_hooks (&null_event_hooks);
299}
63d022e0
KS
300EOF
301
104c1213
JM
302# event type
303echo ""
304cat <<EOF
305enum gdb_event
afbfc876 306{
104c1213
JM
307EOF
308function_list | while eval read $read
309do
310 case "${class}" in
311 "f" )
afbfc876 312 echo " ${function},"
104c1213
JM
313 ;;
314 esac
315done
316cat <<EOF
afbfc876
AC
317 nr_gdb_events
318};
104c1213
JM
319EOF
320
321# event data
322echo ""
323function_list | while eval read $read
324do
325 case "${class}" in
326 "f" )
fd969be2
KS
327 if test ${actual}
328 then
329 echo "struct ${function}"
330 echo " {"
331 echo " `echo ${formal} | tr '[,]' '[;]'`;"
332 echo " };"
333 echo ""
334 fi
104c1213
JM
335 ;;
336 esac
337done
338
339# event queue
340cat <<EOF
341struct event
342 {
343 enum gdb_event type;
344 struct event *next;
345 union
346 {
347EOF
348function_list | while eval read $read
349do
350 case "${class}" in
351 "f" )
fd969be2
KS
352 if test ${actual}
353 then
354 echo " struct ${function} ${function};"
355 fi
104c1213
JM
356 ;;
357 esac
358done
359cat <<EOF
360 }
361 data;
362 };
363struct event *pending_events;
364struct event *delivering_events;
365EOF
366
367# append
368echo ""
369cat <<EOF
370static void
371append (struct event *new_event)
372{
373 struct event **event = &pending_events;
374 while ((*event) != NULL)
375 event = &((*event)->next);
376 (*event) = new_event;
377 (*event)->next = NULL;
378}
379EOF
380
381# schedule a given event
382function_list | while eval read $read
383do
384 case "${class}" in
385 "f" )
386 echo ""
387 echo "static void"
388 echo "queue_${function} (${formal})"
389 echo "{"
390 echo " struct event *event = XMALLOC (struct event);"
391 echo " event->type = ${function};"
9e791099 392 for arg in `echo ${actual} | tr '[,]' '[:]' | tr -d '[ ]'`; do
104c1213
JM
393 echo " event->data.${function}.${arg} = ${arg};"
394 done
395 echo " append (event);"
396 echo "}"
397 ;;
398 esac
399done
400
401# deliver
402echo ""
403cat <<EOF
404void
405gdb_events_deliver (struct gdb_events *vector)
406{
407 /* Just zap any events left around from last time. */
408 while (delivering_events != NULL)
409 {
410 struct event *event = delivering_events;
411 delivering_events = event->next;
e28f816a 412 xfree (event);
104c1213
JM
413 }
414 /* Process any pending events. Because one of the deliveries could
415 bail out we move everything off of the pending queue onto an
416 in-progress queue where it can, later, be cleaned up if
417 necessary. */
418 delivering_events = pending_events;
419 pending_events = NULL;
420 while (delivering_events != NULL)
421 {
422 struct event *event = delivering_events;
423 switch (event->type)
424 {
425EOF
426function_list | while eval read $read
427do
428 case "${class}" in
429 "f" )
430 echo " case ${function}:"
fd969be2
KS
431 if test ${actual}
432 then
433 echo " vector->${function}"
434 sep=" ("
435 ass=""
436 for arg in `echo ${actual} | tr '[,]' '[:]' | tr -d '[ ]'`; do
437 ass="${ass}${sep}event->data.${function}.${arg}"
438 sep=",
439 "
440 done
441 echo "${ass});"
442 else
443 echo " vector->${function} ();"
444 fi
104c1213
JM
445 echo " break;"
446 ;;
447 esac
448done
449cat <<EOF
450 }
451 delivering_events = event->next;
e28f816a 452 xfree (event);
104c1213
JM
453 }
454}
455EOF
456
457# Finally the initialization
458echo ""
459cat <<EOF
460void _initialize_gdb_events (void);
461void
462_initialize_gdb_events (void)
463{
afbfc876 464 struct cmd_list_element *c;
104c1213
JM
465EOF
466function_list | while eval read $read
467do
468 case "${class}" in
469 "f" )
470 echo " queue_event_hooks.${function} = queue_${function};"
471 ;;
472 esac
473done
474cat <<EOF
afbfc876
AC
475
476 c = add_set_cmd ("eventdebug", class_maintenance, var_zinteger,
477 (char *) (&gdb_events_debug), "Set event debugging.\n\\
478When non-zero, event/notify debugging is enabled.", &setlist);
479 deprecate_cmd (c, "set debug event");
480 deprecate_cmd (add_show_from_set (c, &showlist), "show debug event");
481
482 add_show_from_set (add_set_cmd ("event",
104c1213
JM
483 class_maintenance,
484 var_zinteger,
afbfc876 485 (char *) (&gdb_events_debug),
104c1213 486 "Set event debugging.\n\\
afbfc876
AC
487When non-zero, event/notify debugging is enabled.", &setdebuglist),
488 &showdebuglist);
104c1213
JM
489}
490EOF
491
492# close things off
493exec 1>&2
494#../move-if-change new-gdb-events.c gdb-events.c
afbfc876
AC
495# Replace any leading spaces with tabs
496sed < new-gdb-events.c > tmp-gdb-events.c \
497 -e 's/\( \)* /\1 /g'
498mv tmp-gdb-events.c new-gdb-events.c
499# Move if changed?
9e791099 500if test -r gdb-events.c
104c1213 501then
9e791099
KS
502 diff -c gdb-events.c new-gdb-events.c
503 if [ $? = 1 ]
504 then
505 echo "gdb-events.c changed? cp new-gdb-events.c gdb-events.c" 1>&2
506 fi
507else
104c1213 508 echo "File missing? mv new-gdb-events.c gdb-events.c" 1>&2
104c1213 509fi
This page took 0.348065 seconds and 4 git commands to generate.