| 1 | #!/bin/sh -e |
| 2 | |
| 3 | # Make certain that the script is not running in an internationalized |
| 4 | # environment. |
| 5 | LANG=C ; export LANG |
| 6 | LC_ALL=C ; export LC_ALL |
| 7 | |
| 8 | if test $# -ne 3 |
| 9 | then |
| 10 | echo "Usage: $0 <h|inc> <observer.texi> <observer.out>" 1>&2 |
| 11 | exit 0 |
| 12 | fi |
| 13 | |
| 14 | lang=$1 ; shift |
| 15 | texi=$1 ; shift |
| 16 | o=$1 |
| 17 | case $lang in |
| 18 | h) tmp=htmp ;; |
| 19 | inc) tmp=itmp ;; |
| 20 | esac |
| 21 | otmp="`echo $1 | sed -e 's,\.[^.]*$,,'`.$tmp"; shift |
| 22 | echo "Creating ${otmp}" 1>&2 |
| 23 | rm -f ${otmp} |
| 24 | |
| 25 | # Can use any of the following: cat cmp cp diff echo egrep expr false |
| 26 | # grep install-info ln ls mkdir mv pwd rm rmdir sed sleep sort tar |
| 27 | # test touch true |
| 28 | |
| 29 | cat <<EOF >>${otmp} |
| 30 | /* GDB Notifications to Observers. |
| 31 | |
| 32 | Copyright (C) 2004-2017 Free Software Foundation, Inc. |
| 33 | |
| 34 | This file is part of GDB. |
| 35 | |
| 36 | This program is free software; you can redistribute it and/or modify |
| 37 | it under the terms of the GNU General Public License as published by |
| 38 | the Free Software Foundation; either version 3 of the License, or |
| 39 | (at your option) any later version. |
| 40 | |
| 41 | This program is distributed in the hope that it will be useful, |
| 42 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 43 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 44 | GNU General Public License for more details. |
| 45 | |
| 46 | You should have received a copy of the GNU General Public License |
| 47 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 48 | |
| 49 | -- |
| 50 | |
| 51 | This file was generated using observer.sh and observer.texi. */ |
| 52 | |
| 53 | EOF |
| 54 | |
| 55 | |
| 56 | case $lang in |
| 57 | h) cat <<EOF >>${otmp} |
| 58 | #ifndef OBSERVER_H |
| 59 | #define OBSERVER_H |
| 60 | |
| 61 | struct observer; |
| 62 | struct bpstats; |
| 63 | struct so_list; |
| 64 | struct objfile; |
| 65 | struct thread_info; |
| 66 | struct inferior; |
| 67 | struct trace_state_variable; |
| 68 | EOF |
| 69 | ;; |
| 70 | esac |
| 71 | |
| 72 | # We are about to set IFS=:, so DOS-style file names with a drive |
| 73 | # letter and a colon will be in trouble. |
| 74 | |
| 75 | if test -n "$DJGPP" |
| 76 | then |
| 77 | texi=`echo $texi | sed -e 's,^\([a-zA-Z]\):/,/dev/\1/,'` |
| 78 | fi |
| 79 | |
| 80 | # generate a list of events that can be observed |
| 81 | |
| 82 | IFS=: |
| 83 | sed -n ' |
| 84 | /@deftypefun void/{ |
| 85 | # Save original line for later processing into the actual parameter |
| 86 | h |
| 87 | # Convert from: @deftypefun void EVENT (TYPE @var{PARAM},...) |
| 88 | # to event and formals: EVENT:TYPE PARAM, ...: |
| 89 | s/^.* void \([a-z_][a-z_]*\) (\(.*\))$/\1:\2/ |
| 90 | s/@var{//g |
| 91 | s/}//g |
| 92 | # Switch to held |
| 93 | x |
| 94 | # Convert from: @deftypefun void FUNC (TYPE @var{PARAM},...) |
| 95 | # to actuals: PARAM, ... |
| 96 | s/^[^{]*[{]*// |
| 97 | s/[}]*[^}]*$// |
| 98 | s/}[^{]*{/, /g |
| 99 | # Combine held (EVENT:TYPE PARAM, ...:) and pattern (PARAM, ...) into |
| 100 | # FUNC:TYPE PARAM, ...:PARAM, ... |
| 101 | H |
| 102 | x |
| 103 | s/\n/:/g |
| 104 | p |
| 105 | } |
| 106 | ' $texi | while read event formal actual |
| 107 | do |
| 108 | case $lang in |
| 109 | h) cat <<EOF >>${otmp} |
| 110 | |
| 111 | /* ${event} notifications. */ |
| 112 | |
| 113 | typedef void (observer_${event}_ftype) (${formal}); |
| 114 | |
| 115 | extern struct observer *observer_attach_${event} (observer_${event}_ftype *f); |
| 116 | extern void observer_detach_${event} (struct observer *observer); |
| 117 | extern void observer_notify_${event} (${formal}); |
| 118 | EOF |
| 119 | ;; |
| 120 | |
| 121 | inc) |
| 122 | cat <<EOF >>${otmp} |
| 123 | |
| 124 | /* ${event} notifications. */ |
| 125 | |
| 126 | static struct observer_list *${event}_subject = NULL; |
| 127 | |
| 128 | EOF |
| 129 | if test "$formal" != "void"; then |
| 130 | cat<<EOF >>${otmp} |
| 131 | struct ${event}_args { `echo "${formal}" | sed -e 's/,/;/g'`; }; |
| 132 | |
| 133 | EOF |
| 134 | fi |
| 135 | cat <<EOF >>${otmp} |
| 136 | static void |
| 137 | observer_${event}_notification_stub (const void *data, const void *args_data) |
| 138 | { |
| 139 | observer_${event}_ftype *notify = (observer_${event}_ftype *) data; |
| 140 | EOF |
| 141 | |
| 142 | notify_args=`echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args->\1/g'` |
| 143 | |
| 144 | if test ! -z "${notify_args}"; then |
| 145 | cat<<EOF >>${otmp} |
| 146 | const struct ${event}_args *args = (const struct ${event}_args *) args_data; |
| 147 | EOF |
| 148 | fi |
| 149 | cat <<EOF >>${otmp} |
| 150 | notify (${notify_args}); |
| 151 | } |
| 152 | |
| 153 | struct observer * |
| 154 | observer_attach_${event} (observer_${event}_ftype *f) |
| 155 | { |
| 156 | return generic_observer_attach (&${event}_subject, |
| 157 | &observer_${event}_notification_stub, |
| 158 | (void *) f); |
| 159 | } |
| 160 | |
| 161 | void |
| 162 | observer_detach_${event} (struct observer *observer) |
| 163 | { |
| 164 | generic_observer_detach (&${event}_subject, observer); |
| 165 | } |
| 166 | |
| 167 | void |
| 168 | observer_notify_${event} (${formal}) |
| 169 | { |
| 170 | EOF |
| 171 | if test "$formal" != "void"; then |
| 172 | cat<<EOF >>${otmp} |
| 173 | struct ${event}_args args; |
| 174 | `echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args.\1 = \1/g'`; |
| 175 | |
| 176 | EOF |
| 177 | else |
| 178 | echo "char *args = NULL;" >> ${otmp} |
| 179 | fi |
| 180 | cat<<EOF >>${otmp} |
| 181 | if (observer_debug) |
| 182 | fprintf_unfiltered (gdb_stdlog, "observer_notify_${event}() called\n"); |
| 183 | generic_observer_notify (${event}_subject, &args); |
| 184 | } |
| 185 | EOF |
| 186 | ;; |
| 187 | esac |
| 188 | done |
| 189 | |
| 190 | |
| 191 | case $lang in |
| 192 | h) cat <<EOF >>${otmp} |
| 193 | |
| 194 | #endif /* OBSERVER_H */ |
| 195 | EOF |
| 196 | esac |
| 197 | |
| 198 | |
| 199 | echo Moving ${otmp} to ${o} |
| 200 | mv ${otmp} ${o} |