From patchwork Mon Nov 13 15:04:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 79758 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 6598D392C2A7 for ; Mon, 13 Nov 2023 15:07:40 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by sourceware.org (Postfix) with ESMTPS id 2CD783898C6F for ; Mon, 13 Nov 2023 15:05:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2CD783898C6F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2CD783898C6F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887931; cv=none; b=sTcoHxuTruMgYuTDH8k6Mn0PezXpi/CWVbdte9JmRSLSHU/mR5T3RUTe7rU+eaCjFnHbdzMH/sH4kDbuL7cYkLhE3zfWXugMMTgwfQr7FAvEKTqNwZKffB4kMYzlkZFTZEvj9jCyorlD633ILpNBPOc5021E3ucqS8ZRk8zvYjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887931; c=relaxed/simple; bh=4wBnPCf7L5o/cXiI588sOUm5voudZyR1abgSuIjKmPQ=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=V6DK6sWJdbe9LamHw7UonXVP4UhezuP9SpEPNfye6mKmcHFqOFdLqt+vhb6+iMjRPDuYqNcs9a2fcuGNemJOWJXY2WFyXXAMEqWnXcty0urmbQ5kwE4VnARXaVzVubIZtEwIhLFH/5Bbhah+N0IP6hWOt8Ix0tAmSz6Pa9pwhds= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2c5056059e0so65244591fa.3 for ; Mon, 13 Nov 2023 07:05:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699887928; x=1700492728; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V80hSzW/T3X5irHLk5K18FAkysBW1mCBpku+JyHyBZA=; b=K4JS+KaQmEBXmfSOjNIO2vdKN8dwxBs8IQwLOdB8RCQFHcsFYVc9bI5WZbyXo0siln hLQKAHsrW4SGCrM76l5rzl6S7xqYWBa22XXLsIsH83fP//lwd+sgAcled+bO1FettS1N Ohtq6wRulrCrX8oyDiu4RCk0QQDBt4wZ0P37B5TNg+WEQ1/zXnJ2nxDEjfYzVWTekYhW E1mTlv78bAqpIzdoy6VV64CkqaOxF0W6LYmf62N5Ay7iqVyQ7ENYNmQkV+vQXfOI3nO5 pTLzwmHJEHdrSpltlOzpSt07qu3Pe2fqqcqiqmjEfwjQ9wm2pPAsL+ec/z/foAPojrLo fbAg== X-Gm-Message-State: AOJu0Yzoa+jkr409uxPvJDJYrehPaJZGb4TDLkRy1BplQ/SIc6UmYCnA Fpop1ijyVmhtiEZ9X/xGgwcFUZxeDic= X-Google-Smtp-Source: AGHT+IEJ/xbV7Q+OF6/U+7a2R0o6QoB4mF9tEjSa5K52b4mMrj7/dCSqdqfaj8X7nzpZokhHpob3oA== X-Received: by 2002:a2e:b5db:0:b0:2c6:ed74:39bd with SMTP id g27-20020a2eb5db000000b002c6ed7439bdmr4163476ljn.12.1699887928501; Mon, 13 Nov 2023 07:05:28 -0800 (PST) Received: from localhost ([2001:8a0:f91e:1a00:8060:1e54:fb28:9635]) by smtp.gmail.com with UTF8SMTPSA id v14-20020a05600c470e00b0040a47091602sm10525629wmo.31.2023.11.13.07.05.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Nov 2023 07:05:27 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [FYI/pushed v4 13/25] Move deleting thread on TARGET_WAITKIND_THREAD_EXITED to core Date: Mon, 13 Nov 2023 15:04:15 +0000 Message-Id: <20231113150427.477431-14-pedro@palves.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231113150427.477431-1-pedro@palves.net> References: <20231113150427.477431-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Currently, infrun assumes that when TARGET_WAITKIND_THREAD_EXITED is reported, the corresponding GDB thread has already been removed from the GDB thread list. Later in the series, that will no longer work, as infrun will need to refer to the thread's thread_info when it processes TARGET_WAITKIND_THREAD_EXITED. As preparation, this patch makes deleting the GDB thread responsibility of infrun, instead of the target. Reviewed-By: Andrew Burgess Change-Id: I013d87f61ffc9aaca49f0d6ce2a43e3ea69274de --- gdb/infrun.c | 32 +++++++++++++++++++++++++++----- gdb/linux-nat.c | 21 ++++++++++++++------- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 03eb32a68c4..e1e761cf48f 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -4352,7 +4352,12 @@ reinstall_readline_callback_handler_cleanup () } /* Clean up the FSMs of threads that are now stopped. In non-stop, - that's just the event thread. In all-stop, that's all threads. */ + that's just the event thread. In all-stop, that's all threads. In + all-stop, threads that had a pending exit no longer have a reason + to be around, as their FSMs/commands are canceled, so we delete + them. This avoids "info threads" listing such threads as if they + were alive (and failing to read their registers), the user being + able to select and resume them (and that failing), etc. */ static void clean_up_just_stopped_threads_fsms (struct execution_control_state *ecs) @@ -4370,15 +4375,29 @@ clean_up_just_stopped_threads_fsms (struct execution_control_state *ecs) { scoped_restore_current_thread restore_thread; - for (thread_info *thr : all_non_exited_threads ()) + for (thread_info *thr : all_threads_safe ()) { - if (thr->thread_fsm () == nullptr) + if (thr->state == THREAD_EXITED) continue; + if (thr == ecs->event_thread) continue; - switch_to_thread (thr); - thr->thread_fsm ()->clean_up (thr); + if (thr->thread_fsm () != nullptr) + { + switch_to_thread (thr); + thr->thread_fsm ()->clean_up (thr); + } + + /* As we are cancelling the command/FSM of this thread, + whatever was the reason we needed to report a thread + exited event to the user, that reason is gone. Delete + the thread, so that the user doesn't see it in the thread + list, the next proceed doesn't try to resume it, etc. */ + if (thr->has_pending_waitstatus () + && (thr->pending_waitstatus ().kind () + == TARGET_WAITKIND_THREAD_EXITED)) + delete_thread (thr); } } } @@ -5728,6 +5747,9 @@ handle_inferior_event (struct execution_control_state *ecs) if (ecs->ws.kind () == TARGET_WAITKIND_THREAD_EXITED) { + ecs->event_thread = ecs->target->find_thread (ecs->ptid); + gdb_assert (ecs->event_thread != nullptr); + delete_thread (ecs->event_thread); prepare_to_wait (ecs); return; } diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 5bbdabc241a..1e224e03ecb 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -898,14 +898,15 @@ linux_nat_switch_fork (ptid_t new_ptid) registers_changed (); } -/* Handle the exit of a single thread LP. */ +/* Handle the exit of a single thread LP. If DEL_THREAD is true, + delete the thread_info associated to LP, if it exists. */ static void -exit_lwp (struct lwp_info *lp) +exit_lwp (struct lwp_info *lp, bool del_thread = true) { struct thread_info *th = linux_target->find_thread (lp->ptid); - if (th) + if (th != nullptr && del_thread) delete_thread (th); delete_lwp (lp->ptid); @@ -3155,11 +3156,17 @@ filter_exit_event (struct lwp_info *event_child, if (!is_leader (event_child)) { if (report_thread_events) - ourstatus->set_thread_exited (0); + { + ourstatus->set_thread_exited (0); + /* Delete lwp, but not thread_info, infrun will need it to + process the event. */ + exit_lwp (event_child, false); + } else - ourstatus->set_ignore (); - - exit_lwp (event_child); + { + ourstatus->set_ignore (); + exit_lwp (event_child); + } } return ptid;