* [patch/rfc] Generate observer.[hc]
@ 2004-04-08 21:09 Andrew Cagney
2004-04-08 22:29 ` Daniel Jacobowitz
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Andrew Cagney @ 2004-04-08 21:09 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 445 bytes --]
Hello,
The attached adds the script observer.sh that can be used to generate:
observer.h
observer.ch (#included by observer.c)
aat build time using doc/observer.texi as the input.
While this is more ambitious than gdbarch.* (which are explicitly
generated and then committed to CVS) I suspect it is prefered.
Comments?
Once this is in I can add a few observers, and start deleting all those
hooks and events.
Andrew
(only a year late)
[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 10616 bytes --]
2004-04-08 Andrew Cagney <cagney@redhat.com>
* observer.c (normal_stop_subject, observer_notify_normal_stop)
(observer_normal_stop_notification_stub)
(observer_attach_normal_stop, observer_detach_normal_stop):
Delete, replaced by #include "observer.ch".
* infrun.c (normal_stop): Pass "stop_bpstat" to
observer_notify_normal_stop.
* Makefile.in (observer_ch): Define.
(observer.o): Update dependencies.
(observer.h, observer.ch): New rules.
* observer.h: Delete file.
* observer.sh: New file.
Index: doc/ChangeLog
2004-04-08 Andrew Cagney <cagney@redhat.com>
* observer.texi (GDB Observers): Rework, provide generic observer
definitions and then a list of observable events.
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.534
diff -u -r1.534 Makefile.in
--- Makefile.in 7 Apr 2004 00:04:28 -0000 1.534
+++ Makefile.in 8 Apr 2004 20:49:30 -0000
@@ -587,6 +587,7 @@
gdb_sim_frv_h = $(INCLUDE_DIR)/gdb/sim-frv.h
gdb_sim_sh_h = $(INCLUDE_DIR)/gdb/sim-sh.h
splay_tree_h = $(INCLUDE_DIR)/splay-tree.h
+observer_ch = observer.ch
#
# $BUILD/ headers
@@ -1281,6 +1282,15 @@
mv version.c-tmp version.c
version.o: version.c $(version_h)
+observer.h: observer.sh doc/observer.texi
+ rm -f observer.h-tmp
+ ${srcdir}/observer.sh h ${srcdir}/doc/observer.texi > observer.h-tmp
+ mv observer.h-tmp observer.h
+
+observer.ch: observer.sh doc/observer.texi
+ rm -f observer.ch-tmp
+ ${srcdir}/observer.sh c ${srcdir}/doc/observer.texi > observer.ch-tmp
+ mv observer.ch-tmp observer.ch
lint: $(LINTFILES)
$(LINT) $(INCLUDE_CFLAGS) $(LINTFLAGS) $(LINTFILES) \
@@ -2109,7 +2119,7 @@
$(objfiles_h) $(gdb_stabs_h) $(target_h) $(bcache_h) $(gdb_assert_h) \
$(gdb_stat_h) $(gdb_obstack_h) $(gdb_string_h) $(hashtab_h) \
$(breakpoint_h) $(block_h) $(dictionary_h)
-observer.o: observer.c $(defs_h) $(observer_h)
+observer.o: observer.c $(defs_h) $(observer_h) $(observer_ch)
ocd.o: ocd.c $(defs_h) $(gdbcore_h) $(gdb_string_h) $(frame_h) $(inferior_h) \
$(bfd_h) $(symfile_h) $(target_h) $(gdbcmd_h) $(objfiles_h) \
$(gdb_stabs_h) $(serial_h) $(ocd_h) $(regcache_h)
Index: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.145
diff -u -r1.145 infrun.c
--- infrun.c 2 Apr 2004 22:38:43 -0000 1.145
+++ infrun.c 8 Apr 2004 20:49:31 -0000
@@ -3276,7 +3276,7 @@
done:
annotate_stopped ();
- observer_notify_normal_stop ();
+ observer_notify_normal_stop (stop_bpstat);
}
static int
Index: observer.c
===================================================================
RCS file: /cvs/src/src/gdb/observer.c,v
retrieving revision 1.4
diff -u -r1.4 observer.c
--- observer.c 12 Dec 2003 16:14:26 -0000 1.4
+++ observer.c 8 Apr 2004 20:49:31 -0000
@@ -159,37 +159,6 @@
}
}
-/* normal_stop notifications. */
-
-static struct observer_list *normal_stop_subject = NULL;
-
-static void
-observer_normal_stop_notification_stub (const void *data,
- const void *unused_args)
-{
- observer_normal_stop_ftype *notify = (observer_normal_stop_ftype *) data;
- (*notify) ();
-}
-
-struct observer *
-observer_attach_normal_stop (observer_normal_stop_ftype *f)
-{
- return generic_observer_attach (&normal_stop_subject,
- &observer_normal_stop_notification_stub,
- (void *) f);
-}
-
-void
-observer_detach_normal_stop (struct observer *observer)
-{
- generic_observer_detach (&normal_stop_subject, observer);
-}
-
-void
-observer_notify_normal_stop (void)
-{
- generic_observer_notify (normal_stop_subject, NULL);
-}
/* The following code is only used to unit-test the observers from our
testsuite. DO NOT USE IT within observer.c (or anywhere else for
@@ -220,3 +189,4 @@
observer_test_third_observer++;
}
+#include "observer.ch"
Index: observer.h
===================================================================
RCS file: observer.h
diff -N observer.h
--- observer.h 28 Feb 2003 07:08:51 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,35 +0,0 @@
-/* GDB Notifications to Observers.
- Copyright 2003 Free Software Foundation, Inc.
-
- This file is part of GDB.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#ifndef OBSERVER_H
-#define OBSERVER_H
-
-struct observer;
-
-/* normal_stop notifications. */
-
-typedef void (observer_normal_stop_ftype) (void);
-
-extern struct observer *
- observer_attach_normal_stop (observer_normal_stop_ftype *f);
-extern void observer_detach_normal_stop (struct observer *observer);
-extern void observer_notify_normal_stop (void);
-
-#endif /* OBSERVER_H */
Index: observer.sh
===================================================================
RCS file: observer.sh
diff -N observer.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ observer.sh 8 Apr 2004 20:49:31 -0000
@@ -0,0 +1,142 @@
+#!/bin/sh
+
+if test $# -ne 2
+then
+ echo "Usage: $0 [h|c] observer.texi" 1>&2
+ exit 0
+fi
+
+lang=$1 ; shift
+texi=$1 ; shift
+
+# cat cmp cp diff echo egrep expr false grep install-info ln ls mkdir
+# mv pwd rm rmdir sed sleep sort tar test touch true
+
+cat <<EOF
+/* GDB Notifications to Observers.
+
+ Copyright 2004 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ --
+
+ This file was generated using observer.sh and observer.texi. */
+
+EOF
+
+
+case $lang in
+ h) cat <<EOF
+#ifndef OBSERVER_H
+#define OBSERVER_H
+
+struct observer;
+struct bpstats;
+EOF
+ ;;
+esac
+
+
+# generate a list of events that can be observed
+
+IFS=:
+sed -n '
+/@deftypefun void/{
+ # Save original line for actual param list
+ h
+ # event:formal:
+ s/^.* void \([a-z_][a-z_]*\) (\(.*\))$/\1:\2/
+ s/@var{//g
+ s/}//g
+ # Get saved line and create actual
+ x
+ s/^[^{]*[{]*//
+ s/[}]*[^}]*$//
+ s/}[^{]*{/, /g
+ # combine and print
+ H
+ x
+ s/\n/:/g
+ p
+}
+' $texi | while read event formal actual
+do
+ case $lang in
+ h) cat <<EOF
+
+/* ${event} notifications. */
+
+typedef void (observer_${event}_ftype) (${formal});
+
+extern struct observer *observer_attach_${event} (observer_${event}_ftype *f);
+extern void observer_detach_${event} (struct observer *observer);
+extern void observer_notify_${event} (${formal});
+EOF
+ ;;
+
+ c)
+ cat <<EOF
+
+/* ${event} notifications. */
+
+static struct observer_list *${event}_subject = NULL;
+
+struct ${event}_args { `echo "${formal}" | sed -e 's/,/;/g'`; };
+
+static void
+observer_${event}_notification_stub (const void *data, const void *args_data)
+{
+ observer_${event}_ftype *notify = (observer_${event}_ftype *) data;
+ const struct ${event}_args *args = args_data;
+ notify (`echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args->\1/g'`);
+}
+
+struct observer *
+observer_attach_${event} (observer_${event}_ftype *f)
+{
+ return generic_observer_attach (&${event}_subject,
+ &observer_${event}_notification_stub,
+ (void *) f);
+}
+
+void
+observer_detach_${event} (struct observer *observer)
+{
+ generic_observer_detach (&${event}_subject, observer);
+}
+
+void
+observer_notify_${event} (${formal})
+{
+ struct ${event}_args args;
+ `echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args.\1 = \1/g'`;
+ generic_observer_notify (${event}_subject, &args);
+}
+EOF
+ ;;
+ esac
+done
+
+
+case $lang in
+ h) cat <<EOF
+
+#endif /* OBSERVER_H */
+EOF
+esac
Index: doc/observer.texi
===================================================================
RCS file: /cvs/src/src/gdb/doc/observer.texi,v
retrieving revision 1.2
diff -u -r1.2 observer.texi
--- doc/observer.texi 3 Apr 2003 15:14:48 -0000 1.2
+++ doc/observer.texi 8 Apr 2004 20:49:31 -0000
@@ -50,21 +50,26 @@
commands list, the commands are executed after the notification
is emitted.
-The following interface is available to manage @code{normal_stop}
-observers:
+The following interfaces are available to manage observers:
-@deftypefun extern struct observer *observer_attach_normal_stop (observer_normal_stop_ftype *@var{f})
-Attach the given @code{normal_stop} callback function @var{f} and
-return the associated observer.
+@deftypefun extern struct observer *observer_attach_@var{event} (observer_@var{event}_ftype *@var{f})
+Using the function @var{f}, create an observer that is notified when
+ever @var{event} occures, return the observer.
@end deftypefun
-@deftypefun extern void observer_detach_normal_stop (struct observer *@var{observer});
+@deftypefun extern void observer_detach_@var{event} (struct observer *@var{observer});
Remove @var{observer} from the list of observers to be notified when
-a @code{normal_stop} event occurs.
+@var{event} occurs.
@end deftypefun
-@deftypefun extern void observer_notify_normal_stop (void);
-Send a notification to all @code{normal_stop} observers.
+@deftypefun extern void observer_notify_@var{event} (void);
+Send a notification to all @var{event} observers.
@end deftypefun
+The following observable events are defined:
+@c note: all events must take at least one parameter.
+
+@deftypefun void normal_stop (struct bpstats *@var{bs})
+The inferior has stopped for real.
+@end deftypefun
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [patch/rfc] Generate observer.[hc]
2004-04-08 21:09 [patch/rfc] Generate observer.[hc] Andrew Cagney
@ 2004-04-08 22:29 ` Daniel Jacobowitz
2004-04-08 22:40 ` Andrew Cagney
2004-04-15 11:57 ` Eli Zaretskii
2004-04-15 14:32 ` Andrew Cagney
2 siblings, 1 reply; 11+ messages in thread
From: Daniel Jacobowitz @ 2004-04-08 22:29 UTC (permalink / raw)
To: Andrew Cagney; +Cc: gdb-patches
On Thu, Apr 08, 2004 at 05:09:34PM -0400, Andrew Cagney wrote:
> Hello,
>
> The attached adds the script observer.sh that can be used to generate:
> observer.h
> observer.ch (#included by observer.c)
> aat build time using doc/observer.texi as the input.
>
> While this is more ambitious than gdbarch.* (which are explicitly
> generated and then committed to CVS) I suspect it is prefered.
>
> Comments?
>
> Once this is in I can add a few observers, and start deleting all those
> hooks and events.
I like it, and the patch looks fine to me. My only complaint is that I
don't much like the .ch suffix. But then, using .c is probably pretty
confusing too, so I don't have a better idea - I won't complain.
> -@deftypefun extern struct observer *observer_attach_normal_stop (observer_normal_stop_ftype *@var{f})
Also, my instinct when reading this manual would be to just remove
these obsolete "extern"s. Which would break the script, since it would
try to generate an event for observer_detach_@var{event}. So I think
that either that should be fixed or there should be a comment somewhere
to leave them in.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [patch/rfc] Generate observer.[hc]
2004-04-08 22:29 ` Daniel Jacobowitz
@ 2004-04-08 22:40 ` Andrew Cagney
2004-04-08 22:44 ` David Carlton
2004-04-08 22:45 ` Daniel Jacobowitz
0 siblings, 2 replies; 11+ messages in thread
From: Andrew Cagney @ 2004-04-08 22:40 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
> On Thu, Apr 08, 2004 at 05:09:34PM -0400, Andrew Cagney wrote:
>
>>> Hello,
>>>
>>> The attached adds the script observer.sh that can be used to generate:
>>> observer.h
>>> observer.ch (#included by observer.c)
>>> aat build time using doc/observer.texi as the input.
>>>
>>> While this is more ambitious than gdbarch.* (which are explicitly
>>> generated and then committed to CVS) I suspect it is prefered.
>>>
>>> Comments?
>>>
>>> Once this is in I can add a few observers, and start deleting all those
>>> hooks and events.
>
>
> I like it, and the patch looks fine to me. My only complaint is that I
> don't much like the .ch suffix. But then, using .c is probably pretty
> confusing too, so I don't have a better idea - I won't complain.
So far I've been through .hh .cc .hc .ch ....
>>> -@deftypefun extern struct observer *observer_attach_normal_stop (observer_normal_stop_ftype *@var{f})
>
>
> Also, my instinct when reading this manual would be to just remove
> these obsolete "extern"s. Which would break the script, since it would
> try to generate an event for observer_detach_@var{event}. So I think
> that either that should be fixed or there should be a comment somewhere
> to leave them in.
Oops, thats the wrong example, try:
+@deftypefun void normal_stop (struct bpstats *@var{bs})
(yes the externs can go)
Andrew
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [patch/rfc] Generate observer.[hc]
2004-04-08 22:40 ` Andrew Cagney
@ 2004-04-08 22:44 ` David Carlton
2004-04-08 22:45 ` Daniel Jacobowitz
1 sibling, 0 replies; 11+ messages in thread
From: David Carlton @ 2004-04-08 22:44 UTC (permalink / raw)
To: Andrew Cagney; +Cc: Daniel Jacobowitz, gdb-patches
On Thu, 08 Apr 2004 18:40:25 -0400, Andrew Cagney <cagney@gnu.org> said:
>> My only complaint is that I don't much like the .ch suffix. But
>> then, using .c is probably pretty confusing too, so I don't have a
>> better idea - I won't complain.
> So far I've been through .hh .cc .hc .ch ....
.in?
David Carlton
carlton@kealia.com
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch/rfc] Generate observer.[hc]
2004-04-08 22:40 ` Andrew Cagney
2004-04-08 22:44 ` David Carlton
@ 2004-04-08 22:45 ` Daniel Jacobowitz
1 sibling, 0 replies; 11+ messages in thread
From: Daniel Jacobowitz @ 2004-04-08 22:45 UTC (permalink / raw)
To: Andrew Cagney; +Cc: gdb-patches
On Thu, Apr 08, 2004 at 06:40:25PM -0400, Andrew Cagney wrote:
> >On Thu, Apr 08, 2004 at 05:09:34PM -0400, Andrew Cagney wrote:
> >
> >>>Hello,
> >>>
> >>>The attached adds the script observer.sh that can be used to generate:
> >>> observer.h
> >>> observer.ch (#included by observer.c)
> >>>aat build time using doc/observer.texi as the input.
> >>>
> >>>While this is more ambitious than gdbarch.* (which are explicitly
> >>>generated and then committed to CVS) I suspect it is prefered.
> >>>
> >>>Comments?
> >>>
> >>>Once this is in I can add a few observers, and start deleting all those
> >>>hooks and events.
> >
> >
> >I like it, and the patch looks fine to me. My only complaint is that I
> >don't much like the .ch suffix. But then, using .c is probably pretty
> >confusing too, so I don't have a better idea - I won't complain.
>
> So far I've been through .hh .cc .hc .ch ....
GCC uses .inc for this. Is that any better?
> >>>-@deftypefun extern struct observer *observer_attach_normal_stop
> >>>(observer_normal_stop_ftype *@var{f})
> >
> >
> >Also, my instinct when reading this manual would be to just remove
> >these obsolete "extern"s. Which would break the script, since it would
> >try to generate an event for observer_detach_@var{event}. So I think
> >that either that should be fixed or there should be a comment somewhere
> >to leave them in.
>
> Oops, thats the wrong example, try:
>
> +@deftypefun void normal_stop (struct bpstats *@var{bs})
>
> (yes the externs can go)
My point was that the script generated an observer for every
"@deftypefun void". So it would try to generate one for the literal
string "observer_detach_@var{event}". Of course, I pasted in the wrong
line in my message, so my complaint probably didn't make sense. I
meant to quote:
+@deftypefun extern void observer_detach_@var{event} (struct observer *@var{observer});
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch/rfc] Generate observer.[hc]
2004-04-08 21:09 [patch/rfc] Generate observer.[hc] Andrew Cagney
2004-04-08 22:29 ` Daniel Jacobowitz
@ 2004-04-15 11:57 ` Eli Zaretskii
2004-04-15 14:45 ` Andrew Cagney
2004-04-15 14:32 ` Andrew Cagney
2 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2004-04-15 11:57 UTC (permalink / raw)
To: Andrew Cagney; +Cc: gdb-patches
> Date: Thu, 08 Apr 2004 17:09:34 -0400
> From: Andrew Cagney <cagney@gnu.org>
>
> The attached adds the script observer.sh that can be used to generate:
> observer.h
> observer.ch (#included by observer.c)
> at build time using doc/observer.texi as the input.
Sorry for the long delay.
The patch for observer.texi is approved, but let me play the Devil's
advocate and ask what significant wins we gain from generating the
source files from the Texinfo file, that justify maintaining the
scripts which are required to support this machinery?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch/rfc] Generate observer.[hc]
2004-04-15 11:57 ` Eli Zaretskii
@ 2004-04-15 14:45 ` Andrew Cagney
2004-04-16 6:59 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Andrew Cagney @ 2004-04-15 14:45 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
>>> Date: Thu, 08 Apr 2004 17:09:34 -0400
>>> From: Andrew Cagney <cagney@gnu.org>
>>>
>>> The attached adds the script observer.sh that can be used to generate:
>>> observer.h
>>> observer.ch (#included by observer.c)
>>> at build time using doc/observer.texi as the input.
>
>
> Sorry for the long delay.
>
> The patch for observer.texi is approved, but let me play the Devil's
> advocate and ask what significant wins we gain from generating the
> source files from the Texinfo file, that justify maintaining the
> scripts which are required to support this machinery?
We first establish a one-stop shop for adding observers, and second
eliminate the drudgery of churning out the C code needed to implement
each observer. (At a guess, we're going to end up with something
between 10 and 20 observers).
Andrew
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch/rfc] Generate observer.[hc]
2004-04-15 14:45 ` Andrew Cagney
@ 2004-04-16 6:59 ` Eli Zaretskii
2004-04-16 18:56 ` Andrew Cagney
0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2004-04-16 6:59 UTC (permalink / raw)
To: Andrew Cagney; +Cc: gdb-patches
> Date: Thu, 15 Apr 2004 10:45:02 -0400
> From: Andrew Cagney <cagney@gnu.org>
> >
> > let me play the Devil's
> > advocate and ask what significant wins we gain from generating the
> > source files from the Texinfo file, that justify maintaining the
> > scripts which are required to support this machinery?
>
> We first establish a one-stop shop for adding observers, and second
> eliminate the drudgery of churning out the C code needed to implement
> each observer.
That much is understood, but I still have a difficulty to see how
inventing an elaborate machinery for churning C code out of Texinfo
(which is hardly a trivial Sed'ery) is justified by the benefits you
mentioned. I thought perhaps there were other, subtler, benefits
which I didn't see. Are there?
> (At a guess, we're going to end up with something between 10 and 20
> observers).
So what, we will have all of them in the docs?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch/rfc] Generate observer.[hc]
2004-04-16 6:59 ` Eli Zaretskii
@ 2004-04-16 18:56 ` Andrew Cagney
2004-04-17 7:44 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Andrew Cagney @ 2004-04-16 18:56 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
>>Date: Thu, 15 Apr 2004 10:45:02 -0400
>>> From: Andrew Cagney <cagney@gnu.org>
>>
>>>> >
>>>> > let me play the Devil's
>>>> > advocate and ask what significant wins we gain from generating the
>>>> > source files from the Texinfo file, that justify maintaining the
>>>> > scripts which are required to support this machinery?
>>
>>>
>>> We first establish a one-stop shop for adding observers, and second
>>> eliminate the drudgery of churning out the C code needed to implement
>>> each observer.
>
>
> That much is understood, but I still have a difficulty to see how
> inventing an elaborate machinery for churning C code out of Texinfo
> (which is hardly a trivial Sed'ery) is justified by the benefits you
> mentioned. I thought perhaps there were other, subtler, benefits
> which I didn't see. Are there?
This machinery isn't that elaborate. For an example of that look at
gdbarch.sh which desperatly needs to be dumbed down :-/
>>> (At a guess, we're going to end up with something between 10 and 20
>>> observers).
>
>
> So what, we will have all of them in the docs?
Given the choice between duplicating/triplicating the event code, had a
single list and generator, I'll take the latter.
Here's the original proposal as it relates to gdbarch.sh:
http://sources.redhat.com/ml/gdb-patches/2003-02/msg00384.html
when the observer was original posted it discussed doing something
similar as a good thing.
(yes I've reversed the order so that the observer is the prototype, like
I said gdbarch.sh needs to be greatly simplified).
Andrew
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch/rfc] Generate observer.[hc]
2004-04-16 18:56 ` Andrew Cagney
@ 2004-04-17 7:44 ` Eli Zaretskii
0 siblings, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2004-04-17 7:44 UTC (permalink / raw)
To: Andrew Cagney; +Cc: gdb-patches
> Date: Fri, 16 Apr 2004 14:55:57 -0400
> From: Andrew Cagney <cagney@gnu.org>
> >
> > That much is understood, but I still have a difficulty to see how
> > inventing an elaborate machinery for churning C code out of Texinfo
> > (which is hardly a trivial Sed'ery) is justified by the benefits you
> > mentioned. I thought perhaps there were other, subtler, benefits
> > which I didn't see. Are there?
>
> This machinery isn't that elaborate.
As the build failure just reported by Joel demonstrates, it is going
to be... ;-)
> Here's the original proposal as it relates to gdbarch.sh:
> http://sources.redhat.com/ml/gdb-patches/2003-02/msg00384.html
The target architecture vector is a much mode complex creature than
observers. So, while the logic is similar, the conclusions might
well be different.
Anyway, if I'm the only one who thinks producing observer.* from the
docs might be an overkill, I don't want to go on arguing. I just
thought I should bring this to people's attention.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [patch/rfc] Generate observer.[hc]
2004-04-08 21:09 [patch/rfc] Generate observer.[hc] Andrew Cagney
2004-04-08 22:29 ` Daniel Jacobowitz
2004-04-15 11:57 ` Eli Zaretskii
@ 2004-04-15 14:32 ` Andrew Cagney
2 siblings, 0 replies; 11+ messages in thread
From: Andrew Cagney @ 2004-04-15 14:32 UTC (permalink / raw)
To: Andrew Cagney; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 316 bytes --]
Here's what I've actually committed. The tweaks from the original are:
- ".inc" rather than ".ch"
- more comments in observer.sh
it attempts to explain what the sed is doing (but not how :-)
- observer.sh is run with "sh -e"
- observer.sh, and not Makefile.in, is responsible for installing the
new files
Andrew
[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 11025 bytes --]
2004-04-15 Andrew Cagney <cagney@redhat.com>
* observer.c (normal_stop_subject, observer_notify_normal_stop)
(observer_normal_stop_notification_stub)
(observer_attach_normal_stop, observer_detach_normal_stop):
Delete, replaced by #include "observer.inc".
* infrun.c (normal_stop): Pass "stop_bpstat" to
observer_notify_normal_stop.
* Makefile.in (observer_inc): Define.
(observer.o): Update dependencies.
(observer.h, observer.inc): New rules.
* observer.h: Delete file.
* observer.sh: New file.
Index: doc/ChangeLog
2004-04-08 Andrew Cagney <cagney@redhat.com>
* observer.texi (GDB Observers): Rework, provide generic observer
definitions and then a list of observable events.
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.540
diff -u -r1.540 Makefile.in
--- Makefile.in 14 Apr 2004 18:02:43 -0000 1.540
+++ Makefile.in 15 Apr 2004 14:27:18 -0000
@@ -587,6 +587,7 @@
gdb_sim_frv_h = $(INCLUDE_DIR)/gdb/sim-frv.h
gdb_sim_sh_h = $(INCLUDE_DIR)/gdb/sim-sh.h
splay_tree_h = $(INCLUDE_DIR)/splay-tree.h
+observer_inc = observer.inc
#
# $BUILD/ headers
@@ -1281,6 +1282,11 @@
mv version.c-tmp version.c
version.o: version.c $(version_h)
+observer.h: observer.sh doc/observer.texi
+ ${srcdir}/observer.sh h ${srcdir}/doc/observer.texi observer.h
+
+observer.inc: observer.sh doc/observer.texi
+ ${srcdir}/observer.sh inc ${srcdir}/doc/observer.texi observer.inc
lint: $(LINTFILES)
$(LINT) $(INCLUDE_CFLAGS) $(LINTFLAGS) $(LINTFILES) \
@@ -2112,7 +2118,7 @@
$(objfiles_h) $(gdb_stabs_h) $(target_h) $(bcache_h) $(gdb_assert_h) \
$(gdb_stat_h) $(gdb_obstack_h) $(gdb_string_h) $(hashtab_h) \
$(breakpoint_h) $(block_h) $(dictionary_h)
-observer.o: observer.c $(defs_h) $(observer_h)
+observer.o: observer.c $(defs_h) $(observer_h) $(observer_inc)
ocd.o: ocd.c $(defs_h) $(gdbcore_h) $(gdb_string_h) $(frame_h) $(inferior_h) \
$(bfd_h) $(symfile_h) $(target_h) $(gdbcmd_h) $(objfiles_h) \
$(gdb_stabs_h) $(serial_h) $(ocd_h) $(regcache_h)
Index: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.145
diff -u -r1.145 infrun.c
--- infrun.c 2 Apr 2004 22:38:43 -0000 1.145
+++ infrun.c 15 Apr 2004 14:27:19 -0000
@@ -3276,7 +3276,7 @@
done:
annotate_stopped ();
- observer_notify_normal_stop ();
+ observer_notify_normal_stop (stop_bpstat);
}
static int
Index: observer.c
===================================================================
RCS file: /cvs/src/src/gdb/observer.c,v
retrieving revision 1.4
diff -u -r1.4 observer.c
--- observer.c 12 Dec 2003 16:14:26 -0000 1.4
+++ observer.c 15 Apr 2004 14:27:19 -0000
@@ -159,37 +159,6 @@
}
}
-/* normal_stop notifications. */
-
-static struct observer_list *normal_stop_subject = NULL;
-
-static void
-observer_normal_stop_notification_stub (const void *data,
- const void *unused_args)
-{
- observer_normal_stop_ftype *notify = (observer_normal_stop_ftype *) data;
- (*notify) ();
-}
-
-struct observer *
-observer_attach_normal_stop (observer_normal_stop_ftype *f)
-{
- return generic_observer_attach (&normal_stop_subject,
- &observer_normal_stop_notification_stub,
- (void *) f);
-}
-
-void
-observer_detach_normal_stop (struct observer *observer)
-{
- generic_observer_detach (&normal_stop_subject, observer);
-}
-
-void
-observer_notify_normal_stop (void)
-{
- generic_observer_notify (normal_stop_subject, NULL);
-}
/* The following code is only used to unit-test the observers from our
testsuite. DO NOT USE IT within observer.c (or anywhere else for
@@ -220,3 +189,4 @@
observer_test_third_observer++;
}
+#include "observer.inc"
Index: observer.h
===================================================================
RCS file: observer.h
diff -N observer.h
--- observer.h 28 Feb 2003 07:08:51 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,35 +0,0 @@
-/* GDB Notifications to Observers.
- Copyright 2003 Free Software Foundation, Inc.
-
- This file is part of GDB.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#ifndef OBSERVER_H
-#define OBSERVER_H
-
-struct observer;
-
-/* normal_stop notifications. */
-
-typedef void (observer_normal_stop_ftype) (void);
-
-extern struct observer *
- observer_attach_normal_stop (observer_normal_stop_ftype *f);
-extern void observer_detach_normal_stop (struct observer *observer);
-extern void observer_notify_normal_stop (void);
-
-#endif /* OBSERVER_H */
Index: observer.sh
===================================================================
RCS file: observer.sh
diff -N observer.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ observer.sh 15 Apr 2004 14:27:19 -0000
@@ -0,0 +1,154 @@
+#!/bin/sh -e
+
+if test $# -ne 3
+then
+ echo "Usage: $0 <h|inc> <observer.texi> <observer.out>" 1>&2
+ exit 0
+fi
+
+lang=$1 ; shift
+texi=$1 ; shift
+o=$1 ; shift
+echo "Creating ${o}-tmp" 1>&2
+rm -f ${o}-tmp
+
+# Can use any of the following: cat cmp cp diff echo egrep expr false
+# grep install-info ln ls mkdir mv pwd rm rmdir sed sleep sort tar
+# test touch true
+
+cat <<EOF >>${o}-tmp
+/* GDB Notifications to Observers.
+
+ Copyright 2004 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ --
+
+ This file was generated using observer.sh and observer.texi. */
+
+EOF
+
+
+case $lang in
+ h) cat <<EOF >>${o}-tmp
+#ifndef OBSERVER_H
+#define OBSERVER_H
+
+struct observer;
+struct bpstats;
+EOF
+ ;;
+esac
+
+
+# generate a list of events that can be observed
+
+IFS=:
+sed -n '
+/@deftypefun void/{
+ # Save original line for later processing into the actual parameter
+ h
+ # Convert from: @deftypefun void EVENT (TYPE @var{PARAM},...)
+ # to event and formals: EVENT:TYPE PARAM, ...:
+ s/^.* void \([a-z_][a-z_]*\) (\(.*\))$/\1:\2/
+ s/@var{//g
+ s/}//g
+ # Switch to held
+ x
+ # Convert from: @deftypefun void FUNC (TYPE @var{PARAM},...)
+ # to actuals: PARAM, ...
+ s/^[^{]*[{]*//
+ s/[}]*[^}]*$//
+ s/}[^{]*{/, /g
+ # Combine held (EVENT:TYPE PARAM, ...:) and pattern (PARAM, ...) into
+ # FUNC:TYPE PARAM, ...:PARAM, ...
+ H
+ x
+ s/\n/:/g
+ p
+}
+' $texi | while read event formal actual
+do
+ case $lang in
+ h) cat <<EOF >>${o}-tmp
+
+/* ${event} notifications. */
+
+typedef void (observer_${event}_ftype) (${formal});
+
+extern struct observer *observer_attach_${event} (observer_${event}_ftype *f);
+extern void observer_detach_${event} (struct observer *observer);
+extern void observer_notify_${event} (${formal});
+EOF
+ ;;
+
+ inc)
+ cat <<EOF >>${o}-tmp
+
+/* ${event} notifications. */
+
+static struct observer_list *${event}_subject = NULL;
+
+struct ${event}_args { `echo "${formal}" | sed -e 's/,/;/g'`; };
+
+static void
+observer_${event}_notification_stub (const void *data, const void *args_data)
+{
+ observer_${event}_ftype *notify = (observer_${event}_ftype *) data;
+ const struct ${event}_args *args = args_data;
+ notify (`echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args->\1/g'`);
+}
+
+struct observer *
+observer_attach_${event} (observer_${event}_ftype *f)
+{
+ return generic_observer_attach (&${event}_subject,
+ &observer_${event}_notification_stub,
+ (void *) f);
+}
+
+void
+observer_detach_${event} (struct observer *observer)
+{
+ generic_observer_detach (&${event}_subject, observer);
+}
+
+void
+observer_notify_${event} (${formal})
+{
+ struct ${event}_args args;
+ `echo ${actual} | sed -e 's/\([a-z0-9_][a-z0-9_]*\)/args.\1 = \1/g'`;
+ generic_observer_notify (${event}_subject, &args);
+}
+EOF
+ ;;
+ esac
+done
+
+
+case $lang in
+ h) cat <<EOF >>${o}-tmp
+
+#endif /* OBSERVER_H */
+EOF
+esac
+
+
+echo Moving ${o}-tmp to ${o}
+mv ${o}-tmp ${o}
Index: doc/observer.texi
===================================================================
RCS file: /cvs/src/src/gdb/doc/observer.texi,v
retrieving revision 1.2
diff -u -r1.2 observer.texi
--- doc/observer.texi 3 Apr 2003 15:14:48 -0000 1.2
+++ doc/observer.texi 15 Apr 2004 14:27:22 -0000
@@ -50,21 +50,26 @@
commands list, the commands are executed after the notification
is emitted.
-The following interface is available to manage @code{normal_stop}
-observers:
+The following interfaces are available to manage observers:
-@deftypefun extern struct observer *observer_attach_normal_stop (observer_normal_stop_ftype *@var{f})
-Attach the given @code{normal_stop} callback function @var{f} and
-return the associated observer.
+@deftypefun extern struct observer *observer_attach_@var{event} (observer_@var{event}_ftype *@var{f})
+Using the function @var{f}, create an observer that is notified when
+ever @var{event} occures, return the observer.
@end deftypefun
-@deftypefun extern void observer_detach_normal_stop (struct observer *@var{observer});
+@deftypefun extern void observer_detach_@var{event} (struct observer *@var{observer});
Remove @var{observer} from the list of observers to be notified when
-a @code{normal_stop} event occurs.
+@var{event} occurs.
@end deftypefun
-@deftypefun extern void observer_notify_normal_stop (void);
-Send a notification to all @code{normal_stop} observers.
+@deftypefun extern void observer_notify_@var{event} (void);
+Send a notification to all @var{event} observers.
@end deftypefun
+The following observable events are defined:
+@c note: all events must take at least one parameter.
+
+@deftypefun void normal_stop (struct bpstats *@var{bs})
+The inferior has stopped for real.
+@end deftypefun
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2004-04-17 7:44 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-08 21:09 [patch/rfc] Generate observer.[hc] Andrew Cagney
2004-04-08 22:29 ` Daniel Jacobowitz
2004-04-08 22:40 ` Andrew Cagney
2004-04-08 22:44 ` David Carlton
2004-04-08 22:45 ` Daniel Jacobowitz
2004-04-15 11:57 ` Eli Zaretskii
2004-04-15 14:45 ` Andrew Cagney
2004-04-16 6:59 ` Eli Zaretskii
2004-04-16 18:56 ` Andrew Cagney
2004-04-17 7:44 ` Eli Zaretskii
2004-04-15 14:32 ` Andrew Cagney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox