Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: Tom Tromey <tom@tromey.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH 3/3] Add DWARF index cache
Date: Tue, 17 Jul 2018 20:48:00 -0000	[thread overview]
Message-ID: <d3469129-1c96-8388-09bc-0d4c427b55f9@ericsson.com> (raw)
In-Reply-To: <871sc1zlrv.fsf@tromey.com>

On 2018-07-17 03:48 PM, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@ericsson.com> 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 <simon.marchi@ericsson.com>
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<char> 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<char> 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<char> 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
-- 
2.7.4


  reply	other threads:[~2018-07-17 20:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-09 21:56 [PATCH 0/3] Add a " Simon Marchi
2018-07-09 21:56 ` [PATCH 1/3] Make index reading functions more modular Simon Marchi
2018-07-25 16:51   ` Tom Tromey
2018-07-09 21:56 ` [PATCH 2/3] Introduce scoped_mmapped_file Simon Marchi
2018-07-24  2:18   ` Tom Tromey
2018-07-24 12:31     ` Simon Marchi
2018-07-09 21:57 ` [PATCH 3/3] Add DWARF index cache Simon Marchi
2018-07-17 19:48   ` Tom Tromey
2018-07-17 20:48     ` Simon Marchi [this message]
2018-07-18 18:20       ` Tom Tromey
2018-07-25 18:48   ` Tom Tromey
2018-07-25 20:20     ` Simon Marchi
2018-07-26 12:38     ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d3469129-1c96-8388-09bc-0d4c427b55f9@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox