From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sddYGroY4mnGTR4AWB0awg (envelope-from ) for ; Fri, 17 Apr 2026 07:25:46 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fzJx7KGK; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 678281E0B1; Fri, 17 Apr 2026 07:25:46 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=unavailable autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D2D151E0B1 for ; Fri, 17 Apr 2026 07:25:45 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id C45B54BAD14A for ; Fri, 17 Apr 2026 11:25:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C45B54BAD14A Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fzJx7KGK Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id DBBDB4BA23FA for ; Fri, 17 Apr 2026 11:25:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DBBDB4BA23FA Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DBBDB4BA23FA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776425116; cv=none; b=YwbiY54MSNUCtOWEYL7H7d6Y+FQ4peVA+KEJ0kMW9sHCOBwLWmXAraapnFblLSUyKog+cMVy3yG46JG872FbI1kDH+HtympWWeSax/vUVfOiY7LU8KeiyY6BQT5SzrDiz9bN06W1TWg8bT2OSijWEkmrlSPNLasxDvK6b/1f+4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776425116; c=relaxed/simple; bh=GUB7T5n5+5cp2/HqJ93QVRtWGc7CS6vWLrXrRMvoERE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=CcTRvs8xN0x4MySRMMg/TWTkOXXskJlAT2m6muFOnSyhmTWumuvfD5JUuyDtWoWVha71zCcMpbHd0Nz+KGY2B862lLCIsiG9zVz6KEcDONvNovnL2MVwI5T4g+s/w1vK54aYP55uP/uCM+mb2J4EQIiYrMdJhxekh3k/Kd54Mo4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DBBDB4BA23FA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776425114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7OLqx6GuW42+4IF9oSEUS4BwirDxlddqAvWFvURKxjs=; b=fzJx7KGKkkCs184/Z7qd8U4nL6TN0DrPzyEOgGhfr8tc+uJPxvuPXrfOC9pSIEsZ/YPmfJ bV1XJPXn4trnOCCB6WbauuE+iAraTQEpnhumz3DaHgIA6SB665iimhcZrAcM+Y3ugJTitI DYcTieoVAKSH82y51rdF1fK8BSGnuts= 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-546-asbrxwa2NPW6Fo2sVpMWjw-1; Fri, 17 Apr 2026 07:25:13 -0400 X-MC-Unique: asbrxwa2NPW6Fo2sVpMWjw-1 X-Mimecast-MFC-AGG-ID: asbrxwa2NPW6Fo2sVpMWjw_1776425112 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-488c0120047so3320945e9.0 for ; Fri, 17 Apr 2026 04:25:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776425112; x=1777029912; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7OLqx6GuW42+4IF9oSEUS4BwirDxlddqAvWFvURKxjs=; b=NPQ5bYvDPyXPH+cT8hwgvVZhuL22u1p2ePjtSEuScSXH7f2TeILiH9htm7QJsxMt3e bLQ9V2TzP/6EWYL6Yog6dtAtbN9n3Uwo5w4k1Plo86CgSp49Dm/Zhvy0n46rd0mhQVrq jluXpS2QwSlnjokI/65x0zNEg98D/j1m1OPp7OnAqHZbh0fQ8u8wz77UXf7YEd+dFkSU G2Lt2lTz/8rb5elMedcHE0iQ1DuKdClB29n1/xoYJhdbwvSFRSHjKUl/+WrgFczTlC/q o6zq0TE8FYnwRmk9cnyRSA0MBZohnZbo5tRO5k52hwbnRkoe+kV9RsCbg7PFad0Ori27 W4JQ== X-Forwarded-Encrypted: i=1; AFNElJ/eMh0nVmF4H+kaI7oklkZe8G/Tnna59aVAJJdsBkbpsOt97G9ZDfbDQ8Wef7AlnRwxIVMRuf+YUARFcQ==@sourceware.org X-Gm-Message-State: AOJu0YzXfzXtQrBytLQcZtCPvkBT1v77GSdemRxq1FEpX2Ym6f6hnkB6 ZLum8Sr/5IP7xAZL//NYHywYn27mjZn6wN0t8Cn/ncKrMN1ks1cxY3mHU7ha+/sqRQLtNCJF2Fb y8ZmgRVDomrRd+VEBBW+XuBAuvHPGdRQgyC7NXWNlJxDLKgdKHUtWE28yJ0fnHCuWKret9cw= X-Gm-Gg: AeBDiet09+WB3vuhZ0sMsrsqEqfsGpxcpbfvfJpxZa71zk55No03CxfTHWIl2c60gys U4IFqUHIbwIt3pzY3Hwm93ahLlRrZ43AnPSMJjdyHhPPUihIW2jgE9HUPQ6Y4jrc86yXnNxJ0yH 5mVPNqKqQtogf8yS9Lc6mwM2t2ryBNjeT7+/O3N5DBCIFb6ZOpXVD0pEM3qUQIz3j8ZV1XmHw8a 2KJcNeFXygooHgiSYAI9esOq+rgyZR+G3XUACb2/ui5a6ciaEFmK7oG7ghk4lnbRG8Qm4o1B0cr gR5kb1QbO+gRSaypqVt+BfenFgEcUkRudXX7zVfpKFo5PR7LbklWE6whlxyE4FYqpvGUfy/vuMx lp4m8dldRWK9vMBj5Hcd5uGny8xI= X-Received: by 2002:a05:600c:46cb:b0:488:a723:ea53 with SMTP id 5b1f17b1804b1-488fb744fbemr35190045e9.7.1776425112091; Fri, 17 Apr 2026 04:25:12 -0700 (PDT) X-Received: by 2002:a05:600c:46cb:b0:488:a723:ea53 with SMTP id 5b1f17b1804b1-488fb744fbemr35189305e9.7.1776425111553; Fri, 17 Apr 2026 04:25:11 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488fb7b25c9sm14933375e9.29.2026.04.17.04.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2026 04:25:10 -0700 (PDT) From: Andrew Burgess To: Simon Marchi , gdb-patches@sourceware.org Cc: Simon Marchi Subject: Re: [PATCH 05/11] gdb, gdbserver: split iterate_over_lwps in for_each_lwp and find_lwp In-Reply-To: <20260416202408.422441-6-simon.marchi@efficios.com> References: <20260416202408.422441-1-simon.marchi@efficios.com> <20260416202408.422441-6-simon.marchi@efficios.com> Date: Fri, 17 Apr 2026 12:25:09 +0100 Message-ID: <87mrz1esmi.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 8GF4pvIHZSa1Pv-apY-xzM-VJePcmlOptcNax_gG9Js_1776425112 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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~public-inbox=simark.ca@sourceware.org Simon Marchi writes: > From: Simon Marchi > Subject: Re: [PATCH 05/11] gdb, gdbserver: split iterate_over_lwps in for_each_lwp and find_lwp The subject line should say 'into' maybe? > > Even though it works, I have always been mildly annoyed by > iterate_over_lwps being used for both iterating over all lwps and > finding one lwp matching a criterion. I think it would be clearer to > have two functions for the two use cases. Then it would be 100% clear > at the call site what the intention is. It would be clear that a > callback returning bool is meant to be a predicate for the find > function, while a callback returning void is meant to be a callback for > the "for each" function. > > Therefore, split iterate_over_lwps in two: > > - find_lwp to find the first lwp matching a boolean predicate (and the > given ptid filter) > - for_each_lwp to apply a function on all lwps (optionally filtering by > ptid or pid) > > The callbacks given to for_each_lwp can now return void. > > Introduce some overloads for for_each_lwp, for the various common use > cases: > > - filtering by ptid > - filtering by pid > - no ptid/pid filter > > find_lwp and two overloads of for_each_lwp are actually only used in > gdb/linux-nat.c, so make them local to that file. Only the pid variant > of for_each_lwp is used in shared code. > > The pattern used in this patch serves as the basis for subsequent > patches that split other "iterate over" functions the same way. > > Change-Id: I49d3af0916622300cc81e3c32d22e1aff13cf38f > --- > gdb/arm-linux-nat.c | 38 ++-- > gdb/linux-nat.c | 276 +++++++++++++++-------------- > gdb/nat/aarch64-linux-hw-point.c | 17 +- > gdb/nat/linux-nat.h | 16 +- > gdb/nat/loongarch-linux-hw-point.c | 18 +- > gdb/nat/x86-linux-dregs.c | 15 +- > gdb/ppc-linux-nat.c | 22 +-- > gdb/s390-linux-nat.c | 22 +-- > gdbserver/linux-low.cc | 20 +-- > 9 files changed, 208 insertions(+), 236 deletions(-) > > @@ -2940,7 +2953,7 @@ select_event_lwp (ptid_t filter, struct lwp_info **orig_lp, int *status) > > /* Return non-zero if LP has been resumed. */ This comment needs updating now a bool is returned. > > -static int > +static bool > resumed_callback (struct lwp_info *lp) > { > return lp->resumed; > diff --git a/gdb/nat/linux-nat.h b/gdb/nat/linux-nat.h > index 42c0467191fe..4414749b93de 100644 > --- a/gdb/nat/linux-nat.h > +++ b/gdb/nat/linux-nat.h > @@ -46,17 +46,15 @@ extern tribool have_ptrace_getregset; > > extern ptid_t current_lwp_ptid (void); > > -/* Function type for the CALLBACK argument of iterate_over_lwps. */ > -using iterate_over_lwps_ftype = gdb::function_view; > +/* Function type for the CALLBACK argument of for_each_lwp. */ > > -/* Iterate over all LWPs. Calls CALLBACK with its second argument set > - to DATA for every LWP in the list. If CALLBACK returns nonzero for > - a particular LWP, return a pointer to the structure describing that > - LWP immediately. Otherwise return NULL. This function must be > - provided by the client. */ > +using for_each_lwp_ftype = gdb::function_view; > > -extern lwp_info *iterate_over_lwps (ptid_t filter, > - iterate_over_lwps_ftype callback); > +/* Iterate over all LWPs, calling CALLBACK for every LWP. > + > + Only consider the LWPs with that pid. */ Maybe: "Only consider the LWPs that match PID." would be better? > + > +extern void for_each_lwp (int pid, for_each_lwp_ftype callback); > > /* Return the ptid of LWP. */ > Approved-By: Andrew Burgess Thanks, Andrew