From patchwork Tue May 2 20:49:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 68658 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 038AB3857709 for ; Tue, 2 May 2023 20:54:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 038AB3857709 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683060854; bh=Spt6a+5TRgrBZgQSY8j8GCzWkr+LrJYwZOYP3C12BX4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=xFginoKDrTsRLkaQwUKhPJRxerOT2JLNESiOEKu9LgfgTdVWWMidE9/YN/lS/Ophx ycZ/tjllfnXdxy8MzP6ziEkBDVJJBI8qOGv9j9YqORq9z0LTSPbOsN81hWQU7AziZQ snJDQuryBKUrxY47Zf99PUnP84wzteHKMXnFt9ws= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 571153857710 for ; Tue, 2 May 2023 20:52:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 571153857710 Received: from smarchi-efficios.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 1249D1E0D4; Tue, 2 May 2023 16:52:15 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 11/30] gdb: add interp::on_new_thread method Date: Tue, 2 May 2023 16:49:51 -0400 Message-Id: <20230502205011.132151-12-simon.marchi@efficios.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230502205011.132151-1-simon.marchi@efficios.com> References: <20230502205011.132151-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3497.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Same idea as previous patches, but for new_thread. Change-Id: Ib70ae3421b736fd69d86c4e7c708bec349aa256c --- gdb/interps.c | 8 ++++++++ gdb/interps.h | 7 +++++++ gdb/mi/mi-interp.c | 25 +++++++------------------ gdb/mi/mi-interp.h | 1 + gdb/thread.c | 12 +++++++++++- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/gdb/interps.c b/gdb/interps.c index 55abcb3c6e40..896484530aad 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 4706c9bb63e7..05ea91e0cdaa 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 @@ class interp : public intrusive_list_node 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 ab8c3efbb128..42ec1a7b522e 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 *); @@ -306,24 +305,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 @@ -1188,7 +1178,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 430c61dbbf0a..77fa708397ac 100644 --- a/gdb/mi/mi-interp.h +++ b/gdb/mi/mi-interp.h @@ -50,6 +50,7 @@ class mi_interp final : public interp 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 13db9f8747ea..223ba1df96d9 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; }