/gdb/observer.sh

https://github.com/rofl0r/gdb · Shell · 190 lines · 141 code · 37 blank · 12 comment · 9 complexity · 86a0e9cf42e63f410d19f71fdeda7eaa MD5 · raw file

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