aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.base/empty-host-env-vars.exp72
-rw-r--r--gdbsupport/ChangeLog6
-rw-r--r--gdbsupport/pathstuff.cc14
4 files changed, 90 insertions, 7 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 0c5e360..ef3e794 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2021-01-08 Simon Marchi <simon.marchi@polymtl.ca>
+
+ PR gdb/27157
+ * gdb.base/empty-host-env-vars.exp: New test.
+
2021-01-08 Andrew Burgess <andrew.burgess@embecosm.com>
* gdb.base/completion.exp: Add a new test.
diff --git a/gdb/testsuite/gdb.base/empty-host-env-vars.exp b/gdb/testsuite/gdb.base/empty-host-env-vars.exp
new file mode 100644
index 0000000..bd7212e
--- /dev/null
+++ b/gdb/testsuite/gdb.base/empty-host-env-vars.exp
@@ -0,0 +1,72 @@
+# Copyright 2021 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# GDB reads some environment variables on startup, make sure it behaves
+# correctly if these variables are defined but empty.
+
+set all_env_vars { HOME XDG_CACHE_HOME LOCALAPPDATA XDG_CONFIG_HOME }
+
+# Record the initial value of the index-cache directory.
+clean_restart
+set index_cache_directory ""
+gdb_test_multiple "show index-cache directory" "" {
+ -re -wrap "The directory of the index cache is \"(.*)\"\\." {
+ set index_cache_directory $expect_out(1,string)
+ set index_cache_directory [string_to_regexp $index_cache_directory]
+ pass $gdb_test_name
+ }
+}
+
+foreach_with_prefix env_var_name $all_env_vars {
+ # Restore the original state of the environment variable.
+ save_vars env($env_var_name) {
+ set env($env_var_name) {}
+ clean_restart
+
+ # Verify that the empty environment variable didn't affect the
+ # index-cache directory setting, that we still see the initial value.
+ # "HOME" is different, because if that one is unset, GDB isn't even
+ # able to compute the default location. In that case, we expect it to
+ # be empty.
+ if { $env_var_name == "HOME" } {
+ gdb_test "show index-cache directory" \
+ "The directory of the index cache is \"\"\\."
+ } else {
+ gdb_test "show index-cache directory" \
+ "The directory of the index cache is \"$index_cache_directory\"\\."
+ }
+ }
+}
+
+# Try the same, but with all the env vars set to an empty value at the same
+# time.
+with_test_prefix "all env vars" {
+ set save_vars_arg {}
+ foreach env_var_name $all_env_vars {
+ lappend save_vars_arg env($env_var_name)
+ }
+
+ # Restore the original state of all the environment variables.
+ save_vars $save_vars_arg {
+ foreach env_var_name $all_env_vars {
+ set env($env_var_name) {}
+ }
+
+ clean_restart
+
+ gdb_test "show index-cache directory" \
+ "The directory of the index cache is \"\"\\."
+ }
+}
diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog
index 4cac86f..d973a6d 100644
--- a/gdbsupport/ChangeLog
+++ b/gdbsupport/ChangeLog
@@ -1,3 +1,9 @@
+2021-01-08 Simon Marchi <simon.marchi@polymtl.ca>
+
+ PR gdb/27157
+ * pathstuff.cc (get_standard_cache_dir, get_standard_config_dir,
+ find_gdb_home_config_file): Add empty string check.
+
2021-01-06 Mike Frysinger <vapier@gentoo.org>
* common-utils.h (align_up): Fix typo in header comment.
diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc
index 51ab8c6..ad13900 100644
--- a/gdbsupport/pathstuff.cc
+++ b/gdbsupport/pathstuff.cc
@@ -222,7 +222,7 @@ get_standard_cache_dir ()
#ifndef __APPLE__
const char *xdg_cache_home = getenv ("XDG_CACHE_HOME");
- if (xdg_cache_home != NULL)
+ if (xdg_cache_home != NULL && xdg_cache_home[0] != '\0')
{
/* Make sure the path is absolute and tilde-expanded. */
gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (xdg_cache_home));
@@ -231,7 +231,7 @@ get_standard_cache_dir ()
#endif
const char *home = getenv ("HOME");
- if (home != NULL)
+ if (home != NULL && home[0] != '\0')
{
/* Make sure the path is absolute and tilde-expanded. */
gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (home));
@@ -240,14 +240,14 @@ get_standard_cache_dir ()
#ifdef WIN32
const char *win_home = getenv ("LOCALAPPDATA");
- if (win_home != NULL)
+ if (win_home != NULL && win_home[0] != '\0')
{
/* Make sure the path is absolute and tilde-expanded. */
gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (win_home));
return string_printf ("%s/gdb", abs.get ());
}
#endif
-
+
return {};
}
@@ -289,7 +289,7 @@ get_standard_config_dir ()
#ifndef __APPLE__
const char *xdg_config_home = getenv ("XDG_CONFIG_HOME");
- if (xdg_config_home != NULL)
+ if (xdg_config_home != NULL && xdg_config_home[0] != '\0')
{
/* Make sure the path is absolute and tilde-expanded. */
gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (xdg_config_home));
@@ -298,7 +298,7 @@ get_standard_config_dir ()
#endif
const char *home = getenv ("HOME");
- if (home != NULL)
+ if (home != NULL && home[0] != '\0')
{
/* Make sure the path is absolute and tilde-expanded. */
gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (home));
@@ -340,7 +340,7 @@ find_gdb_home_config_file (const char *name, struct stat *buf)
}
const char *homedir = getenv ("HOME");
- if (homedir != nullptr)
+ if (homedir != nullptr && homedir[0] != '\0')
{
/* Make sure the path is absolute and tilde-expanded. */
gdb::unique_xmalloc_ptr<char> abs (gdb_abspath (homedir));