From patchwork Tue Jul 17 20:48:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 28445 Received: (qmail 103060 invoked by alias); 17 Jul 2018 20:48:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 102849 invoked by uid 89); 17 Jul 2018 20:48:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: sessmg22.ericsson.net Received: from sessmg22.ericsson.net (HELO sessmg22.ericsson.net) (193.180.251.58) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 17 Jul 2018 20:48:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1531860513; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2Os92OwAGqC3H2TcTpor2ukhvUKNAzHgfbBJZVjCwTo=; b=RaAyFrGLri+W+MYm2ZWI1GpW6xs4rCxRu6jOYMxzgABwTdvY5v89NDi3RMLDRCjm peMs43RcvIUrO9eu2JWLR4/txgXkATOANjiOmNQk1nUCUXRmqpFWCmLJg2ELgBHi uQX70KtyRc5PySxtSxqNY1QkvSlDqJ+zCK5rYL3aao4=; Received: from ESESBMB502.ericsson.se (Unknown_Domain [153.88.183.115]) by sessmg22.ericsson.net (Symantec Mail Security) with SMTP id 58.85.31169.1265E4B5; Tue, 17 Jul 2018 22:48:33 +0200 (CEST) Received: from ESESBMR504.ericsson.se (153.88.183.139) by ESESBMB502.ericsson.se (153.88.183.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Tue, 17 Jul 2018 22:48:32 +0200 Received: from ESESSMB503.ericsson.se (153.88.183.164) by ESESBMR504.ericsson.se (153.88.183.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Tue, 17 Jul 2018 22:48:32 +0200 Received: from NAM05-DM3-obe.outbound.protection.outlook.com (153.88.183.157) by ESESSMB503.ericsson.se (153.88.183.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3 via Frontend Transport; Tue, 17 Jul 2018 22:48:32 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qPf9Aa85ScMnX2Bj5g2g0aw0WEG8M3wzC2s/EDgQcl4=; b=GzXr/VLoUlMbbAczJ20ACc/sEJRf/dBP2X9BgKZ4Jbgl8sS2kkvWot3zEHTOS0PIhfNORfS5jBZcPTHCp4LZHBOZb+5kM58UttHHzsQz4MNbw3f4V037hjtSSZdQVSrCpD+Gg+oxAz5tfA38T/H6DtkdZXNaCf7E+K9SAjlEgSM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; Received: from [142.133.61.147] (192.75.88.130) by BYAPR15MB2390.namprd15.prod.outlook.com (2603:10b6:a02:8c::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.952.20; Tue, 17 Jul 2018 20:48:29 +0000 Subject: Re: [PATCH 3/3] Add DWARF index cache To: Tom Tromey CC: References: <1531173351-6351-1-git-send-email-simon.marchi@ericsson.com> <1531173351-6351-4-git-send-email-simon.marchi@ericsson.com> <871sc1zlrv.fsf@tromey.com> From: Simon Marchi Message-ID: Date: Tue, 17 Jul 2018 16:48:15 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <871sc1zlrv.fsf@tromey.com> Return-Path: simon.marchi@ericsson.com Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-IsSubscribed: yes On 2018-07-17 03:48 PM, Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi writes: > > Simon> +/* The index cache directory, used for "set/show index-cache directory". */ > Simon> +static char *index_cache_directory = NULL; > > I think it would be good if the code that used this first passed it > through tilde_expand, so users could "set index-cache directory ~/.blah". Good point. This is already done in do_set_command, because the parameter is of type var_filename. But it is not done in the case the path comes from XDG_CACHE_HOME, for example. Also, I think it would be good to store that path as an absolute path too. Let's say I do: (gdb) cd /tmp (gdb) set index-cache directory foo (gdb) cd / I would expect the index-cache directory to stay /tmp/foo (relative to the current working directory at the moment I entered the command). Storing the directory as a relative path would make it "follow" the current working directory changes, which I think would be unintuitive. So here's what I changed: - Make get_standard_cache_dir return an absolute, tilde-expanded path. - Make set_index_cache_directory_command transform index_cache_directory so it is absolute and tilde-expanded. Here's the addendum to the patch (I also included an unrelated change, remove an unnecessary rvalue-reference): From f091b3930e784394e2edc35a27d6c07468776f31 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 17 Jul 2018 16:33:18 -0400 Subject: [PATCH] fixup --- gdb/common/pathstuff.c | 12 ++++++++++-- gdb/common/pathstuff.h | 2 +- gdb/dwarf-index-cache.c | 6 +++++- gdb/dwarf-index-cache.h | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gdb/common/pathstuff.c b/gdb/common/pathstuff.c index b64d43a..f449f1a 100644 --- a/gdb/common/pathstuff.c +++ b/gdb/common/pathstuff.c @@ -166,11 +166,19 @@ get_standard_cache_dir () { char *xdg_cache_home = getenv ("XDG_CACHE_HOME"); if (xdg_cache_home != NULL) - return string_printf ("%s/gdb", xdg_cache_home); + { + /* Make sure the path is absolute and tilde-expanded. */ + gdb::unique_xmalloc_ptr abs (gdb_abspath (xdg_cache_home)); + return string_printf ("%s/gdb", abs.get ()); + } char *home = getenv ("HOME"); if (home != NULL) - return string_printf ("%s/.cache/gdb", home); + { + /* Make sure the path is absolute and tilde-expanded. */ + gdb::unique_xmalloc_ptr abs (gdb_realpath (home)); + return string_printf ("%s/.cache/gdb", abs.get ()); + } return {}; } diff --git a/gdb/common/pathstuff.h b/gdb/common/pathstuff.h index 264700f..d1aa6b3 100644 --- a/gdb/common/pathstuff.h +++ b/gdb/common/pathstuff.h @@ -54,7 +54,7 @@ extern bool contains_dir_separator (const char *path); On Linux, it follows the XDG Base Directory specification: use $XDG_CACHE_HOME/gdb if the XDG_CACHE_HOME environment variable is defined, - otherwise $HOME/.cache. + otherwise $HOME/.cache. The return value is absolute and tilde-expanded. Return an empty string if neither XDG_CACHE_HOME or HOME are defined. */ diff --git a/gdb/dwarf-index-cache.c b/gdb/dwarf-index-cache.c index 049d091..d3d669a 100644 --- a/gdb/dwarf-index-cache.c +++ b/gdb/dwarf-index-cache.c @@ -124,7 +124,7 @@ index_cache_resource::~index_cache_resource () = default; /* See dwarf-index-cache.h. */ void -index_cache::set_directory (std::string &&dir) +index_cache::set_directory (std::string dir) { gdb_assert (!dir.empty ()); @@ -345,6 +345,10 @@ static void set_index_cache_directory_command (const char *arg, int from_tty, cmd_list_element *element) { + /* Make sure the index cache directory is absolute and tilde-expanded. */ + gdb::unique_xmalloc_ptr abs (gdb_abspath (index_cache_directory)); + xfree (index_cache_directory); + index_cache_directory = abs.release (); global_index_cache.set_directory (index_cache_directory); } diff --git a/gdb/dwarf-index-cache.h b/gdb/dwarf-index-cache.h index 7b305c3..b4fa8c4 100644 --- a/gdb/dwarf-index-cache.h +++ b/gdb/dwarf-index-cache.h @@ -38,7 +38,7 @@ class index_cache { public: /* Change the directory used to save/load index files. */ - void set_directory (std::string &&dir); + void set_directory (std::string dir); /* Return true if the usage of the cache is enabled. */ bool enabled () const