From patchwork Tue Oct 3 17:56:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 77049 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C55F3858D38 for ; Tue, 3 Oct 2023 17:57:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C55F3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1696355840; bh=m9IZ6fDsxwLg207mi6itdwSYkOH4w+3kpfvrCEZuDTg=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=blJwaLVb06HiVRCUKPsrKbNxfsnbeJM0nAlvBZNGAiaR7FdCIfuqKcGfu8/ruo+2k 80P98GGUxTNy2CQ7nFoTGbhdQgBvAIOfBKCYjZgr1DIG0/EB9VJfX96GoYMI1yxKQF u1fTssUInuxsMa+W2sRAH0p9ksigf+KSJQ+DRe4U= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id DA8C53858C60 for ; Tue, 3 Oct 2023 17:56:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA8C53858C60 Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-3512c43adebso4487075ab.3 for ; Tue, 03 Oct 2023 10:56:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696355787; x=1696960587; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m9IZ6fDsxwLg207mi6itdwSYkOH4w+3kpfvrCEZuDTg=; b=nndcDvy4SMZMDJCZzvVEw21D0lhyRvOvMi4M6Af+ScTdEyq0D8rGZMpkpnEpjVghFr k7QICW/RenZjsitcZUE95Ak2Dyd8jxImoP6eDJ+JnV6umN4NY20T4Pey0g3rBIXiXnF+ hOnGGfbo2Ew6rw97Mige4uzVoVxnCeWVX8Ku3+3BARGSPfaICmfvHiZS10g3rPtU5wy5 FpeipCTUrdjEdGkQdD9W10vc8r+5JOyOHPD/HOhG6CMoRtZcw8j67sgUzeykIBKXfEpO Tx/lxzAokoCqwZrcuQl2WfCMnFPT3fUT0qQdv245WUqErwOC5P9/8iqDnMw0vwLa0fXq LlGQ== X-Gm-Message-State: AOJu0Yx/tjZIn/sHqXr41mPp7LfDrgUu5ZoqZf5vKt6h57DoeOU0ZZ1x 38v/wblw7yXvTIqaMGKweigiFCynLoO9aXOO+dHikQ== X-Google-Smtp-Source: AGHT+IF7Z9IzG8ufQz/Dqh9uyErHV7spRQAPSvMmCYZHAmSh52K3Mp++7NadFHFxnhevNVKw2NoDAA== X-Received: by 2002:a05:6e02:1a2c:b0:351:5629:1ca8 with SMTP id g12-20020a056e021a2c00b0035156291ca8mr222875ile.6.1696355787242; Tue, 03 Oct 2023 10:56:27 -0700 (PDT) Received: from localhost.localdomain (71-211-130-31.hlrn.qwest.net. [71.211.130.31]) by smtp.gmail.com with ESMTPSA id t9-20020a028789000000b0042b326ed1ebsm486965jai.48.2023.10.03.10.56.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 10:56:26 -0700 (PDT) Date: Tue, 03 Oct 2023 11:56:23 -0600 Subject: [PATCH 2/3] Use gdb_dir_up in linux_proc_attach_tgid_threads MIME-Version: 1.0 Message-Id: <20231003-attach-bug-v1-2-f5de2e583c5d@adacore.com> References: <20231003-attach-bug-v1-0-f5de2e583c5d@adacore.com> In-Reply-To: <20231003-attach-bug-v1-0-f5de2e583c5d@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.5 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: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This changes linux_proc_attach_tgid_threads to use gdb_dir_up. This makes it robust against exceptions. --- gdb/nat/linux-procfs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c index 95ecae443e4..c7d8ba2bd67 100644 --- a/gdb/nat/linux-procfs.c +++ b/gdb/nat/linux-procfs.c @@ -275,7 +275,6 @@ void linux_proc_attach_tgid_threads (pid_t pid, linux_proc_attach_lwp_func attach_lwp) { - DIR *dir; char pathname[128]; int new_threads_found; int iterations; @@ -284,7 +283,7 @@ linux_proc_attach_tgid_threads (pid_t pid, return; xsnprintf (pathname, sizeof (pathname), "/proc/%ld/task", (long) pid); - dir = opendir (pathname); + gdb_dir_up dir (opendir (pathname)); if (dir == NULL) { warning (_("Could not open %s."), pathname); @@ -300,7 +299,7 @@ linux_proc_attach_tgid_threads (pid_t pid, struct dirent *dp; new_threads_found = 0; - while ((dp = readdir (dir)) != NULL) + while ((dp = readdir (dir.get ())) != NULL) { unsigned long lwp; @@ -321,10 +320,8 @@ linux_proc_attach_tgid_threads (pid_t pid, iterations = -1; } - rewinddir (dir); + rewinddir (dir.get ()); } - - closedir (dir); } /* See linux-procfs.h. */