aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2023-03-01 20:38:35 -0500
committerSimon Marchi <simon.marchi@efficios.com>2023-05-30 15:07:26 -0400
commit8782926771b1212acb90b944f7402466c998d592 (patch)
treef46baf46bc4895ecbd7fbcec6b5243f1a0bcc1ab /gdb
parent3f75a984d27da2801a9c4237b2b40917c68d6f19 (diff)
downloadgdb-8782926771b1212acb90b944f7402466c998d592.zip
gdb-8782926771b1212acb90b944f7402466c998d592.tar.gz
gdb-8782926771b1212acb90b944f7402466c998d592.tar.bz2
gdb: add interp::on_normal_stop method
Same idea as the previous patch, but for the normal_stop event. Change-Id: I4fc8ca8a51c63829dea390a2b6ce30b77f9fb863
Diffstat (limited to 'gdb')
-rw-r--r--gdb/cli/cli-interp.c21
-rw-r--r--gdb/cli/cli-interp.h1
-rw-r--r--gdb/infrun.c19
-rw-r--r--gdb/infrun.h4
-rw-r--r--gdb/interps.c8
-rw-r--r--gdb/interps.h7
-rw-r--r--gdb/mi/mi-interp.c51
-rw-r--r--gdb/mi/mi-interp.h1
-rw-r--r--gdb/remote.c3
9 files changed, 57 insertions, 58 deletions
diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 51c78d9..9508171 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -112,10 +112,8 @@ should_print_stop_to_console (struct interp *console_interp,
interpreter-exec), print nothing. These are named "cli_base" as
they print to both CLI interpreters and TUI interpreters. */
-/* Observer for the normal_stop notification. */
-
-static void
-cli_base_on_normal_stop (struct bpstat *bs, int print_frame)
+void
+cli_interp_base::on_normal_stop (struct bpstat *bs, int print_frame)
{
if (!print_frame)
return;
@@ -124,17 +122,10 @@ cli_base_on_normal_stop (struct bpstat *bs, int print_frame)
if (cli_suppress_notification.normal_stop)
return;
- SWITCH_THRU_ALL_UIS ()
- {
- struct interp *interp = top_level_interpreter ();
- cli_interp_base *cli = as_cli_interp_base (interp);
- if (cli == nullptr)
- continue;
+ thread_info *thread = inferior_thread ();
+ if (should_print_stop_to_console (this, thread))
+ print_stop_event (this->interp_ui_out ());
- thread_info *thread = inferior_thread ();
- if (should_print_stop_to_console (interp, thread))
- print_stop_event (cli->interp_ui_out ());
- }
}
void
@@ -397,8 +388,6 @@ _initialize_cli_interp ()
interp_factory_register (INTERP_CONSOLE, cli_interp_factory);
/* Note these all work for both the CLI and TUI interpreters. */
- gdb::observers::normal_stop.attach (cli_base_on_normal_stop,
- "cli-interp-base");
gdb::observers::signal_exited.attach (cli_base_on_signal_exited,
"cli-interp-base");
gdb::observers::exited.attach (cli_base_on_exited, "cli-interp-base");
diff --git a/gdb/cli/cli-interp.h b/gdb/cli/cli-interp.h
index f7bee45..4fca801 100644
--- a/gdb/cli/cli-interp.h
+++ b/gdb/cli/cli-interp.h
@@ -34,6 +34,7 @@ public:
bool supports_command_editing () override;
void on_signal_received (gdb_signal sig) override;
+ void on_normal_stop(bpstat *bs, int print_frame) override;
private:
struct saved_output_files
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 6a2973e..9c4417f 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -6274,6 +6274,15 @@ notify_signal_received (gdb_signal sig)
gdb::observers::signal_received.notify (sig);
}
+/* See infrun.h. */
+
+void
+notify_normal_stop (bpstat *bs, int print_frame)
+{
+ interps_notify_normal_stop (bs, print_frame);
+ gdb::observers::normal_stop.notify (bs, print_frame);
+}
+
/* Come here when the program has stopped with a signal. */
static void
@@ -8956,12 +8965,10 @@ normal_stop ()
/* Notify observers about the stop. This is where the interpreters
print the stop event. */
- if (inferior_ptid != null_ptid)
- gdb::observers::normal_stop.notify (inferior_thread ()->control.stop_bpstat,
- stop_print_frame);
- else
- gdb::observers::normal_stop.notify (nullptr, stop_print_frame);
-
+ notify_normal_stop ((inferior_ptid != null_ptid
+ ? inferior_thread ()->control.stop_bpstat
+ : nullptr),
+ stop_print_frame);
annotate_stopped ();
if (target_has_execution ())
diff --git a/gdb/infrun.h b/gdb/infrun.h
index f7b60a4..cbafc3e 100644
--- a/gdb/infrun.h
+++ b/gdb/infrun.h
@@ -214,6 +214,10 @@ extern void set_step_info (thread_info *tp,
signal SIG. */
extern void notify_signal_received (gdb_signal sig);
+/* Notify interpreters and observers that the current inferior has stopped
+ normally. */
+extern void notify_normal_stop (bpstat *bs, int print_frame);
+
/* Several print_*_reason helper functions to print why the inferior
has stopped to the passed in UIOUT. */
diff --git a/gdb/interps.c b/gdb/interps.c
index 5d061ad..80160bc 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -406,6 +406,14 @@ interps_notify_signal_received (gdb_signal sig)
interps_notify (&interp::on_signal_received, sig);
}
+/* See interps.h. */
+
+void
+interps_notify_normal_stop (bpstat *bs, int print_frame)
+{
+ interps_notify (&interp::on_normal_stop, bs, print_frame);
+}
+
/* This just adds the "interpreter-exec" command. */
void _initialize_interpreter ();
void
diff --git a/gdb/interps.h b/gdb/interps.h
index 4762c4c..dd5a9b7 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -24,6 +24,7 @@
#include "gdbsupport/intrusive_list.h"
+struct bpstat;
struct ui_out;
struct interp;
struct ui;
@@ -86,6 +87,9 @@ public:
SIG. */
virtual void on_signal_received (gdb_signal sig) {}
+ /* Notify the interpreter that the current inferior has stopped normally. */
+ virtual void on_normal_stop (bpstat *bs, int print_frame) {}
+
private:
/* The memory for this is static, it comes from literal strings (e.g. "cli"). */
const char *m_name;
@@ -178,6 +182,9 @@ extern void interpreter_completer (struct cmd_list_element *ignore,
SIG. */
extern void interps_notify_signal_received (gdb_signal sig);
+/* Notify all interpreters that the current inferior has stopped normally. */
+extern void interps_notify_normal_stop (bpstat *bs, int print_frame);
+
/* well-known interpreters */
#define INTERP_CONSOLE "console"
#define INTERP_MI2 "mi2"
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index b77494e..e3cb159 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -62,7 +62,6 @@ static void mi_remove_notify_hooks (void);
static void mi_on_signal_exited (enum gdb_signal siggnal);
static void mi_on_exited (int exitstatus);
-static void mi_on_normal_stop (struct bpstat *bs, int print_frame);
static void mi_on_no_history (void);
static void mi_new_thread (struct thread_info *t);
@@ -582,33 +581,28 @@ mi_on_no_history (void)
}
}
-static void
-mi_on_normal_stop_1 (struct bpstat *bs, int print_frame)
+void
+mi_interp::on_normal_stop (struct bpstat *bs, int print_frame)
{
/* Since this can be called when CLI command is executing,
using cli interpreter, be sure to use MI uiout for output,
not the current one. */
- struct ui_out *mi_uiout = top_level_interpreter ()->interp_ui_out ();
- struct mi_interp *mi = (struct mi_interp *) top_level_interpreter ();
+ ui_out *mi_uiout = this->interp_ui_out ();
if (print_frame)
{
- struct thread_info *tp;
- int core;
- struct interp *console_interp;
-
- tp = inferior_thread ();
+ thread_info *tp = inferior_thread ();
if (tp->thread_fsm () != nullptr
&& tp->thread_fsm ()->finished_p ())
{
- enum async_reply_reason reason;
-
- reason = tp->thread_fsm ()->async_reply_reason ();
+ async_reply_reason reason
+ = tp->thread_fsm ()->async_reply_reason ();
mi_uiout->field_string ("reason", async_reason_lookup (reason));
}
- console_interp = interp_lookup (current_ui, INTERP_CONSOLE);
+ interp *console_interp = interp_lookup (current_ui, INTERP_CONSOLE);
+
/* We only want to print the displays once, and we want it to
look just how it would on the console, so we use this to
decide whether the MI stop should include them. */
@@ -616,7 +610,7 @@ mi_on_normal_stop_1 (struct bpstat *bs, int print_frame)
print_stop_event (mi_uiout, !console_print);
if (console_print)
- print_stop_event (mi->cli_uiout);
+ print_stop_event (this->cli_uiout);
mi_uiout->field_signed ("thread-id", tp->global_num);
if (non_stop)
@@ -628,29 +622,17 @@ mi_on_normal_stop_1 (struct bpstat *bs, int print_frame)
else
mi_uiout->field_string ("stopped-threads", "all");
- core = target_core_of_thread (tp->ptid);
+ int core = target_core_of_thread (tp->ptid);
if (core != -1)
mi_uiout->field_signed ("core", core);
}
-
- gdb_puts ("*stopped", mi->raw_stdout);
- mi_out_put (mi_uiout, mi->raw_stdout);
- mi_out_rewind (mi_uiout);
- mi_print_timing_maybe (mi->raw_stdout);
- gdb_puts ("\n", mi->raw_stdout);
- gdb_flush (mi->raw_stdout);
-}
-static void
-mi_on_normal_stop (struct bpstat *bs, int print_frame)
-{
- SWITCH_THRU_ALL_UIS ()
- {
- if (as_mi_interp (top_level_interpreter ()) == NULL)
- continue;
-
- mi_on_normal_stop_1 (bs, print_frame);
- }
+ gdb_puts ("*stopped", this->raw_stdout);
+ mi_out_put (mi_uiout, this->raw_stdout);
+ mi_out_rewind (mi_uiout);
+ mi_print_timing_maybe (this->raw_stdout);
+ gdb_puts ("\n", this->raw_stdout);
+ gdb_flush (this->raw_stdout);
}
static void
@@ -1303,7 +1285,6 @@ _initialize_mi_interp ()
gdb::observers::inferior_exit.attach (mi_inferior_exit, "mi-interp");
gdb::observers::inferior_removed.attach (mi_inferior_removed, "mi-interp");
gdb::observers::record_changed.attach (mi_record_changed, "mi-interp");
- gdb::observers::normal_stop.attach (mi_on_normal_stop, "mi-interp");
gdb::observers::target_resumed.attach (mi_on_resume, "mi-interp");
gdb::observers::solib_loaded.attach (mi_solib_loaded, "mi-interp");
gdb::observers::solib_unloaded.attach (mi_solib_unloaded, "mi-interp");
diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h
index a8fd7b6..51e6298 100644
--- a/gdb/mi/mi-interp.h
+++ b/gdb/mi/mi-interp.h
@@ -43,6 +43,7 @@ public:
void pre_command_loop () override;
void on_signal_received (gdb_signal sig) override;
+ void on_normal_stop (struct bpstat *bs, int print_frame) override;
/* MI's output channels */
mi_console_file *out;
diff --git a/gdb/remote.c b/gdb/remote.c
index 0d82d0f..b25a0b7 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4722,7 +4722,8 @@ remote_target::print_one_stopped_thread (thread_info *thread)
if (signal_print_state (sig))
notify_signal_received (sig);
}
- gdb::observers::normal_stop.notify (NULL, 1);
+
+ notify_normal_stop (nullptr, 1);
}
/* Process all initial stop replies the remote side sent in response