From patchwork Sun Sep 29 18:52:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 98135 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 4AD86385F01B for ; Sun, 29 Sep 2024 18:53:27 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id 25D92385E45C for ; Sun, 29 Sep 2024 18:52:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25D92385E45C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 25D92385E45C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727635972; cv=none; b=LRhMB578DuWz418lNb1T+Cw+XebH7Q16urCs96UCUO2GtwfFZWrQaoibL3O9+zIKYDvAOMaMz702ok6ZWdpVqAByjxAeC573vkbnrn1n78pqYHyCEvHnfuYfA0/ClMPadFj/XR+PPy2rWtJkZwN5LpV7MMLaYXMWWfktthbqi/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727635972; c=relaxed/simple; bh=kiRUYI43/J3vBnzuYHSnJOk73cGdhzEju+pnTokBGKk=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=EHuBG5PkNhL+RLQc0YpGxjI1VArzZyXtxciOfNUU/0narlnqX+++G0S3waVMebHJRwuo4b5nL0j9fj7BNxwpYT04bvaWp1XdJIbO9WRhACzeVWAWRFXlxEaJcprIgsv4J5zWGhI16aIkBAQnMwCL57w6l/zHaUvMP2nKdBNGhYU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5001a.ext.cloudfilter.net ([10.0.29.139]) by cmsmtp with ESMTPS id uyr4ssX8RnNFGuz2HshzDD; Sun, 29 Sep 2024 18:52:49 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id uz2GsTM9qmNYjuz2HsqBow; Sun, 29 Sep 2024 18:52:49 +0000 X-Authority-Analysis: v=2.4 cv=fb9myFQF c=1 sm=1 tr=0 ts=66f9a201 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=EaEq8P2WXUwA:10 a=ItBw4LHWJt0A:10 a=CCpqsmhAAAAA:8 a=ZZ7sXkSqYycp381gWdsA:9 a=QEXdDO2ut3YA:10 a=ul9cdbp4aOFLsgKbc677:22 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=d2NX0SUt8BmkSwGbm0wpDHWbqpUbexLrU6ITSSMDzfA=; b=j4gZCHUkyMgqnTo3OZsccp4tVu CAzRWqeH1z6bQa7/lRLpKlVo2sZ6G/3yD31xybY0qx37AXzgM6WSacDzsQ7pDCriSqV1GleGeXLe0 m2EdeR5x6MFlUK7W2HhHdVTlc; Received: from 97-118-34-56.hlrn.qwest.net ([97.118.34.56]:52182 helo=prentzel.local) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1suz2G-000ox4-2D for gdb-patches@sourceware.org; Sun, 29 Sep 2024 12:52:48 -0600 From: Tom Tromey Date: Sun, 29 Sep 2024 12:52:45 -0600 Subject: [PATCH 1/3] Pass current directory to gdb_abspath MIME-Version: 1.0 Message-Id: <20240929-pr-31716-capture-openp-v1-1-ee6bd616d3bf@tromey.com> References: <20240929-pr-31716-capture-openp-v1-0-ee6bd616d3bf@tromey.com> In-Reply-To: <20240929-pr-31716-capture-openp-v1-0-ee6bd616d3bf@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.14.2 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.118.34.56 X-Source-L: No X-Exim-ID: 1suz2G-000ox4-2D X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-34-56.hlrn.qwest.net (prentzel.local) [97.118.34.56]:52182 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfFo2H5nxHc0PbF4UV48wy4YfhJnZJdTU+HI8/VJCMOEe6ut4NsBeBk1JgMoyB9tt6mLlNTsMjHQzr4bqh1OBum22LTucGKZdhukIYse8vr0RH30V1dG5 tfrmhHZdz6vl7i5jel6nh5iBVZ2jzOaV4lorJe4xZxPlMnNIBSQwDAU8snH3M2NfJkQDoUoyE+gs7NhlkJ7xpFVdY+3Aq01tjcI= X-Spam-Status: No, score=-3020.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H2, 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~patchwork=sourceware.org@sourceware.org Currently, gdb_abspath uses the current_directory global. However, background threads need to capture this global to avoid races with the user using "cd". This patch changes this function to accept a cwd parameter, in prepration for this. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31716 --- gdbsupport/pathstuff.cc | 6 +++--- gdbsupport/pathstuff.h | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc index 029e3c9a89001688877ea041d414acd41927e349..faed79b2cfb1d63c7051245e9018c0c2be7e083f 100644 --- a/gdbsupport/pathstuff.cc +++ b/gdbsupport/pathstuff.cc @@ -124,17 +124,17 @@ gdb_realpath_keepfile (const char *filename) /* See gdbsupport/pathstuff.h. */ std::string -gdb_abspath (const char *path) +gdb_abspath (const char *path, const char *cwd) { gdb_assert (path != NULL && path[0] != '\0'); if (path[0] == '~') return gdb_tilde_expand (path); - if (IS_ABSOLUTE_PATH (path) || current_directory == NULL) + if (IS_ABSOLUTE_PATH (path) || cwd == NULL) return path; - return path_join (current_directory, path); + return path_join (cwd, path); } /* See gdbsupport/pathstuff.h. */ diff --git a/gdbsupport/pathstuff.h b/gdbsupport/pathstuff.h index 22170bbabf2016a7d2118c2dd8c74c4d4a176b6a..15c7872aa9ab10e7f995d267b007011692ce8fbd 100644 --- a/gdbsupport/pathstuff.h +++ b/gdbsupport/pathstuff.h @@ -30,6 +30,9 @@ /* Path utilities. */ +/* String containing the current directory (what getwd would return). */ +extern char *current_directory; + /* Return the real path of FILENAME, expanding all the symbolic links. Contrary to "gdb_abspath", this function does not use @@ -47,14 +50,14 @@ extern std::string gdb_realpath_keepfile (const char *filename); PATH cannot be NULL or the empty string. This does not resolve symlinks however, use gdb_realpath for that. - Contrary to "gdb_realpath", this function uses CURRENT_DIRECTORY - for the path expansion. This may lead to scenarios the current - working directory (CWD) is different than CURRENT_DIRECTORY. + Contrary to "gdb_realpath", this function uses CWD for the path + expansion. This may lead to scenarios the current working + directory is different than CWD. - If CURRENT_DIRECTORY is NULL, this function returns a copy of - PATH. */ + If CWD is NULL, this function returns a copy of PATH. */ -extern std::string gdb_abspath (const char *path); +extern std::string gdb_abspath (const char *path, + const char *cwd = current_directory); /* Overload of gdb_abspath which takes std::string. */ @@ -177,7 +180,4 @@ extern const char *get_shell (); extern gdb::char_vector make_temp_filename (const std::string &f); -/* String containing the current directory (what getwd would return). */ -extern char *current_directory; - #endif /* COMMON_PATHSTUFF_H */