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