* gdb.base/attach.exp (do_attach_tests): Don't forget to kill second
[deliverable/binutils-gdb.git] / gdb / observer.c
index 92ec48e614fb261726018d684f21aa7f62e6f601..6bdcdf5b45299254331d0fd1bc65dd9a9a9a9787 100644 (file)
 
 #include "defs.h"
 #include "observer.h"
+#include "command.h"
+#include "gdbcmd.h"
+
+static int observer_debug;
 
 /* The internal generic observer.  */
 
@@ -159,34 +163,48 @@ generic_observer_notify (struct observer_list *subject, const void *args)
     }
 }
 
-/* normal_stop notifications.  */
 
-static struct observer_list *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
+   that matter)!  */
 
-static void
-observer_normal_stop_notification_stub (const void *data,
-                                       const void *unused_args)
+/* If we define these variables and functions as `static', the
+   compiler will optimize them out.  */
+int observer_test_first_observer = 0;
+int observer_test_second_observer = 0;
+int observer_test_third_observer = 0;
+
+void
+observer_test_first_notification_function (struct bpstats *bs)
 {
-  observer_normal_stop_ftype *notify = (observer_normal_stop_ftype *) data;
-  (*notify) ();
+  observer_test_first_observer++;
 }
 
-struct observer *
-observer_attach_normal_stop (observer_normal_stop_ftype *f)
+void
+observer_test_second_notification_function (struct bpstats *bs)
 {
-  return generic_observer_attach (&normal_stop_subject,
-                                 &observer_normal_stop_notification_stub,
-                                 (void *) f);
+  observer_test_second_observer++;
 }
 
 void
-observer_detach_normal_stop (struct observer *observer)
+observer_test_third_notification_function (struct bpstats *bs)
 {
-  generic_observer_detach (&normal_stop_subject, observer);
+  observer_test_third_observer++;
 }
 
+extern initialize_file_ftype _initialize_observer; /* -Wmissing-prototypes */
+
 void
-observer_notify_normal_stop (void)
+_initialize_observer (void)
 {
-  generic_observer_notify (normal_stop_subject, NULL);
+  add_setshow_zinteger_cmd ("observer", class_maintenance, &observer_debug, "\
+Set observer debugging.\n\
+When non-zero, observer debugging is enabled.",  "\
+Show observer debugging.\n\
+When non-zero, observer debugging is enabled.",
+                           NULL, NULL,
+                           &setdebuglist, &showdebuglist);
 }
+
+#include "observer.inc"
This page took 0.026127 seconds and 4 git commands to generate.