From patchwork Thu Mar 21 23:11:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 781597 Delivered-To: patch@linaro.org Received: by 2002:adf:cf01:0:b0:33e:7753:30bd with SMTP id o1csp1080011wrj; Thu, 21 Mar 2024 16:19:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVH47Rpg3EU/slgrlSwwUqv0seynHexukNXeHOvMI2QUrkKRLWR2Uz6bkQYLSlbfvm8hIQCXTjhNhR85+tuDyzn X-Google-Smtp-Source: AGHT+IF4+aFjEUxKhzuKMISFPVKdzo/uETUIillJSL6gK++UzQhJ+ivZ5F4zBcx5frHm64xe4gdR X-Received: by 2002:a25:b21d:0:b0:dc7:4854:1b1e with SMTP id i29-20020a25b21d000000b00dc748541b1emr674319ybj.54.1711063182058; Thu, 21 Mar 2024 16:19:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711063182; cv=pass; d=google.com; s=arc-20160816; b=ruzQeQKznCryAmnv2BTtPqbrxlzdwAwkNzgXdcRyvI6GGmOsN416u9Mb3fTIyP8H2g otbmmWZeM/B5Dz8dbIN08SoFNJkEn3c+9ePFXhnRVADqZhTj6eB3sqm0iTOprQfwndaI VGVwYv4pdungrQtw948YQmOn4hl44Q4lyRtGmnKMei2dSDRWxdsEKcRktpXaLouw7W5K 2b1B+5toDwmb57UeIMFS6t08FWGzkOMu+NvbH0THW3JIKqihD9k18gPwD1yip5OFebrK YbUt2q3bfySjrLLSFM4nQ5ddFbO8XAxqCuQEAu8w3cK8I0Yt1dANgiyAL7+2kriWayzZ Z97g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=Ii9Tppm+h0NUn2okDBnn43pxmy2QsohdlV0FH6w6L+c=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=bavtUcGw7lIrRqQhSVoEA3t47+VaDSvb5/c1wJYYVijgJmlckuZb1b2cI1pZnGnUit jRl6JQsekrDkc6QzvcXgX9ORq2W6dKegTFcK9wn1qeEVNcBqURjAcn22c4dcIqjE7LxA zkLhGzq2yown0fkyCTmlnx2vgLSYkOAK9lDnW+zFpn72zsjJbwT08t1NfDxZmf1Bx6gx EAP1t0YQXTxSO4aYq/u241y9qVGeyOudf62/HFY9bCHX8RPeWT2xvtaKv4twEUUlEkoH pwE8loKxRIbUGuw65z4xDQfe3Yec+filB6nZjXrVhAZuvQMyA+OsPdSia6JAo7oIxbar GY5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xsFBTy2+; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v16-20020ac85790000000b00430d738da53si811773qta.135.2024.03.21.16.19.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 16:19:42 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xsFBTy2+; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B53F43858D28 for ; Thu, 21 Mar 2024 23:19:41 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-vk1-xa2a.google.com (mail-vk1-xa2a.google.com [IPv6:2607:f8b0:4864:20::a2a]) by sourceware.org (Postfix) with ESMTPS id 18A813858D28 for ; Thu, 21 Mar 2024 23:19:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 18A813858D28 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 18A813858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::a2a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711063164; cv=none; b=cRuVViA5AyonoI1+uJOJrNimAD0U3rVY7dK9fy7OmyfPZX5GDqGe42Hnswxcbg2SKHRwU3FyCB6ctDNqKDnFmiWwROe+5gcfQ/0bRMtt9w+yZT9v8D+d+a6qvveFTLqlTKBHsFFN3OGV+9hCVeCiXxHEIEXMOcC5c+MKUt6PGiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711063164; c=relaxed/simple; bh=cSbphJ1LC3FBkmjUtwQCyiFr3lNZmJYbxFDuoOguxo4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Nq66UF2Ino/ozoXq5g0kCxGTp6Ff+cglJJTLMaRu1LRtMW61dNqIMldsftStlxBP40TZi803zlS9UqOx7gZZFc87aO90eHkgRfP2h7mUVUguZLxWcuC8X7Avz45t+EbZuhKZ6mmV+k3OjsgllvlbQ52lTj4gzmXWkZbW5g3Iy6s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-vk1-xa2a.google.com with SMTP id 71dfb90a1353d-4d42ea640f0so551181e0c.3 for ; Thu, 21 Mar 2024 16:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711063161; x=1711667961; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Ii9Tppm+h0NUn2okDBnn43pxmy2QsohdlV0FH6w6L+c=; b=xsFBTy2+ncAHCFsgCZczG9LFm3ufxobkFA7cYEI5tEFOzipui+bWyB+CnhA2DFc+H3 oKnKxqI3fnCDPh5V14iSrckM0NeH+2uYN7YZLW5pKx7/RGJLSMsPg7AFuSRM0v3N5SJO jJJovJJp/+/RkpkT2F6ll2UltOjuZP4JWidT+bomLRQEoMnmtIzFmsJ0RPbmxVX3Y/Vg G3onUDPVfwQnBGJLDKEzMNB9Xd+1kQNUgVQcGQjKE+hCqDyqUBf+8SqvY4Tw71ZPj7X1 otuEv2/Io39qAApqR9Idxd+R4mcgnH0b82Z/B8lBHa4v7i3KlAesHwKOV0VbRF6btP88 Ccxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711063161; x=1711667961; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ii9Tppm+h0NUn2okDBnn43pxmy2QsohdlV0FH6w6L+c=; b=vcsEWbtlWN9mzcDAnBELM2Q0D2b/HZnToa4aQioOgsGYSCeXfMlxWHaY4B8IIb3wv5 TLZCmYR0D8AZgpEHnW2Q5LvNU8bTYuV2MVdadkEgIqbEO1AwqVzj3VvRBnTc5aXWffim 6IIOZAXqxkV1W+WXhA8E7VQKbvikoaz7lw4KEDJ/Ooq5Yi5wcZMn2QU7sz4LxTkWMwgG eWijH3lk8nMkNQRerpH70JrrjqbIKaKyk01W79ozlwWze9h6N+Of15vwMsk7O2rcckaV 5J2DOVWaRokcVLCwIBJLw4mjEllclHwqFRptq1Kxru//JArpZ8SlsnWjNREvWRi3nqGi Q5KQ== X-Gm-Message-State: AOJu0YxgSOcGILkHXX2bGzQGkpjyxkRcIy0cmzDuih0zPGfPTvkyNBjy 7XH5KSb2Vt7YgzNMdc0zIAb7Ky4cNhFXJ87ulLmOk/uWMFg6UEMOO+PZ1U/SvdjjxJLu7AveHnb Z X-Received: by 2002:a05:6a20:bca5:b0:1a3:4469:5967 with SMTP id fx37-20020a056a20bca500b001a344695967mr947826pzb.57.1711062715999; Thu, 21 Mar 2024 16:11:55 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:e28:f7d5:8d63:c544]) by smtp.gmail.com with ESMTPSA id n4-20020a62e504000000b006e64a9104fdsm375185pff.114.2024.03.21.16.11.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 16:11:55 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [RFC PATCH 1/3] gdb/nat: Use procfs(5) indexes in linux_common_core_of_thread Date: Thu, 21 Mar 2024 20:11:47 -0300 Message-ID: <20240321231149.519549-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240321231149.519549-1-thiago.bauermann@linaro.org> References: <20240321231149.519549-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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+patch=linaro.org@sourceware.org The code and comment reference stat fields by made-up indexes. The procfs(5) man page, which describes the /proc/PID/stat file, has a numbered list of these fields so it's more convenient to use those numbers instead. This is currently an implementation detail inside the function so it's not really relevant with the code as-is, but a future patch will do some refactoring which will make the index more prominent. Therefore, make this change in a separate patch so that it's simpler to review. Reviewed-By: Luis Machado --- gdb/nat/linux-osdata.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c index c9192940f236..172fea5cea85 100644 --- a/gdb/nat/linux-osdata.c +++ b/gdb/nat/linux-osdata.c @@ -75,10 +75,10 @@ linux_common_core_of_thread (ptid_t ptid) if (pos == std::string::npos) return -1; - /* If the first field after program name has index 0, then core number is - the field with index 36 (so, the 37th). There's no constant for that - anywhere. */ - for (int i = 0; i < 37; ++i) + /* If the first field after program name has index 3, then core number is + the field with index 39. These are the indexes shown in the procfs(5) + man page. */ + for (int i = 3; i <= 39; ++i) { /* Find separator. */ pos = content->find_first_of (' ', pos); From patchwork Thu Mar 21 23:11:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 781596 Delivered-To: patch@linaro.org Received: by 2002:adf:cf01:0:b0:33e:7753:30bd with SMTP id o1csp1077849wrj; Thu, 21 Mar 2024 16:12:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCURKmDo2+ewbLr+5tRnoeTF0J3gbbqZ+Lw/BrBfd9pnFa44GEf/Tc+ZaKoYMgCwJ5i6X3lyquAACFWSBssQV80z X-Google-Smtp-Source: AGHT+IFO4F4mqktj+ujzcBoqe2Y/FR7i3koyS9wHCxVpOmuSKv2Wv4aKukNC4eFnN/BgpFLm1rro X-Received: by 2002:ac8:59d4:0:b0:42e:cc3d:a257 with SMTP id f20-20020ac859d4000000b0042ecc3da257mr676747qtf.53.1711062764132; Thu, 21 Mar 2024 16:12:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711062764; cv=pass; d=google.com; s=arc-20160816; b=m5VqvXEdx7UK+B8uT8VNWyFLYy/0zl8ATckvljo5+oYvVWx3rrmFEw5L4ovUE/fMg+ 5a4ypD7exrW/MmRFrixumXvr8Ku3Wnvj3VkYtRHDRJn2RVn0L4J3AYO+5ODojGqQxIWh BZHzf7ZM0zc6mRCQS9iL8faJMX4h5lhDRUK8e+62abxh93rtq3Bba6viApZEb4AjNnrs DHM1PrBwsSVAozdBY3Ss8Us1BdAUmXN73dRhJulZaS43jAxOZqL7Pzr/rgUOt0QKQaTC ip1UTcKICBr+wG7DYWH/wrdTNZTP94ZUquG/KSdbL+nD0a76d5XUneBNCRM0W22VUboa wvbg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=7aFAglohWo67xvqz/cY8xqU1zU3/C+glppEcfODGlXc=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=ufEJSW6tSK+YEGz7jzEYCR25O56qfDAZJ744cjZV2xWWp1zMdnRSfrUzHZuEEtez6X CZQWCEDCVELIWjsTCFnPVGeEgNFCXI+1e8pX0ahw55rMpN4jHKaUA4kP55+v+RrR+e24 rY5Gd20sRtUZGrKsx0r3CTQck3MT/PwycMtMxG+OefhKnkt9oUbXhgtGGO5Fns1HKesZ AfQu/ietURVoLtCCosydqf/o/WzH99L1TH5m0Z9c++nwEW0r/mcpLYOKhld+I440szZe wBmXtr9cHtJHopc8AJx5FgJvqPFQ6zc5ZRfWmCvKzWYtWsRbSXvwGr4/+CY4eVV3qI56 Yd7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jhjk6SaN; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d15-20020a05622a100f00b0042f4b96c4f9si811733qte.302.2024.03.21.16.12.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 16:12:44 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jhjk6SaN; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A5CF13858C24 for ; Thu, 21 Mar 2024 23:12:43 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by sourceware.org (Postfix) with ESMTPS id B43EC3858C5E for ; Thu, 21 Mar 2024 23:11:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B43EC3858C5E 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 B43EC3858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711062722; cv=none; b=fyIJfqRcN6D/7Z6CjRX/a9V8LOexjQdAKW1L51XFZ0TMCJm42zW8ikdUactRqdaUdYat/+f1Oo2D5ASOFFQ/M9SStK3Bes8ZAo2dghlDi3xj8nWL3cPZzSnzHqz9HI0iMDNOplkA8Alx+Cl3hSTvdP1YGX6x3CQNSXItHih24PU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711062722; c=relaxed/simple; bh=ygPiGSWnZRknJbrN0UT4y8y1c4WDxffc49lMAMaSVlQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fej2Oxi/Y8QTXc2tbmVaMF0djWZslo6ovY6sYNSZNsQ6KTLVegEYFzd6BZpv6tEkGjQpEv9tKjWRTDN4DsAnee/gtC3OqfrEuiLkiF3IJKDvFl7OjlflT6AtNX+sEIQD9ACAvojBd/JlZnS/7lpyj66ZKyjGrxdHoV3txDLf3U8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-5a480985625so853885eaf.0 for ; Thu, 21 Mar 2024 16:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711062719; x=1711667519; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=7aFAglohWo67xvqz/cY8xqU1zU3/C+glppEcfODGlXc=; b=Jhjk6SaNEnRqiKfPNsUkHjeCJ5pJsFdtDxaBjpcqhI64e9BOIDyrCp0SRvKrSLhVQx O3YE4/qsDJfgwSZP+9dvJCYtN55u8I91vzsz0WsYd2I/5JIk7gXZB8EsiGeHrGgr65GH X+DfpHGXoSOYGVyjEnp211/IJ5wBABrePt+P+bSQ9TA1C7g6yD+fSmz/oZsk80dQjTnK WjhoZ3EUyNCiP+OuRBkb7QE2tbMhSrM84jze9Ru7QUh8C6+cGP5QKYf67pBNlCTd5pFv sq0j0+/Qj1DYlI/DDuJFmHtRv/hcmiuwvtykjnhzEnsaZBHKm7trbAe07S7x9ZAf/lN6 9vAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711062719; x=1711667519; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7aFAglohWo67xvqz/cY8xqU1zU3/C+glppEcfODGlXc=; b=DJFFkKnTeW86cLDx3GZ4bxoXkYJIVNhhXJtFLSsMbme6ZbfaG8E8arbl+UNd7IEZpm OtG6E707BPiKdyH0f0xG68rNbS/jmP55h1z3+lXuuirXANibNUUAe50W8k4uT0PDgGT5 oIbCpfNr8QLBgM2Bnx0VkAgsRWWiDx+DOyYlyyJYlESnMTs2/5T3EVeowhgFO2t6KlPR isJzMq+NZrLdZSKJVzl3wRV/uAbSFZmpY3yngjeNJMyHEAC+ciJg3jvaMQUSwViOh+rh 0phb2b1rG1FHKpfZGKBKSvSiIEr49CpnZbqL8EPPwntXvRNJofdaYoDZqwWe8yJHvgha ONPg== X-Gm-Message-State: AOJu0YwHzWBcC/NGjx4AL1dbI0mA6vhlz74DngUMpOkbV+bguXp4WrYB MPVTXTshc6fpOmHFW5up6aQtZzaEVC3pDxilINUuZHowkYEjbzXqvMjCeKzq3lff0q9Dh2in5TN 7 X-Received: by 2002:a05:6870:8086:b0:222:7404:f3e4 with SMTP id q6-20020a056870808600b002227404f3e4mr776304oab.29.1711062718896; Thu, 21 Mar 2024 16:11:58 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:e28:f7d5:8d63:c544]) by smtp.gmail.com with ESMTPSA id n4-20020a62e504000000b006e8f75d3b07sm367592pff.181.2024.03.21.16.11.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 16:11:58 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [RFC PATCH 2/3] gdb/nat: Factor linux_find_proc_stat_field out of linux_common_core_of_thread Date: Thu, 21 Mar 2024 20:11:48 -0300 Message-ID: <20240321231149.519549-3-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240321231149.519549-1-thiago.bauermann@linaro.org> References: <20240321231149.519549-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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+patch=linaro.org@sourceware.org The new function will be used in a subsequent patch to read a different stat field. The new code is believed to be equivalent to the old code, so there should be no change in GDB behaviour. Also, take the opportunity to move the function's documentation comment to the header file, to conform with GDB practice. Reviewed-By: Luis Machado --- gdb/nat/linux-osdata.c | 43 ++++++++++++++++++++++++++++-------------- gdb/nat/linux-osdata.h | 3 +++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c index 172fea5cea85..c254f2e4f05b 100644 --- a/gdb/nat/linux-osdata.c +++ b/gdb/nat/linux-osdata.c @@ -53,32 +53,31 @@ typedef long long TIME_T; #define MAX_PID_T_STRLEN (sizeof ("-9223372036854775808") - 1) -/* Returns the CPU core that thread PTID is currently running on. */ +/* Returns FIELD (as numbered in procfs(5) man page) of + /proc/PID/task/LWP/stat file. */ -/* Compute and return the processor core of a given thread. */ - -int -linux_common_core_of_thread (ptid_t ptid) +static std::optional +linux_find_proc_stat_field (ptid_t ptid, int field) { + /* We never need to read PID from the stat file, and there's + command_from_pid to read the comm field. */ + gdb_assert (field >= 3); + char filename[sizeof ("/proc//task//stat") + 2 * MAX_PID_T_STRLEN]; - int core; sprintf (filename, "/proc/%lld/task/%lld/stat", (PID_T) ptid.pid (), (PID_T) ptid.lwp ()); std::optional content = read_text_file_to_string (filename); if (!content.has_value ()) - return -1; + return {}; /* ps command also relies on no trailing fields ever contain ')'. */ std::string::size_type pos = content->find_last_of (')'); if (pos == std::string::npos) - return -1; + return {}; - /* If the first field after program name has index 3, then core number is - the field with index 39. These are the indexes shown in the procfs(5) - man page. */ - for (int i = 3; i <= 39; ++i) + for (int i = 3; i <= field; ++i) { /* Find separator. */ pos = content->find_first_of (' ', pos); @@ -91,8 +90,24 @@ linux_common_core_of_thread (ptid_t ptid) return {}; } - if (sscanf (&(*content)[pos], "%d", &core) == 0) - core = -1; + /* Find end of field. */ + std::string::size_type end_pos = content->find_first_of (' ', pos); + if (end_pos == std::string::npos) + return content->substr (pos); + else + return content->substr (pos, end_pos - pos); +} + +/* See linux-osdata.h. */ + +int +linux_common_core_of_thread (ptid_t ptid) +{ + std::optional field = linux_find_proc_stat_field (ptid, 39); + int core; + + if (!field.has_value () || sscanf (field->c_str (), "%d", &core) == 0) + return -1; return core; } diff --git a/gdb/nat/linux-osdata.h b/gdb/nat/linux-osdata.h index 833915cdb2fd..a82fb08b998e 100644 --- a/gdb/nat/linux-osdata.h +++ b/gdb/nat/linux-osdata.h @@ -20,7 +20,10 @@ #ifndef NAT_LINUX_OSDATA_H #define NAT_LINUX_OSDATA_H +/* Returns the CPU core that thread PTID is currently running on. */ + extern int linux_common_core_of_thread (ptid_t ptid); + extern LONGEST linux_common_xfer_osdata (const char *annex, gdb_byte *readbuf, ULONGEST offset, ULONGEST len); From patchwork Thu Mar 21 23:11:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 781595 Delivered-To: patch@linaro.org Received: by 2002:adf:cf01:0:b0:33e:7753:30bd with SMTP id o1csp1077738wrj; Thu, 21 Mar 2024 16:12:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW9tqL7PjnlvNNnDqzZMNgYpVqDsQnc/POwiaApJhysqWa8E70p9yLWUC26CwJiIdvRSwYrFE7l82NZSpBwiSiy X-Google-Smtp-Source: AGHT+IGwYDi6Yl/k7el9woUe6mFykXvIdR6hBFirq3MV2q6ReZcIym7AcWMGyTz5Cv611UcgR/vv X-Received: by 2002:a05:620a:3bc1:b0:788:6375:4577 with SMTP id yf1-20020a05620a3bc100b0078863754577mr672273qkn.65.1711062747127; Thu, 21 Mar 2024 16:12:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711062747; cv=pass; d=google.com; s=arc-20160816; b=DbszRetvqcsTEVNforEdSGEp3sBi4dfnuW3rTTw6NAAqMREWTza4X99SUhPLyt/DvT /A6mLBjiHcif3C7sPjBNqK1U+xk3JIdDqarumDd6wBGm/6nXSrtQMPgSfR8zYJSqLs3D wWgUJnisrMZbacJWVLHPDX8c5nb0ePKiOGz/be0n8/hGfYx2sFllPIGuvCiMeGG0A3pc LGFfz26hLz2wh4wJ6maD97zrI04uth73/Y2qR27VayMgYgn4zBsZIytBUQwag47sAukx eg1ddLdOvQXKdVXdJBNinNmki62GFTxIXj7gvGY1EsmfjKgHvXnvo4/6puNGI9A/GUct ysLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=a+Z4bhIfz3C2lA0gF6f2QF56TZJlgwzNAgggQlmVHTY=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=0eWjUVGtL5PH4Sl/Z0FFJtgFXcKjQf2+p22wZV+NnyAiw925FnufHSoCtn0yuyRpo9 tRon1mTx4mdESqX2ZBkRQH0OuhJNFx3ba+NbMK9gXcgiA2CQZz21qGnqaBFW0pgpJnpu bm2rgN47uijQoYSqGhdbxoR2eX3T2vK/a9Ub4Tou6SUV+E9jg+cowjxdL01pWasu+adV 8bMZjC6ehrpvrXl622y0yH63CjewbPiQJoifkICpR9Y2CdDTeEIuqQUlyaUCKF8tJY4K gjbOZa1CrW6UFvxhybJdBr9IHokXZtHtobmswdHZZBwuddtdqhwqL9uG5gBRw0EWxfmh pfLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=laS3ar0Z; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e14-20020a05620a208e00b00789febb0f09si772704qka.534.2024.03.21.16.12.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 16:12:27 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=laS3ar0Z; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BCA39385829F for ; Thu, 21 Mar 2024 23:12:26 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 319693858403 for ; Thu, 21 Mar 2024 23:12:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 319693858403 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 319693858403 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::635 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711062726; cv=none; b=K8mrCEBDBLCevBTv9u1nGSi8LeAarWTVzQKy0EjZ2p16GR/JSHldUVynYx0ER65sP8HTIOrJQi31SnCF9E8DfFy40IDI8JsAnJH/Zm8wJnzEPGZ/Z0Siutq6pQOHH2QnF63ZEPSzy9Ju6dmByuQgK+CrTTBM07k4Rw1Xwird+Xk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711062726; c=relaxed/simple; bh=818FEv4/frxkFsGU1SsjCA0NgV1W90ucluEEANX2nH4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kw3ES8nyl/OsfogtfcUXcBmZfYml+z2YuSXXVCAoh8mdy50lZd5eKnwP8xq1fnZTuITVvGSMFAHgJa/pz6uqqHdx7rWedhS4vR6GIt52Sp5Z4Rg5NZGH9zmyLsc73+1T5EQJt7bJCOa89kq+8VrwkAU8155cCYkfztuasQ5cSus= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1df01161b39so11676355ad.3 for ; Thu, 21 Mar 2024 16:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711062722; x=1711667522; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=a+Z4bhIfz3C2lA0gF6f2QF56TZJlgwzNAgggQlmVHTY=; b=laS3ar0ZGVQlZboUAKkaE0mnk71i7sFQ4XKWLOMIZqXsU5c3/JXVbD6jpky7ZN0X4L 4iMi0b4f+k+Va0RCc5rWlvzwRMPgUbkEisxzfoUwGuGJmjFuS5tVwehELdUZ2b7SsIcu M7yo99QFVWIxoqATwjjR+k8i19cVFGRta43hxWWngvON8zPs30qClnwRmmmtCQG3llOq Ym83estK36tiS73Y3P9/ytnwluD+0wp58WoBb0Zhzeht+xieybrN49o6aLWyYYAeEBbf DsD8FEOBLYDmPsDle540ccHws7TBE0dVZepooodzeLuxCgYy/oi+0GkZsnDhCvy1SkFX kpcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711062722; x=1711667522; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a+Z4bhIfz3C2lA0gF6f2QF56TZJlgwzNAgggQlmVHTY=; b=FMj+Co9SaLRouaKKeEtr2VbalNjQK/BCsS00lxwGycbuyXoiC5e4cc+DyXf95OFy14 mNUDDICM9hkw5KMFko3G0qZuUR4MOKi3Cvx3sTkmauY9/8tWGRi3CBYHHKIngaJP6OXR s6vIyAJHqIiPLlGPF4HJ7GbUmVZ/laqkUHqkK8nBEH5hjIvePAn+a/OF+BHkTIOvPP3R PjC6v1HKBeQHCCucOjqKtx59HjoE6ASvzoCxZO3WnkAfw/9atvkuVEn3UwtP2vtCU0dn Rfsx/ntyGG7vVlw9FqlBAP0XHTt4H2sBPxE0dWuqt3jFIlCs6+GUZl2yLXMNb0f59WP9 UuUw== X-Gm-Message-State: AOJu0YwHTbSbTcqgHuNpWiO+xBjs5FjmcNtX+S9809uxJHFgH27Pxoqk GVxuh2ueHDpkJg5orMtpPwuyneauf8FWSvK/LQ/S7W23UprowqsZdhdBhq/niPdT7Nu4kBMsKA9 x X-Received: by 2002:a17:903:2609:b0:1e0:2a5f:5e21 with SMTP id jd9-20020a170903260900b001e02a5f5e21mr940890plb.26.1711062722111; Thu, 21 Mar 2024 16:12:02 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:e28:f7d5:8d63:c544]) by smtp.gmail.com with ESMTPSA id i17-20020a17090332d100b001dd922cbb58sm417977plr.62.2024.03.21.16.12.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 16:12:01 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [RFC PATCH 3/3] gdb/nat/linux: Fix attaching to process when it has zombie threads Date: Thu, 21 Mar 2024 20:11:49 -0300 Message-ID: <20240321231149.519549-4-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240321231149.519549-1-thiago.bauermann@linaro.org> References: <20240321231149.519549-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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+patch=linaro.org@sourceware.org When GDB attaches to a multi-threaded process, it calls linux_proc_attach_tgid_threads () to go through all threads found in /proc/PID/task/ and call attach_proc_task_lwp_callback () on each of them. If it does that twice without the callback reporting that a new thread was found, then it considers that all inferior threads have been found and returns. The problem is that the callback considers any thread that it hasn't attached to yet as new. This causes problems if the process has one or more zombie threads, because GDB can't attach to it and the loop will always "find" a new thread (the zombie one), and get stuck in an infinite loop. This is easy to trigger (at least on aarch64-linux and powerpc64le-linux) with the gdb.threads/attach-many-short-lived-threads.exp testcase, because its test program constantly creates and finishes joinable threads so the chance of having zombie threads is high. This problem causes the following failures: FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: attach (timeout) FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: no new threads (timeout) FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: set breakpoint always-inserted on (timeout) FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: break break_fn (timeout) FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: break at break_fn: 1 (timeout) FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: break at break_fn: 2 (timeout) FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: break at break_fn: 3 (timeout) FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: reset timer in the inferior (timeout) FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: print seconds_left (timeout) FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: detach (timeout) FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: set breakpoint always-inserted off (timeout) FAIL: gdb.threads/attach-many-short-lived-threads.exp: iter 8: delete all breakpoints, watchpoints, tracepoints, and catchpoints in delete_breakpoints (timeout) ERROR: breakpoints not deleted The iteration number is random, and all tests in the subsequent iterations fail too, because GDB is stuck in the attach command at the beginning of the iteration. The solution is to make linux_proc_attach_tgid_threads () remember when it has already processed a given LWP and skip it in the subsequent iterations. PR testsuite/31312 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31312 Reviewed-By: Luis Machado --- gdb/nat/linux-osdata.c | 22 ++++++++++++++++++++++ gdb/nat/linux-osdata.h | 4 ++++ gdb/nat/linux-procfs.c | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c index c254f2e4f05b..998279377433 100644 --- a/gdb/nat/linux-osdata.c +++ b/gdb/nat/linux-osdata.c @@ -112,6 +112,28 @@ linux_common_core_of_thread (ptid_t ptid) return core; } +/* See linux-osdata.h. */ + +std::optional +linux_get_starttime (ptid_t ptid) +{ + std::optional field = linux_find_proc_stat_field (ptid, 22); + + if (!field.has_value ()) + return {}; + + errno = 0; + const char *trailer; + ULONGEST starttime = strtoulst (field->c_str (), &trailer, 10); + if (starttime == ULONGEST_MAX && errno == ERANGE) + return {}; + else if (*trailer != '\0') + /* There were unexpected characters. */ + return {}; + + return starttime; +} + /* Finds the command-line of process PID and copies it into COMMAND. At most MAXLEN characters are copied. If the command-line cannot be found, PID is copied into command in text-form. */ diff --git a/gdb/nat/linux-osdata.h b/gdb/nat/linux-osdata.h index a82fb08b998e..1cdc687aa9cf 100644 --- a/gdb/nat/linux-osdata.h +++ b/gdb/nat/linux-osdata.h @@ -27,4 +27,8 @@ extern int linux_common_core_of_thread (ptid_t ptid); extern LONGEST linux_common_xfer_osdata (const char *annex, gdb_byte *readbuf, ULONGEST offset, ULONGEST len); +/* Get the start time of thread PTID. */ + +extern std::optional linux_get_starttime (ptid_t ptid); + #endif /* NAT_LINUX_OSDATA_H */ diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c index b17e3120792e..b01bf36c0b53 100644 --- a/gdb/nat/linux-procfs.c +++ b/gdb/nat/linux-procfs.c @@ -17,10 +17,13 @@ along with this program. If not, see . */ #include "gdbsupport/common-defs.h" +#include "linux-osdata.h" #include "linux-procfs.h" #include "gdbsupport/filestuff.h" #include #include +#include +#include /* Return the TGID of LWPID from /proc/pid/status. Returns -1 if not found. */ @@ -290,6 +293,10 @@ linux_proc_attach_tgid_threads (pid_t pid, return; } + /* Keeps track of the LWPs we have already visited in /proc, + identified by their PID and starttime to detect PID reuse. */ + std::set> visited_lwps; + /* Scan the task list for existing threads. While we go through the threads, new threads may be spawned. Cycle through the list of threads until we have done two iterations without finding new @@ -308,6 +315,18 @@ linux_proc_attach_tgid_threads (pid_t pid, if (lwp != 0) { ptid_t ptid = ptid_t (pid, lwp); + std::optional starttime = linux_get_starttime (ptid); + + if (starttime.has_value ()) + { + std::pair key (lwp, *starttime); + + /* If we already visited this LWP, skip it this time. */ + if (visited_lwps.find (key) != visited_lwps.cend ()) + continue; + + visited_lwps.insert (key); + } if (attach_lwp (ptid)) new_threads_found = 1;