[PATCH] gdb/gdbsupport: Use LOCALAPPDATA for index cache on windows

Alexander Fedotov via Gdb-patches
2020-12-08T10:17:09Z

[-- Attachment #1: Type: text/plain, Size: 247 bytes --]

Hi all

When running GDB on Windows using native command line (not Msys2 or
another) I see nasty warning Couldn't determine a path for index
cached directory"

So I have decided to use LOCALAPPDATA as a last resort.

Comments are welcomed.

Alex

[-- Attachment #2: 0001-gdb-gdbsupport-pathstuff.cc-Use-LOCALAPPDATA-environ.patch --]
[-- Type: text/x-patch, Size: 1706 bytes --]

From 9c78154311c6315e8aae627fada5c339e932f887 Mon Sep 17 00:00:00 2001
From: Alexander Fedotov <alfedotov@gmail.com>
Date: Tue, 8 Dec 2020 13:07:23 +0300
Subject: [PATCH] gdb/gdbsupport/pathstuff.cc: Use LOCALAPPDATA environment
variable when running on Windows with native command line, otherwise nasty
warning "Couldn't determine a path for index cached directory" appears.

---
gdbsupport/ChangeLog | 6 ++++++
gdbsupport/pathstuff.cc | 10 ++++++++++
2 files changed, 16 insertions(+)

diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog
index 88a0413e8b..cc1035d0ae 100644
--- a/gdbsupport/ChangeLog
+++ b/gdbsupport/ChangeLog
@@ -1,3 +1,9 @@
+2020-12-08 Alexander Fedotov <alfedotov@gmail.com>
+
+ * pathstuff.cc (get_standard_cache_dir): Use LOCALAPPDATA environment
+ variable when running on Windows with native command line, otherwise nasty
+ warning "Couldn't determine a path for index cached directory" appears.
+
2020-12-01 Andrew Burgess <andrew.burgess@embecosm.com>

* tdesc.cc (print_xml_feature::visit): Print enum fields using
diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc
index 311456720e..994ddff300 100644
--- a/gdbsupport/pathstuff.cc
+++ b/gdbsupport/pathstuff.cc
@@ -238,6 +238,16 @@ get_standard_cache_dir ()
return string_printf ("%s/" HOME_CACHE_DIR "/gdb", abs.get ());
}

+#ifdef _WIN32
+ const char *win_home = getenv ("LOCALAPPDATA");
+ if (win_home != NULL)
+ {
+ /* Make sure the path is absolute and tilde-expanded. */
+ gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (win_home));
+ return string_printf ("%s/" HOME_CACHE_DIR "/gdb", abs.get ());
+ }
+#endif
+
return {};
}

--
2.25.1