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.133.124]) by sourceware.org (Postfix) with ESMTPS id B5EC93857019 for ; Thu, 8 Jun 2023 14:17:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B5EC93857019 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=1686233831; 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=QZZ2fptXCYxmTevzCnAXuBYY0+OEqpYcD7wQTUFp4BE=; b=AhCcfQCKoA1FxzCLDk6E4UtAo/fIf8DI+ONNAAqnk8pR6TYtCq2Wzxb6th3mOnl6e1UVwo DS3vgEyf+OY6i25AodXPZII1RnFtZeyqEi3KZUDeVVNOqKsbzJ/LAeeCWVc4ZkBiw9fyka vT6jpmFMUDBu02JJRmn3V5r5lJsDg7k= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-QxXCpCTSODCXcZZkV-7Mtg-1; Thu, 08 Jun 2023 10:17:06 -0400 X-MC-Unique: QxXCpCTSODCXcZZkV-7Mtg-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-30e3ee8a42eso299466f8f.1 for ; Thu, 08 Jun 2023 07:17:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686233825; x=1688825825; 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=MwAE3XXXg8GMvZvdiqMmVEc2Bxl69rhx1EMXXt7otTE=; b=A1yugNQqPQ9BWYcSRZvsX1qwVTZ/fXOjHCGDBFpXQykq1EeHRahhxx1ZGtTEaaDXw4 OFnzNEXnST9AAbEdrgPRgWYTxrprK9EQBXryLhrHigF0P99/RTaasUEFywesW5ErmxfY 1DMXEwuoEAJIocF17f+2ZXFqlMaGEYKuFt8e7hSZMT5I3SQEu/3iW4HXWyEREgbat60C c0RPo/7IvYXz/VB9ypHJix5hXsq75RtBrRgLq5Lzhns/qSxKa0+0ucOvvIc0NBAhKte+ ifVk/f4bTveJEGvb1sRDK08HFcDiQfSTze+s3bhGY5RYOcTJr1gG5ezich3P2n7mjalS ejZg== X-Gm-Message-State: AC+VfDxYwUaRP9IaCmpZmF9GU/91GhpJfE9m2XbX09sAZcVWFgCtD7oV 5FhzKiAJ5blJHnMr673BRWre19BwBE50JshoLIoX28ccdIosWC5wAyOgFUSPPDMTEmxA93AGFfL 4g8dFsC1oomuJ9J975WZDa3YZk/kXUg== X-Received: by 2002:a5d:4751:0:b0:30e:4a0e:1a23 with SMTP id o17-20020a5d4751000000b0030e4a0e1a23mr6709930wrs.28.1686233824843; Thu, 08 Jun 2023 07:17:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5xGxXUzpaZ0Ebl5AKyxsLyRLqiGbTbNNV/gUVdkLJw8YVuW9hvdV1ZX89RGdVRxOmifn1cow== X-Received: by 2002:a5d:4751:0:b0:30e:4a0e:1a23 with SMTP id o17-20020a5d4751000000b0030e4a0e1a23mr6709917wrs.28.1686233824504; Thu, 08 Jun 2023 07:17:04 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id h17-20020a5d4311000000b003048477729asm1721699wrq.81.2023.06.08.07.17.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 07:17:04 -0700 (PDT) From: Andrew Burgess To: Pedro Alves , gdb-patches@sourceware.org Subject: Re: [PATCH 19/31] Implement GDB_THREAD_OPTION_EXIT support for native Linux In-Reply-To: <20221212203101.1034916-20-pedro@palves.net> References: <20221212203101.1034916-1-pedro@palves.net> <20221212203101.1034916-20-pedro@palves.net> Date: Thu, 08 Jun 2023 15:17:03 +0100 Message-ID: <87leguyr6o.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.7 required=5.0 tests=BAYES_00,DKIM_INVALID,DKIM_SIGNED,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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: > This implements support for the new GDB_THREAD_OPTION_EXIT thread > option for native Linux. maybe one day we'll be able to unify the remote native support and GDB's in-built native support. Like the last one, this LGTM. Reviewed-By: Andrew Burgess Thanks, Andrew > > Change-Id: Ia69fc0b9b96f9af7de7cefc1ddb1fba9bbb0bb90 > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27338 > --- > gdb/linux-nat.c | 44 +++++++++++++++++++++++++++++++------------- > 1 file changed, 31 insertions(+), 13 deletions(-) > > diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c > index b576ce60b75..75f81edf20a 100644 > --- a/gdb/linux-nat.c > +++ b/gdb/linux-nat.c > @@ -269,6 +269,18 @@ pending_status_str (lwp_info *lp) > return status_to_str (lp->status); > } > > +/* Return true if we should report exit events for LP. */ > + > +static bool > +report_exit_events_for (lwp_info *lp) > +{ > + thread_info *thr = find_thread_ptid (linux_target, lp->ptid); > + gdb_assert (thr != nullptr); > + > + return (report_thread_events > + || (thr->thread_options () & GDB_THREAD_OPTION_EXIT) != 0); > +} > + > > /* LWP accessors. */ > > @@ -2131,8 +2143,7 @@ wait_lwp (struct lwp_info *lp) > /* Check if the thread has exited. */ > if (WIFEXITED (status) || WIFSIGNALED (status)) > { > - if (report_thread_events > - || lp->ptid.pid () == lp->ptid.lwp ()) > + if (report_exit_events_for (lp) || is_leader (lp)) > { > linux_nat_debug_printf ("LWP %d exited.", lp->ptid.pid ()); > > @@ -2913,7 +2924,7 @@ linux_nat_filter_event (int lwpid, int status) > /* Check if the thread has exited. */ > if (WIFEXITED (status) || WIFSIGNALED (status)) > { > - if (!report_thread_events && !is_leader (lp)) > + if (!report_exit_events_for (lp) && !is_leader (lp)) > { > linux_nat_debug_printf ("%s exited.", > lp->ptid.to_string ().c_str ()); > @@ -3123,10 +3134,11 @@ check_zombie_leaders (void) > } > } > > -/* Convenience function that is called when the kernel reports an exit > - event. This decides whether to report the event to GDB as a > - process exit event, a thread exit event, or to suppress the > - event. */ > +/* Convenience function that is called when we're about to return an > + event to the core. If the event is an exit or signalled event, > + then this decides whether to report it as process-wide event, as a > + thread exit event, or to suppress it. All other event kinds are > + passed through unmodified. */ > > static ptid_t > filter_exit_event (struct lwp_info *event_child, > @@ -3134,9 +3146,17 @@ filter_exit_event (struct lwp_info *event_child, > { > ptid_t ptid = event_child->ptid; > > + /* Note we must filter TARGET_WAITKIND_SIGNALLED as well, otherwise > + if a non-leader thread exits with a signal, we'd report it to the > + core which would interpret it as the whole-process exiting. > + There is no TARGET_WAITKIND_THREAD_SIGNALLED event kind. */ > + if (ourstatus->kind () != TARGET_WAITKIND_EXITED > + && ourstatus->kind () != TARGET_WAITKIND_SIGNALLED) > + return ptid; > + > if (!is_leader (event_child)) > { > - if (report_thread_events) > + if (report_exit_events_for (event_child)) > { > ourstatus->set_thread_exited (0); > /* Delete lwp, but not thread_info, infrun will need it to > @@ -3369,10 +3389,7 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus, > else > lp->core = linux_common_core_of_thread (lp->ptid); > > - if (ourstatus->kind () == TARGET_WAITKIND_EXITED) > - return filter_exit_event (lp, ourstatus); > - > - return lp->ptid; > + return filter_exit_event (lp, ourstatus); > } > > /* Resume LWPs that are currently stopped without any pending status > @@ -4479,7 +4496,8 @@ linux_nat_target::thread_events (int enable) > bool > linux_nat_target::supports_set_thread_options (gdb_thread_options options) > { > - constexpr gdb_thread_options supported_options = GDB_THREAD_OPTION_CLONE; > + constexpr gdb_thread_options supported_options > + = GDB_THREAD_OPTION_CLONE | GDB_THREAD_OPTION_EXIT; > return ((options & supported_options) == options); > } > > -- > 2.36.0