Convert observers to C++

This converts observers from using a special source-generating script
to be plain C++.  This version of the patch takes advantage of C++11
by using std::function and variadic templates; incorporates Pedro's
patches; and renames the header file to "observable.h" (this change
eliminates the need for a clean rebuild).

Note that Pedro's patches used a template lambda in tui-hooks.c, but
this failed to compile on some buildbot instances (presumably due to
differing C++ versions); I replaced this with an ordinary template
function.

Regression tested on the buildbot.

gdb/ChangeLog
2018-03-19  Pedro Alves  <palves@redhat.com>
	    Tom Tromey  <tom@tromey.com>

	* unittests/observable-selftests.c: New file.
	* common/observable.h: New file.
	* observable.h: New file.
	* ada-lang.c, ada-tasks.c, agent.c, aix-thread.c, annotate.c,
	arm-tdep.c, auto-load.c, auxv.c, break-catch-syscall.c,
	breakpoint.c, bsd-uthread.c, cli/cli-interp.c, cli/cli-setshow.c,
	corefile.c, dummy-frame.c, event-loop.c, event-top.c, exec.c,
	extension.c, frame.c, gdbarch.c, guile/scm-breakpoint.c,
	infcall.c, infcmd.c, inferior.c, inflow.c, infrun.c, jit.c,
	linux-tdep.c, linux-thread-db.c, m68klinux-tdep.c,
	mi/mi-cmd-break.c, mi/mi-interp.c, mi/mi-main.c, objfiles.c,
	ppc-linux-nat.c, ppc-linux-tdep.c, printcmd.c, procfs.c,
	python/py-breakpoint.c, python/py-finishbreakpoint.c,
	python/py-inferior.c, python/py-unwind.c, ravenscar-thread.c,
	record-btrace.c, record-full.c, record.c, regcache.c, remote.c,
	riscv-tdep.c, sol-thread.c, solib-aix.c, solib-spu.c, solib.c,
	spu-multiarch.c, spu-tdep.c, stack.c, symfile-mem.c, symfile.c,
	symtab.c, thread.c, top.c, tracepoint.c, tui/tui-hooks.c,
	tui/tui-interp.c, valops.c: Update all users.
	* tui/tui-hooks.c (tui_bp_created_observer)
	(tui_bp_deleted_observer, tui_bp_modified_observer)
	(tui_inferior_exit_observer, tui_before_prompt_observer)
	(tui_normal_stop_observer, tui_register_changed_observer):
	Remove.
	(tui_observers_token): New global.
	(attach_or_detach, tui_attach_detach_observers): New functions.
	(tui_install_hooks, tui_remove_hooks): Use
	tui_attach_detach_observers.
	* record-btrace.c (record_btrace_thread_observer): Remove.
	(record_btrace_thread_observer_token): New global.
	* observer.sh: Remove.
	* observer.c: Rename to observable.c.
	* observable.c (namespace gdb_observers): Define new objects.
	(observer_debug): Move into gdb_observers namespace.
	(struct observer, struct observer_list, xalloc_observer_list_node)
	(xfree_observer_list_node, generic_observer_attach)
	(generic_observer_detach, generic_observer_notify): Remove.
	(_initialize_observer): Update.
	Don't include observer.inc.
	* Makefile.in (generated_files): Remove observer.h, observer.inc.
	(clean mostlyclean): Likewise.
	(observer.h, observer.inc): Remove targets.
	(SUBDIR_UNITTESTS_SRCS): Add observable-selftests.c.
	(COMMON_SFILES): Use observable.c, not observer.c.
	* .gitignore: Remove observer.h.

gdb/doc/ChangeLog
2018-03-19  Tom Tromey  <tom@tromey.com>

	* observer.texi: Remove.

gdb/testsuite/ChangeLog
2018-03-19  Tom Tromey  <tom@tromey.com>

	* gdb.gdb/observer.exp: Remove.
This commit is contained in:
Tom Tromey
2016-10-02 10:50:20 -06:00
parent 194ed4130d
commit 76727919ce
86 changed files with 999 additions and 1234 deletions

