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