From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iX6uIsgdcGooOgEAWB0awg (envelope-from ) for ; Mon, 03 Aug 2026 00:49:12 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=bvt1T22v; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8A2031E09E; Mon, 03 Aug 2026 00:49:12 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 019911E033 for ; Mon, 03 Aug 2026 00:49:12 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 222DE4BB1C1A for ; Mon, 3 Aug 2026 04:49:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 222DE4BB1C1A Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=bvt1T22v Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by sourceware.org (Postfix) with ESMTPS id AD64A4BB1C06 for ; Mon, 3 Aug 2026 04:48:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD64A4BB1C06 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AD64A4BB1C06 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785732526; cv=none; b=KRQ0szzYNhgYQaem82t6u+gaMuYTFWMh4FoVdePYL3uCsGC2sF8RhueIPxF1VEBjL4MSsK/WT2D4AlpZiLHyUgvKB7JRE5mqT0LZlVVEtauh55LPOVXCccFPT5YNtFpED7/++Nsa8/b7lfc5U5/gO7c3m5oYM5Mc5y8+6ixREKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785732526; c=relaxed/simple; bh=u+IXhDNPKFIRwp0knXvzezD3Q2WlXt1sXsKs+TczWOc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Qe8BSRGIEnbiDxncGrQtoxOlwq6D3GYHNuCVSCQh6ytRjtjHan5aIf6XtA6FIB2SJB+UfICczv4WbnDSWJZhMeM2GCiqbLY86bvfpVA6ikUNkOfVaIBvq+vjG19Q+1KZbz48aMBRGIebdtRaD4OQ8yhJDoOqn8SLVrYmSI6y3MY= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=bvt1T22v DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD64A4BB1C06 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-81ed2a06b9eso24341687b3.3 for ; Sun, 02 Aug 2026 21:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1785732526; x=1786337326; darn=sourceware.org; h=content-type:mime-version:message-id:date:user-agent:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=XKS+/+IshKhVISnO9knyxGsDDhlLPm1NWk4fwSfU4mw=; b=bvt1T22vQ3sU5USb1eA3GsiQs/KRQaNLBmYXA3/eI4/dSe26+aoiGFqrKvbINcHY8M Z+CJvSoyAG1YbTaKJWZrR9V3X40AeBgZfD6Q0WOJf5qKR4MX0h9iuie5f3ETwdDFoJlY 87GcR1/q0Zei7yAQbJPhhijxG82G+jevKuFc93H9N3e8VEWWlP7q4DgK2Oi5i2rFg2h1 CrX8Vk8oite7oSgn5WtazOkKmolr5UXglJeM+Mhj6s97ZbZyYgP0wkwFOcMJfiOp9zch 8+D3DgrSlWlfvgaYUiw5fGricMr99/p9UUOppvLY+4Om4lcriLKBtw9uW7bZwj9uHV1C 1ioQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785732526; x=1786337326; h=content-type:mime-version:message-id:date:user-agent:references :in-reply-to:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=XKS+/+IshKhVISnO9knyxGsDDhlLPm1NWk4fwSfU4mw=; b=rYSto/kkdoURXWfFKVT1rvFLxuZaZxw2O1vgG48HV5ESmgfFhd/43wRH+qKesqNula /IVG3Taou578FbgeSRDkvDN8XohkNO1lRw2Lw78ygklMrjOQZNqfjsrfAwki6K4yfDqH r77ke1VYzMaBb3D+cV1AcKzdyXP0LPsd2o0xF2d4nzQV7DjlGZJQuSuhVkY3wvXJN7Mm rWjs+wb5PV1Cq3smpPaeMLALpnFKbrDTfcwkC0Z/ukWcus7VFKb+T46/w/hmJ1WMAUhJ ddXqBeQxWulVRwqZvGVriM6JNVAOjQ3IvffqJG5kyipibX/6gGTjAMiKKinByVxISEf2 kFXQ== X-Gm-Message-State: AOJu0Yxczx2HkKXAuQ0tYS9I4y567x6/TAS6UI16Ax/yqqlJb2tS54kO 4Zttjoj3PYzj+u63ZQW36t2Sn65YJXN3MCNyLUgu2m2cZ2qer+1geBk/8HD3NK54V8TYMMFn7Dc x7YJ+ X-Gm-Gg: AR+sD12+pnmdlQvqkjhus7Zri0MMsCgfJY1lthHcRBOfmM9QkMtkqQB1qHV5FeEHvjo pJGguS8YcwdkwYVvLdsLtHS9KnMGgLhB0LIyrm65C7QaMv4G4tmkifMnJyxM6xhpHSirZsNTjS8 lNptis81S8FfE9JdoEuHN14aKHbzDaLYBVbzYhNKGyCqk7PklhBQR0yuEoMqQGz7SyWVBsGzrDK 6ARN2R3ZJL/rC7b2sIsig+gxtKbdWF/aV/oTdT+8Zy6gOoZqvdYgNj9m8xOEjIf0aUQW+XoaHXW EiAT8zDBUR/eYUGZlSWfnvd9GOOiSEWnbVdnoWdP1CdAiJM3k28xeXEEnrfQ7fw98F3qtXDmMjq 6zFWI5oYf8Whs1LygCwbVQ5vxpIlmxmbpwBrm6HHsmjWsi01b1IYIZ/EsEdYBmy7SCm+/bzj9SP 6oBcQCtiyrMrpw9SC5rmzMsLfmfbYn1NyLYRRh/bAXWCnmJ5CY1tdOj9SLEGsg0Ds+rs7dTQM= X-Received: by 2002:a05:690c:6811:b0:81d:5155:2149 with SMTP id 00721157ae682-81fd49b4b6amr125033707b3.4.1785732525968; Sun, 02 Aug 2026 21:48:45 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8083:f04c:42e3:5943:38f6]) by smtp.gmail.com with ESMTPSA id 00721157ae682-81fccf2e4e9sm53218557b3.7.2026.08.02.21.48.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2026 21:48:45 -0700 (PDT) From: Thiago Jung Bauermann To: Matthieu Longo Cc: , Luis Machado , Luis Machado , Simon Marchi Subject: Re: [PATCH v1 2/2] gdb: rely on the first non-exited thread TPID when reading Linux procfs files In-Reply-To: <20260728143317.245389-3-matthieu.longo@arm.com> (Matthieu Longo's message of "Tue, 28 Jul 2026 15:33:17 +0100") References: <20260728143317.245389-1-matthieu.longo@arm.com> <20260728143317.245389-3-matthieu.longo@arm.com> User-Agent: mu4e 1.14.2; emacs 30.2 Date: Mon, 03 Aug 2026 04:48:43 +0000 Message-ID: <87tspb3j2s.fsf@linaro.org> MIME-Version: 1.0 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 Hello Matthieu, Matthieu Longo writes: > On Linux, /proc/ is keyed by the thread-group leader PID. When > the leader has exited, some /proc//... entries become unavailable > even though another thread is still alive. This can happen, for instance, > when the main thread calls pthread_exit() and another thread continues > the execution (existing test: gcore-stale-thread). > > This causes GDB to fail to read procfs entries such as cmdline, cwd, > exe, maps, and smaps when it uses 'current_inferior ()->pid' after the > thread-group leader has exited. > > Fix this by adding inferior::first_non_exited_thread(), which returns > the PTID of the first non-exited thread of the inferior. Use its LWP ID > when accessing procfs entries that only need a representative live LWP > belonging to the process. > > This is a best-effort choice of a thread that is expected to still exist > in the target. Since GDB's view of the threads list may be stale, the > selected thread may already have exited by the time it is accessed. > Callers must therefore still be prepared to handle that case. > > Update the following functions: > - linux_info_proc > - linux_process_address_in_memtag_page > - linux_find_memory_regions_full > - linux_fill_prpsinfo > - linux_address_in_shadow_stack_mem_range > to use the first non-exited thread's LWP ID instead of the inferior PID > when constructing procfs paths. > > Add a new test in gdb.threads. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31207 > --- > gdb/inferior.c | 12 +++ > gdb/inferior.h | 11 +++ > gdb/linux-tdep.c | 90 +++++++++++++------ > ...access-procfs-while-thread-leader-exited.c | 48 ++++++++++ > ...cess-procfs-while-thread-leader-exited.exp | 78 ++++++++++++++++ > 5 files changed, 211 insertions(+), 28 deletions(-) > create mode 100644 gdb/testsuite/gdb.threads/access-procfs-while-thread-leader-exited.c > create mode 100644 gdb/testsuite/gdb.threads/access-procfs-while-thread-leader-exited.exp Reviewed-by: Thiago Jung Bauermann Just one nit: > diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c > index 8c53ffd5e89..9bdcc55a0e1 100644 > --- a/gdb/linux-tdep.c > +++ b/gdb/linux-tdep.c > @@ -457,6 +457,44 @@ linux_has_shared_address_space (struct gdbarch *gdbarch) > return linux_is_uclinux (); > } > > +/* Return a PTID that identifies the current process and can be used to > + access procfs safely. > + > + The returned PTID is that of the thread-group leader whenever it is > + still alive. If the leader has already exited, the PTID of the first > + non-exited thread in the current inferior is returned instead. > + This ensures that the returned PTID always refers to a live thread > + whose procfs entries are present and populated. */ > +static ptid_t > +get_process_reference_ptid (bool verbose = false) > +{ > + /* Get the current thread. */ > + thread_info *thr = inferior_thread (); > + > + /* Construct the PTID of the thread-group leader. On Linux, > + the leader's LWP ID is equal to the process ID. */ > + ptid_t leader_ptid (thr->ptid.pid (), thr->ptid.pid ()); > + > + /* Use the thread-group leader if it is still alive. Otherwise, use > + the first thread that has not exited. */ > + thread_info *leader_thr > + = current_inferior ()->find_thread (leader_ptid); > + ptid_t ptid = (leader_thr == nullptr > + ? current_inferior ()->first_non_exited_thread () > + : leader_ptid); > + > + if (!verbose) > + return ptid; > + > + if (leader_thr != nullptr) > + gdb_printf (_("process %d\n"), leader_ptid.pid ()); > + else > + gdb_printf (_("process %d [Note: information where gathered from LWP %ld " \ s/where/was/ Though actually IMHO it reads just as well with s/where //. > + "as the thread-group leader (LWP=%ld) already exited.]\n"), > + ptid.pid (), ptid.lwp (), leader_ptid.lwp ()); > + return ptid; > +} > + > /* This is how we want PTIDs from core files to be printed. */ > > static std::string -- Thiago (he/him)