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