aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2023-04-21 09:45:30 -0400
committerSimon Marchi <simon.marchi@efficios.com>2023-05-30 15:07:26 -0400
commit0c613e170e60f673cd47b23a7052b19b128469c5 (patch)
treebcf6872d90c5ed20a9890d108eae6ef3f9ec22b6
parent023c6d45d793b729b58968a50dee607e8b30a4d0 (diff)
downloadfsf-binutils-gdb-0c613e170e60f673cd47b23a7052b19b128469c5.zip
fsf-binutils-gdb-0c613e170e60f673cd47b23a7052b19b128469c5.tar.gz
fsf-binutils-gdb-0c613e170e60f673cd47b23a7052b19b128469c5.tar.bz2
gdb: add interp::on_inferior_appeared method
Same idea as previous patches, but for inferior_appeared. Change-Id: Ibe4feba34274549a886b1dfb5b3f8d59ae79e1b5
-rw-r--r--gdb/inferior.c11
-rw-r--r--gdb/interps.c8
-rw-r--r--gdb/interps.h10
-rw-r--r--gdb/mi/mi-interp.c25
-rw-r--r--gdb/mi/mi-interp.h1
5 files changed, 34 insertions, 21 deletions
diff --git a/gdb/inferior.c b/gdb/inferior.c
index a70bbe4..46d418a 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -345,6 +345,15 @@ detach_inferior (inferior *inf)
target_pid_to_str (ptid_t (pid)).c_str ());
}
+/* Notify interpreters and observers that inferior INF appeared. */
+
+static void
+notify_inferior_appeared (inferior *inf)
+{
+ interps_notify_inferior_appeared (inf);
+ gdb::observers::inferior_appeared.notify (inf);
+}
+
void
inferior_appeared (struct inferior *inf, int pid)
{
@@ -358,7 +367,7 @@ inferior_appeared (struct inferior *inf, int pid)
inf->has_exit_code = false;
inf->exit_code = 0;
- gdb::observers::inferior_appeared.notify (inf);
+ notify_inferior_appeared (inf);
}
struct inferior *
diff --git a/gdb/interps.c b/gdb/interps.c
index f648699..ed33df2 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -470,6 +470,14 @@ interps_notify_inferior_added (inferior *inf)
interps_notify (&interp::on_inferior_added, inf);
}
+/* See interps.h. */
+
+void
+interps_notify_inferior_appeared (inferior *inf)
+{
+ interps_notify (&interp::on_inferior_appeared, inf);
+}
+
/* This just adds the "interpreter-exec" command. */
void _initialize_interpreter ();
void
diff --git a/gdb/interps.h b/gdb/interps.h
index 0c73a1a..09edaae 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -122,9 +122,12 @@ public:
/* Notify the interpreter that thread T has exited. */
virtual void on_thread_exited (thread_info *, int silent) {}
- /* Notify the intepreter that inferior INF was added. */
+ /* Notify the interpreter that inferior INF was added. */
virtual void on_inferior_added (inferior *inf) {}
+ /* Notify the interpreter that inferior INF was started or attached. */
+ virtual void on_inferior_appeared (inferior *inf) {}
+
private:
/* The memory for this is static, it comes from literal strings (e.g. "cli"). */
const char *m_name;
@@ -242,9 +245,12 @@ extern void interps_notify_new_thread (thread_info *t);
/* Notify all interpreters that thread T has exited. */
extern void interps_notify_thread_exited (thread_info *t, int silent);
-/* Notify all intepreters that inferior INF was added. */
+/* Notify all interpreters that inferior INF was added. */
extern void interps_notify_inferior_added (inferior *inf);
+/* Notify all interpreters that inferior INF was started or attached. */
+extern void interps_notify_inferior_appeared (inferior *inf);
+
/* 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 c42c23d..3fce9b6 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_record_changed (struct inferior*, int, const char *,
const char *);
-static void mi_inferior_appeared (struct inferior *inf);
static void mi_inferior_exit (struct inferior *inf);
static void mi_inferior_removed (struct inferior *inf);
static void mi_on_resume (ptid_t ptid);
@@ -369,24 +368,15 @@ mi_interp::on_inferior_added (inferior *inf)
gdb_flush (this->event_channel);
}
-static void
-mi_inferior_appeared (struct inferior *inf)
+void
+mi_interp::on_inferior_appeared (inferior *inf)
{
- SWITCH_THRU_ALL_UIS ()
- {
- struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-
- if (mi == NULL)
- continue;
-
- target_terminal::scoped_restore_terminal_state term_state;
- target_terminal::ours_for_output ();
+ target_terminal::scoped_restore_terminal_state term_state;
+ target_terminal::ours_for_output ();
- gdb_printf (mi->event_channel,
- "thread-group-started,id=\"i%d\",pid=\"%d\"",
- inf->num, inf->pid);
- gdb_flush (mi->event_channel);
- }
+ gdb_printf (this->event_channel, "thread-group-started,id=\"i%d\",pid=\"%d\"",
+ inf->num, inf->pid);
+ gdb_flush (this->event_channel);
}
static void
@@ -1140,7 +1130,6 @@ _initialize_mi_interp ()
interp_factory_register (INTERP_MI4, mi_interp_factory);
interp_factory_register (INTERP_MI, mi_interp_factory);
- gdb::observers::inferior_appeared.attach (mi_inferior_appeared, "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");
diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h
index 71d526f..f57f99b 100644
--- a/gdb/mi/mi-interp.h
+++ b/gdb/mi/mi-interp.h
@@ -53,6 +53,7 @@ public:
void on_new_thread (thread_info *t) override;
void on_thread_exited (thread_info *t, int silent) override;
void on_inferior_added (inferior *inf) override;
+ void on_inferior_appeared (inferior *inf) override;
/* MI's output channels */
mi_console_file *out;