From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 631C13856976 for ; Thu, 8 Jun 2023 12:27:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 631C13856976 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686227252; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nwydN8NjM2LTypaKqSA1BuHhPM35INaB+J0nvoSsaSo=; b=ShnQRGHu14i6uvNUYGcUfoFyi1E9Wmf9emq39hvRVlQHBUF8ghc15vgtn778DC/8vqEltw efA1tcq3VJKHoEOOiBpHZP6tNC3CYysKNwdQ1CSSjMKOGlFlNiwgApeesrD0aF8j2BeqSU nGtOjvdYbsOALzzs5LmnsB0QfgUYwXE= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-483-dJrgjkM4OUSHYHTqVVwBdw-1; Thu, 08 Jun 2023 08:27:30 -0400 X-MC-Unique: dJrgjkM4OUSHYHTqVVwBdw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3f5ec8aac77so3415595e9.3 for ; Thu, 08 Jun 2023 05:27:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686227249; x=1688819249; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nwydN8NjM2LTypaKqSA1BuHhPM35INaB+J0nvoSsaSo=; b=H7GdQUn9SlhKOK8HI+35BQHOTL96p24pIE3EdAzU4wFZjRIvp3nnk8QXKPCMHis1Lw yeAhFpPNq8ap+aJD2GrxAm/Ggqcvjeb5q2iDs9+36xwxC7VO6b0btU0fKr7Cmm1wlgRA OGDHCO3WnrA4MkSmjPvEE6+Tzze3R6URJwpYVUmo276pPPAMgaUOJVx+PjnjbuntZMbj J24l5q5rInDHjfGuWwJgWB2HmK9DkBr+3kp3P+0keKDuQZPiMAt+KLsnih5xZ4CWFv1t KHw0s8SUTTJbyjpgJIcua7QA7E7IYcaPvXGLWSHyuUtP5suzwN4kf0M6yxmpXhwAEGDU 1dig== X-Gm-Message-State: AC+VfDwyDKaRZKvt1Yme8ieRMgRpAozInEqw8ipjtJ7lvGmh6l7owr8N 2saPvgXYmGqSMLBW7JSTmJd4DsebkuKDKtQn81PcG8ZYDh83+PA8KhO39fM2pe7VkWTz7pXh5KJ K9bROI7sJuoypa95ln3NoPhamcomRpw== X-Received: by 2002:a7b:c448:0:b0:3f6:906:1195 with SMTP id l8-20020a7bc448000000b003f609061195mr1314015wmi.35.1686227249419; Thu, 08 Jun 2023 05:27:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7nLv4jw/nRvlOhTqkNx/BFfqGyeQk5/mL35YgJ2KlLFJb8jS26dq3h/8n7UOy1xLZ2cWpS9A== X-Received: by 2002:a7b:c448:0:b0:3f6:906:1195 with SMTP id l8-20020a7bc448000000b003f609061195mr1313993wmi.35.1686227248992; Thu, 08 Jun 2023 05:27:28 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id z10-20020a05600c220a00b003f60a446fe5sm1854004wml.29.2023.06.08.05.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 05:27:28 -0700 (PDT) From: Andrew Burgess To: Pedro Alves , gdb-patches@sourceware.org Subject: Re: [PATCH 16/31] Move deleting thread on TARGET_WAITKIND_THREAD_EXITED to core In-Reply-To: <20221212203101.1034916-17-pedro@palves.net> References: <20221212203101.1034916-1-pedro@palves.net> <20221212203101.1034916-17-pedro@palves.net> Date: Thu, 08 Jun 2023 13:27:27 +0100 Message-ID: <87ttviyw9c.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,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 List-Id: Pedro Alves writes: > 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. LGTM. Reviewed-By: Andrew Burgess Thanks, Andrew > > Change-Id: I013d87f61ffc9aaca49f0d6ce2a43e3ea69274de > --- > gdb/infrun.c | 31 ++++++++++++++++++++++++++----- > gdb/linux-nat.c | 22 +++++++++++++++------- > gdb/netbsd-nat.c | 1 - > 3 files changed, 41 insertions(+), 13 deletions(-) > > diff --git a/gdb/infrun.c b/gdb/infrun.c > index c100bc70034..6fdffb31884 100644 > --- a/gdb/infrun.c > +++ b/gdb/infrun.c > @@ -4238,7 +4238,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 to > + select and resume them (and that failing), etc. */ > > static void > clean_up_just_stopped_threads_fsms (struct execution_control_state *ecs) > @@ -4256,15 +4261,28 @@ 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); > } > } > } > @@ -5537,6 +5555,9 @@ handle_inferior_event (struct execution_control_state *ecs) > > if (ecs->ws.kind () == TARGET_WAITKIND_THREAD_EXITED) > { > + ecs->event_thread = find_thread_ptid (ecs->target, 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 5fadc82deb0..b576ce60b75 100644 > --- a/gdb/linux-nat.c > +++ b/gdb/linux-nat.c > @@ -898,10 +898,11 @@ 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 = find_thread_ptid (linux_target, lp->ptid); > > @@ -911,7 +912,8 @@ exit_lwp (struct lwp_info *lp) > gdb_printf (_("[%s exited]\n"), > target_pid_to_str (lp->ptid).c_str ()); > > - delete_thread (th); > + if (del_thread) > + delete_thread (th); > } > > delete_lwp (lp->ptid); > @@ -3135,11 +3137,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; > diff --git a/gdb/netbsd-nat.c b/gdb/netbsd-nat.c > index bbadd865823..aa16a6cc5bd 100644 > --- a/gdb/netbsd-nat.c > +++ b/gdb/netbsd-nat.c > @@ -629,7 +629,6 @@ nbsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, > if (print_thread_events) > gdb_printf (_("[%s exited]\n"), > target_pid_to_str (wptid).c_str ()); > - delete_thread (thr); > } > > /* The GDB core expects that the rest of the threads are running. */ > -- > 2.36.0