From patchwork Tue May 2 20:49:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 68657 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 E7D723858D33 for ; Tue, 2 May 2023 20:53:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E7D723858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683060820; bh=u6cM6+7+szLjZTyHUB6SV2GzFKB4gU0HZjTZTa+wONI=; 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=psiYtJIX31GUzCT3UbwohFumHoZczq9xEF74tIYeKZZuyDpWs1jPK9h/+4UgzmD3s NN/vlJszddd0kcV8EsdOBf39qURNOGX1yPF1VigXoPzV9vm7nkcFdXl6DW5fSq/ycL PiarMgR7wXLz0scg+mjN0Es8CJ2WOcIwdkZD1fdg= 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 69E7F3857711 for ; Tue, 2 May 2023 20:52:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 69E7F3857711 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 292501E114; Tue, 2 May 2023 16:52:21 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 12/30] gdb: add interp::on_thread_exited method Date: Tue, 2 May 2023 16:49:52 -0400 Message-Id: <20230502205011.132151-13-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 thread_exited. Change-Id: I4be974cbe58cf635453fef503c2d77c82522cbd9 --- gdb/interps.c | 8 ++++++++ gdb/interps.h | 6 ++++++ gdb/mi/mi-interp.c | 25 +++++++------------------ gdb/mi/mi-interp.h | 1 + gdb/thread.c | 11 ++++++++++- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/gdb/interps.c b/gdb/interps.c index 896484530aad..be11fd835189 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -454,6 +454,14 @@ interps_notify_new_thread (thread_info *t) interps_notify (&interp::on_new_thread, t); } +/* See interps.h. */ + +void +interps_notify_thread_exited (thread_info *t, int silent) +{ + interps_notify (&interp::on_thread_exited, t, silent); +} + /* This just adds the "interpreter-exec" command. */ void _initialize_interpreter (); void diff --git a/gdb/interps.h b/gdb/interps.h index 05ea91e0cdaa..cd099381d002 100644 --- a/gdb/interps.h +++ b/gdb/interps.h @@ -118,6 +118,9 @@ class interp : public intrusive_list_node /* Notify the interpreter that thread T has been created. */ virtual void on_new_thread (thread_info *t) {} + /* Notify the interpreter that thread T has exited. */ + virtual void on_thread_exited (thread_info *, int silent) {} + private: /* The memory for this is static, it comes from literal strings (e.g. "cli"). */ const char *m_name; @@ -232,6 +235,9 @@ extern void interps_notify_user_selected_context_changed /* Notify all interpreters that thread T has been created. */ 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); + /* 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 42ec1a7b522e..a1960b14046d 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_thread_exit (struct thread_info *t, int silent); static void mi_record_changed (struct inferior*, int, const char *, const char *); static void mi_inferior_added (struct inferior *inf); @@ -316,23 +315,14 @@ mi_interp::on_new_thread (thread_info *t) gdb_flush (this->event_channel); } -static void -mi_thread_exit (struct thread_info *t, int silent) +void +mi_interp::on_thread_exited (thread_info *t, int silent) { - 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 (); - gdb_printf (mi->event_channel, - "thread-exited,id=\"%d\",group-id=\"i%d\"", - t->global_num, t->inf->num); - gdb_flush (mi->event_channel); - } + target_terminal::scoped_restore_terminal_state term_state; + target_terminal::ours_for_output (); + gdb_printf (this->event_channel, "thread-exited,id=\"%d\",group-id=\"i%d\"", + t->global_num, t->inf->num); + gdb_flush (this->event_channel); } /* Emit notification on changing the state of record. */ @@ -1178,7 +1168,6 @@ _initialize_mi_interp () interp_factory_register (INTERP_MI4, mi_interp_factory); interp_factory_register (INTERP_MI, mi_interp_factory); - 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"); gdb::observers::inferior_exit.attach (mi_inferior_exit, "mi-interp"); diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h index 77fa708397ac..443ec03465a7 100644 --- a/gdb/mi/mi-interp.h +++ b/gdb/mi/mi-interp.h @@ -51,6 +51,7 @@ class mi_interp final : public interp void on_command_error () override; void on_user_selected_context_changed (user_selected_what selection) override; void on_new_thread (thread_info *t) override; + void on_thread_exited (thread_info *t, int silent) override; /* MI's output channels */ mi_console_file *out; diff --git a/gdb/thread.c b/gdb/thread.c index 223ba1df96d9..b7b5d9fdd993 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -191,6 +191,15 @@ clear_thread_inferior_resources (struct thread_info *tp) clear_inline_frame_state (tp); } +/* Notify interpreters and observers that thread T has exited. */ + +static void +notify_thread_exited (thread_info *t, int silent) +{ + interps_notify_thread_exited (t, silent); + gdb::observers::thread_exit.notify (t, silent); +} + /* See gdbthread.h. */ void @@ -213,7 +222,7 @@ set_thread_exited (thread_info *tp, bool silent) if (proc_target != nullptr) proc_target->maybe_remove_resumed_with_pending_wait_status (tp); - gdb::observers::thread_exit.notify (tp, silent); + notify_thread_exited (tp, silent); /* Tag it as exited. */ tp->state = THREAD_EXITED;