gdb: add interp::on_new_thread method

Same idea as previous patches, but for new_thread.

Change-Id: Ib70ae3421b736fd69d86c4e7c708bec349aa256c
This commit is contained in:
Simon Marchi
2023-04-21 09:45:30 -04:00
parent 77cd03e27c
commit 30e7e0a917
5 changed files with 34 additions and 19 deletions

View File

@@ -446,6 +446,14 @@ interps_notify_user_selected_context_changed (user_selected_what selection)
interps_notify (&interp::on_user_selected_context_changed, selection); interps_notify (&interp::on_user_selected_context_changed, selection);
} }
/* See interps.h. */
void
interps_notify_new_thread (thread_info *t)
{
interps_notify (&interp::on_new_thread, t);
}
/* This just adds the "interpreter-exec" command. */ /* This just adds the "interpreter-exec" command. */
void _initialize_interpreter (); void _initialize_interpreter ();
void void

View File

@@ -29,6 +29,7 @@ struct ui_out;
struct interp; struct interp;
struct ui; struct ui;
class completion_tracker; class completion_tracker;
struct thread_info;
typedef struct interp *(*interp_factory_func) (const char *name); typedef struct interp *(*interp_factory_func) (const char *name);
@@ -114,6 +115,9 @@ public:
virtual void on_user_selected_context_changed (user_selected_what selection) virtual void on_user_selected_context_changed (user_selected_what selection)
{} {}
/* Notify the interpreter that thread T has been created. */
virtual void on_new_thread (thread_info *t) {}
private: private:
/* The memory for this is static, it comes from literal strings (e.g. "cli"). */ /* The memory for this is static, it comes from literal strings (e.g. "cli"). */
const char *m_name; const char *m_name;
@@ -225,6 +229,9 @@ extern void interps_notify_exited (int status);
extern void interps_notify_user_selected_context_changed extern void interps_notify_user_selected_context_changed
(user_selected_what selection); (user_selected_what selection);
/* Notify all interpreters that thread T has been created. */
extern void interps_notify_new_thread (thread_info *t);
/* well-known interpreters */ /* well-known interpreters */
#define INTERP_CONSOLE "console" #define INTERP_CONSOLE "console"
#define INTERP_MI2 "mi2" #define INTERP_MI2 "mi2"

View File

@@ -60,7 +60,6 @@ static int mi_interp_query_hook (const char *ctlstr, va_list ap)
static void mi_insert_notify_hooks (void); static void mi_insert_notify_hooks (void);
static void mi_remove_notify_hooks (void); static void mi_remove_notify_hooks (void);
static void mi_new_thread (struct thread_info *t);
static void mi_thread_exit (struct thread_info *t, int silent); static void mi_thread_exit (struct thread_info *t, int silent);
static void mi_record_changed (struct inferior*, int, const char *, static void mi_record_changed (struct inferior*, int, const char *,
const char *); const char *);
@@ -307,24 +306,15 @@ mi_interp::pre_command_loop ()
display_mi_prompt (mi); display_mi_prompt (mi);
} }
static void void
mi_new_thread (struct thread_info *t) mi_interp::on_new_thread (thread_info *t)
{ {
SWITCH_THRU_ALL_UIS () target_terminal::scoped_restore_terminal_state term_state;
{ target_terminal::ours_for_output ();
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
if (mi == NULL) gdb_printf (this->event_channel, "thread-created,id=\"%d\",group-id=\"i%d\"",
continue; t->global_num, t->inf->num);
gdb_flush (this->event_channel);
target_terminal::scoped_restore_terminal_state term_state;
target_terminal::ours_for_output ();
gdb_printf (mi->event_channel,
"thread-created,id=\"%d\",group-id=\"i%d\"",
t->global_num, t->inf->num);
gdb_flush (mi->event_channel);
}
} }
static void static void
@@ -1189,7 +1179,6 @@ _initialize_mi_interp ()
interp_factory_register (INTERP_MI4, mi_interp_factory); interp_factory_register (INTERP_MI4, mi_interp_factory);
interp_factory_register (INTERP_MI, mi_interp_factory); interp_factory_register (INTERP_MI, mi_interp_factory);
gdb::observers::new_thread.attach (mi_new_thread, "mi-interp");
gdb::observers::thread_exit.attach (mi_thread_exit, "mi-interp"); gdb::observers::thread_exit.attach (mi_thread_exit, "mi-interp");
gdb::observers::inferior_added.attach (mi_inferior_added, "mi-interp"); gdb::observers::inferior_added.attach (mi_inferior_added, "mi-interp");
gdb::observers::inferior_appeared.attach (mi_inferior_appeared, "mi-interp"); gdb::observers::inferior_appeared.attach (mi_inferior_appeared, "mi-interp");

View File

@@ -50,6 +50,7 @@ public:
void on_sync_execution_done () override; void on_sync_execution_done () override;
void on_command_error () override; void on_command_error () override;
void on_user_selected_context_changed (user_selected_what selection) override; void on_user_selected_context_changed (user_selected_what selection) override;
void on_new_thread (thread_info *t) override;
/* MI's output channels */ /* MI's output channels */
mi_console_file *out; mi_console_file *out;

View File

@@ -49,6 +49,7 @@
#include "gdbsupport/gdb_optional.h" #include "gdbsupport/gdb_optional.h"
#include "inline-frame.h" #include "inline-frame.h"
#include "stack.h" #include "stack.h"
#include "interps.h"
/* See gdbthread.h. */ /* See gdbthread.h. */
@@ -260,6 +261,15 @@ new_thread (struct inferior *inf, ptid_t ptid)
return tp; return tp;
} }
/* Notify interpreters and observers that thread T has been created. */
static void
notify_new_thread (thread_info *t)
{
interps_notify_new_thread (t);
gdb::observers::new_thread.notify (t);
}
struct thread_info * struct thread_info *
add_thread_silent (process_stratum_target *targ, ptid_t ptid) add_thread_silent (process_stratum_target *targ, ptid_t ptid)
{ {
@@ -280,7 +290,7 @@ add_thread_silent (process_stratum_target *targ, ptid_t ptid)
delete_thread (tp); delete_thread (tp);
tp = new_thread (inf, ptid); tp = new_thread (inf, ptid);
gdb::observers::new_thread.notify (tp); notify_new_thread (tp);
return tp; return tp;
} }