forked from Imagelibrary/binutils-gdb
gdb: add interp::on_inferior_disappeared method
Same idea as previous patches, but for inferior_disappeared. For symmetry with on_inferior_appeared, I named this one on_inferior_disappeared, despite the observer being called inferior_exit. This is called when detaching an inferior, so I think that calling it "disappeared" is a bit less misleading (the observer should probably be renamed later). Change-Id: I372101586bc9454997953c1e540a2a6685f53ef6
This commit is contained in:
@@ -283,6 +283,15 @@ delete_inferior (struct inferior *inf)
|
||||
delete inf;
|
||||
}
|
||||
|
||||
/* Notify interpreters and observers that inferior INF disappeared. */
|
||||
|
||||
static void
|
||||
notify_inferior_disappeared (inferior *inf)
|
||||
{
|
||||
interps_notify_inferior_disappeared (inf);
|
||||
gdb::observers::inferior_exit.notify (inf);
|
||||
}
|
||||
|
||||
/* If SILENT then be quiet -- don't announce a inferior exit, or the
|
||||
exit of its threads. */
|
||||
|
||||
@@ -291,7 +300,7 @@ exit_inferior_1 (struct inferior *inf, int silent)
|
||||
{
|
||||
inf->clear_thread_list (silent);
|
||||
|
||||
gdb::observers::inferior_exit.notify (inf);
|
||||
notify_inferior_disappeared (inf);
|
||||
|
||||
inf->pid = 0;
|
||||
inf->fake_pid_p = false;
|
||||
|
||||
@@ -478,6 +478,14 @@ interps_notify_inferior_appeared (inferior *inf)
|
||||
interps_notify (&interp::on_inferior_appeared, inf);
|
||||
}
|
||||
|
||||
/* See interps.h. */
|
||||
|
||||
void
|
||||
interps_notify_inferior_disappeared (inferior *inf)
|
||||
{
|
||||
interps_notify (&interp::on_inferior_disappeared, inf);
|
||||
}
|
||||
|
||||
/* This just adds the "interpreter-exec" command. */
|
||||
void _initialize_interpreter ();
|
||||
void
|
||||
|
||||
@@ -128,6 +128,9 @@ public:
|
||||
/* Notify the interpreter that inferior INF was started or attached. */
|
||||
virtual void on_inferior_appeared (inferior *inf) {}
|
||||
|
||||
/* Notify the interpreter that inferior INF exited or was detached. */
|
||||
virtual void on_inferior_disappeared (inferior *inf) {}
|
||||
|
||||
private:
|
||||
/* The memory for this is static, it comes from literal strings (e.g. "cli"). */
|
||||
const char *m_name;
|
||||
@@ -251,6 +254,9 @@ 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);
|
||||
|
||||
/* Notify all interpreters that inferior INF exited or was detached. */
|
||||
extern void interps_notify_inferior_disappeared (inferior *inf);
|
||||
|
||||
/* well-known interpreters */
|
||||
#define INTERP_CONSOLE "console"
|
||||
#define INTERP_MI2 "mi2"
|
||||
|
||||
@@ -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_exit (struct inferior *inf);
|
||||
static void mi_inferior_removed (struct inferior *inf);
|
||||
static void mi_on_resume (ptid_t ptid);
|
||||
static void mi_solib_loaded (struct so_list *solib);
|
||||
@@ -379,29 +378,21 @@ mi_interp::on_inferior_appeared (inferior *inf)
|
||||
gdb_flush (this->event_channel);
|
||||
}
|
||||
|
||||
static void
|
||||
mi_inferior_exit (struct inferior *inf)
|
||||
void
|
||||
mi_interp::on_inferior_disappeared (inferior *inf)
|
||||
{
|
||||
SWITCH_THRU_ALL_UIS ()
|
||||
{
|
||||
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
|
||||
target_terminal::scoped_restore_terminal_state term_state;
|
||||
target_terminal::ours_for_output ();
|
||||
|
||||
if (mi == NULL)
|
||||
continue;
|
||||
if (inf->has_exit_code)
|
||||
gdb_printf (this->event_channel,
|
||||
"thread-group-exited,id=\"i%d\",exit-code=\"%s\"",
|
||||
inf->num, int_string (inf->exit_code, 8, 0, 0, 1));
|
||||
else
|
||||
gdb_printf (this->event_channel,
|
||||
"thread-group-exited,id=\"i%d\"", inf->num);
|
||||
|
||||
target_terminal::scoped_restore_terminal_state term_state;
|
||||
target_terminal::ours_for_output ();
|
||||
|
||||
if (inf->has_exit_code)
|
||||
gdb_printf (mi->event_channel,
|
||||
"thread-group-exited,id=\"i%d\",exit-code=\"%s\"",
|
||||
inf->num, int_string (inf->exit_code, 8, 0, 0, 1));
|
||||
else
|
||||
gdb_printf (mi->event_channel,
|
||||
"thread-group-exited,id=\"i%d\"", inf->num);
|
||||
|
||||
gdb_flush (mi->event_channel);
|
||||
}
|
||||
gdb_flush (this->event_channel);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1130,7 +1121,6 @@ _initialize_mi_interp ()
|
||||
interp_factory_register (INTERP_MI4, mi_interp_factory);
|
||||
interp_factory_register (INTERP_MI, mi_interp_factory);
|
||||
|
||||
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::target_resumed.attach (mi_on_resume, "mi-interp");
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
void on_thread_exited (thread_info *t, int silent) override;
|
||||
void on_inferior_added (inferior *inf) override;
|
||||
void on_inferior_appeared (inferior *inf) override;
|
||||
void on_inferior_disappeared (inferior *inf) override;
|
||||
|
||||
/* MI's output channels */
|
||||
mi_console_file *out;
|
||||
|
||||
Reference in New Issue
Block a user