View File

@@ -38,7 +38,7 @@
#include "inf-loop.h"
#include "regcache.h"
#include "value.h"
#include "observer.h"
#include "observable.h"
#include "language.h"
#include "solib.h"
#include "main.h"
@@ -2899,7 +2899,7 @@ clear_proceed_status (int step)
inferior->control.stop_soon = NO_STOP_QUIETLY;
}
observer_notify_about_to_proceed ();
gdb::observers::about_to_proceed.notify ();
}
/* Returns true if TP is still stopped at a breakpoint that needs
@@ -3816,7 +3816,7 @@ check_curr_ui_sync_execution_done (void)
&& !gdb_in_secondary_prompt_p (ui))
{
target_terminal::ours ();
observer_notify_sync_execution_done ();
gdb::observers::sync_execution_done.notify ();
ui_register_input_event_handler (ui);
}
}
@@ -5069,7 +5069,7 @@ handle_inferior_event_1 (struct execution_control_state *ecs)
/* Support the --return-child-result option. */
return_child_result_value = ecs->ws.value.integer;
observer_notify_exited (ecs->ws.value.integer);
gdb::observers::exited.notify (ecs->ws.value.integer);
}
else
{
@@ -5098,7 +5098,7 @@ handle_inferior_event_1 (struct execution_control_state *ecs)
Cannot fill $_exitsignal with the correct signal number.\n"));
}
observer_notify_signal_exited (ecs->ws.value.sig);
gdb::observers::signal_exited.notify (ecs->ws.value.sig);
}
gdb_flush (gdb_stdout);
@@ -5392,7 +5392,7 @@ Cannot fill $_exitsignal with the correct signal number.\n"));
if (handle_stop_requested (ecs))
return;
observer_notify_no_history ();
gdb::observers::no_history.notify ();
stop_waiting (ecs);
return;
}
@@ -6096,7 +6096,7 @@ handle_signal_stop (struct execution_control_state *ecs)
{
/* The signal table tells us to print about this signal. */
target_terminal::ours_for_output ();
observer_notify_signal_received (ecs->event_thread->suspend.stop_signal);
gdb::observers::signal_received.notify (ecs->event_thread->suspend.stop_signal);
target_terminal::inferior ();
}
@@ -8205,7 +8205,7 @@ normal_stop (void)
update_thread_list ();
if (last.kind == TARGET_WAITKIND_STOPPED && stopped_by_random_signal)
observer_notify_signal_received (inferior_thread ()->suspend.stop_signal);
gdb::observers::signal_received.notify (inferior_thread ()->suspend.stop_signal);
/* As with the notification of thread events, we want to delay
notifying the user that we've switched thread context until
@@ -8330,10 +8330,10 @@ normal_stop (void)
/* Notify observers about the stop. This is where the interpreters
print the stop event. */
if (!ptid_equal (inferior_ptid, null_ptid))
observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat,
gdb::observers::normal_stop.notify (inferior_thread ()->control.stop_bpstat,
stop_print_frame);
else
observer_notify_normal_stop (NULL, stop_print_frame);
gdb::observers::normal_stop.notify (NULL, stop_print_frame);
annotate_stopped ();
@@ -9438,10 +9438,10 @@ enabled by default on some platforms."),
inferior_ptid = null_ptid;
target_last_wait_ptid = minus_one_ptid;
observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
observer_attach_thread_stop_requested (infrun_thread_stop_requested);
observer_attach_thread_exit (infrun_thread_thread_exit);
observer_attach_inferior_exit (infrun_inferior_exit);
gdb::observers::thread_ptid_changed.attach (infrun_thread_ptid_changed);
gdb::observers::thread_stop_requested.attach (infrun_thread_stop_requested);
gdb::observers::thread_exit.attach (infrun_thread_thread_exit);
gdb::observers::inferior_exit.attach (infrun_inferior_exit);
/* Explicitly create without lookup, since that tries to create a
value with a void typed value, and when we get here, gdbarch