From: Simon Marchi Date: Fri, 21 Apr 2023 13:45:30 +0000 (-0400) Subject: gdb: add interp::on_new_thread method X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=30e7e0a917b44cbef439cb9c52fa41d21a5f8e44;p=binutils-gdb.git gdb: add interp::on_new_thread method Same idea as previous patches, but for new_thread. Change-Id: Ib70ae3421b736fd69d86c4e7c708bec349aa256c --- diff --git a/gdb/interps.c b/gdb/interps.c index 55abcb3c6e4..896484530aa 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -446,6 +446,14 @@ interps_notify_user_selected_context_changed (user_selected_what 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. */ void _initialize_interpreter (); void diff --git a/gdb/interps.h b/gdb/interps.h index 4706c9bb63e..05ea91e0cda 100644 --- a/gdb/interps.h +++ b/gdb/interps.h @@ -29,6 +29,7 @@ struct ui_out; struct interp; struct ui; class completion_tracker; +struct thread_info; 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) {} + /* Notify the interpreter that thread T has been created. */ + virtual void on_new_thread (thread_info *t) {} + private: /* The memory for this is static, it comes from literal strings (e.g. "cli"). */ const char *m_name; @@ -225,6 +229,9 @@ extern void interps_notify_exited (int status); extern void interps_notify_user_selected_context_changed (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 */ #define INTERP_CONSOLE "console" #define INTERP_MI2 "mi2" diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index 2984cb9af11..70903311568 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -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_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_record_changed (struct inferior*, int, const char *, const char *); @@ -307,24 +306,15 @@ mi_interp::pre_command_loop () display_mi_prompt (mi); } -static void -mi_new_thread (struct thread_info *t) +void +mi_interp::on_new_thread (thread_info *t) { - 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-created,id=\"%d\",group-id=\"i%d\"", - t->global_num, t->inf->num); - gdb_flush (mi->event_channel); - } + gdb_printf (this->event_channel, "thread-created,id=\"%d\",group-id=\"i%d\"", + t->global_num, t->inf->num); + gdb_flush (this->event_channel); } static void @@ -1189,7 +1179,6 @@ _initialize_mi_interp () interp_factory_register (INTERP_MI4, 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::inferior_added.attach (mi_inferior_added, "mi-interp"); gdb::observers::inferior_appeared.attach (mi_inferior_appeared, "mi-interp"); diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h index bb66e630432..72e3c2158c2 100644 --- a/gdb/mi/mi-interp.h +++ b/gdb/mi/mi-interp.h @@ -50,6 +50,7 @@ public: void on_sync_execution_done () override; void on_command_error () 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_console_file *out; diff --git a/gdb/thread.c b/gdb/thread.c index 13db9f8747e..223ba1df96d 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -49,6 +49,7 @@ #include "gdbsupport/gdb_optional.h" #include "inline-frame.h" #include "stack.h" +#include "interps.h" /* See gdbthread.h. */ @@ -260,6 +261,15 @@ new_thread (struct inferior *inf, ptid_t ptid) 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 * 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); tp = new_thread (inf, ptid); - gdb::observers::new_thread.notify (tp); + notify_new_thread (tp); return tp; }