gdb/observer.sh - gdb

  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-2015 Free Software Foundation, Inc.

  27.    This file is part of GDB.

  28.    This program is free software; you can redistribute it and/or modify
  29.    it under the terms of the GNU General Public License as published by
  30.    the Free Software Foundation; either version 3 of the License, or
  31.    (at your option) any later version.

  32.    This program is distributed in the hope that it will be useful,
  33.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  34.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  35.    GNU General Public License for more details.

  36.    You should have received a copy of the GNU General Public License
  37.    along with this program.  If not, see <http://www.gnu.org/licenses/>.

  38.    --

  39.    This file was generated using observer.sh and observer.texi.  */

  40. EOF


  41. case $lang in
  42.     h) cat <<EOF >>${otmp}
  43. #ifndef OBSERVER_H
  44. #define OBSERVER_H

  45. struct observer;
  46. struct bpstats;
  47. struct so_list;
  48. struct objfile;
  49. struct thread_info;
  50. struct inferior;
  51. struct trace_state_variable;
  52. EOF
  53.         ;;
  54. esac

  55. # We are about to set IFS=:, so DOS-style file names with a drive
  56. # letter and a colon will be in trouble.

  57. if test -n "$DJGPP"
  58. then
  59.      texi=`echo $texi | sed -e 's,^\([a-zA-Z]\):/,/dev/\1/,'`
  60. fi

  61. # generate a list of events that can be observed

  62. IFS=:
  63. sed -n '
  64. /@deftypefun void/{
  65. # Save original line for later processing into the actual parameter
  66.     h
  67. # Convert from: @deftypefun void EVENT (TYPE @var{PARAM},...)
  68. # to event and formals: EVENT:TYPE PARAM, ...:
  69.     s/^.* void \([a-z_][a-z_]*\) (\(.*\))$/\1:\2/
  70.     s/@var{//g
  71.     s/}//g
  72. # Switch to held
  73.     x
  74. # Convert from: @deftypefun void FUNC (TYPE @var{PARAM},...)
  75. # to actuals: PARAM, ...
  76.     s/^[^{]*[{]*//
  77.     s/[}]*[^}]*$//
  78.     s/}[^{]*{/, /g
  79. # Combine held (EVENT:TYPE PARAM, ...:) and pattern (PARAM, ...) into
  80. # FUNC:TYPE PARAM, ...:PARAM, ...
  81.     H
  82.     x
  83.     s/\n/:/g
  84.     p
  85. }
  86. ' $texi | while read event formal actual
  87. do
  88.   case $lang in
  89.       h) cat <<EOF >>${otmp}

  90. /* ${event} notifications.  */

  91. typedef void (observer_${event}_ftype) (${formal});

  92. extern struct observer *observer_attach_${event} (observer_${event}_ftype *f);
  93. extern void observer_detach_${event} (struct observer *observer);
  94. extern void observer_notify_${event} (${formal});
  95. EOF
  96.         ;;

  97.       inc)
  98.               cat <<EOF >>${otmp}

  99. /* ${event} notifications.  */

  100. static struct observer_list *${event}_subject = NULL;

  101. EOF
  102.         if test "$formal" != "void"; then
  103.             cat<<EOF >>${otmp}
  104. struct ${event}_args { `echo "${formal}" | sed -e 's/,/;/g'`; };

  105. EOF
  106.         fi
  107.         cat <<EOF >>${otmp}
  108. static void
  109. observer_${event}_notification_stub (const void *data, const void *args_data)
  110. {
  111.   observer_${event}_ftype *notify = (observer_${event}_ftype *) data;
  112. EOF

  113.         notify_args=`echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args->\1/g'`

  114.         if test ! -z "${notify_args}"; then
  115.             cat<<EOF >>${otmp}
  116.   const struct ${event}_args *args = args_data;
  117. EOF
  118.         fi
  119.         cat <<EOF >>${otmp}
  120.   notify (${notify_args});
  121. }

  122. struct observer *
  123. observer_attach_${event} (observer_${event}_ftype *f)
  124. {
  125.   return generic_observer_attach (&${event}_subject,
  126.                                   &observer_${event}_notification_stub,
  127.                                   (void *) f);
  128. }

  129. void
  130. observer_detach_${event} (struct observer *observer)
  131. {
  132.   generic_observer_detach (&${event}_subject, observer);
  133. }

  134. void
  135. observer_notify_${event} (${formal})
  136. {
  137. EOF
  138.         if test "$formal" != "void"; then
  139.             cat<<EOF >>${otmp}
  140.   struct ${event}_args args;
  141.   `echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args.\1 = \1/g'`;

  142. EOF
  143.         else
  144.             echo "char *args = NULL;" >> ${otmp}
  145.         fi
  146.         cat<<EOF >>${otmp}
  147.   if (observer_debug)
  148.     fprintf_unfiltered (gdb_stdlog, "observer_notify_${event}() called\n");
  149.   generic_observer_notify (${event}_subject, &args);
  150. }
  151. EOF
  152.         ;;
  153.     esac
  154. done


  155. case $lang in
  156.     h) cat <<EOF >>${otmp}

  157. #endif /* OBSERVER_H */
  158. EOF
  159. esac


  160. echo Moving ${otmp} to ${o}
  161. mv ${otmp} ${o}