]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix "unset local-environment" when clearenv not available
authorTom Tromey <tromey@adacore.com>
Wed, 10 Dec 2025 14:23:37 +0000 (07:23 -0700)
committerTom Tromey <tromey@adacore.com>
Thu, 11 Dec 2025 13:55:49 +0000 (06:55 -0700)
Tom de Vries pointed out that clearenv isn't available on all hosts.
Since this seems like a niche command at best, it seemed fine to
disable this command on such platforms.

Reviewed-By: Tom de Vries <tdevries@suse.de>
gdb/config.in
gdb/configure
gdb/configure.ac
gdb/infcmd.c
gdb/testsuite/gdb.base/local-env.exp

index 9e2bba42e287018d29d88e526768c654cbb1b6fc..62d9e0eda6de29bf26fffb9c3a133bb2b64270a8 100644 (file)
    the CoreFoundation framework. */
 #undef HAVE_CFPREFERENCESCOPYAPPVALUE
 
+/* Define to 1 if you have the `clearenv' function. */
+#undef HAVE_CLEARENV
+
 /* Define if compiling support to gdb compile. */
 #undef HAVE_COMPILE
 
index cc446c6e4c89746a0ba594b00075184d7ad1de7d..dcf4fee40ddcf821141f545753678cdfe2bb7a34 100755 (executable)
@@ -30123,6 +30123,7 @@ $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h
 
 for ac_func in  \
   btowc \
+  clearenv \
   getgid \
   getpgid \
   getrlimit \
index 1b9939b0754602a01a13eb5edf0ce98d33e52332..3f44d9e684be3bf0ecd4e3245c9dced240a26a9e 100644 (file)
@@ -1458,6 +1458,7 @@ AC_C_BIGENDIAN
 
 AC_CHECK_FUNCS([ \
   btowc \
+  clearenv \
   getgid \
   getpgid \
   getrlimit \
index 3ba286738a00b012079012074917bd51c0178afa..ed4fb819faf0152a15e6c4042f9f83e15b128b97 100644 (file)
@@ -2146,12 +2146,25 @@ unset_var_in_environment (gdb_environ *env, const char *var, int from_tty)
 {
   if (var == 0)
     {
+      /* If there is no clearenv, don't bother asking the question.  */
+#ifndef HAVE_CLEARENV
+      if (env == nullptr)
+       from_tty = 0;
+#endif
+
       /* If there is no argument, delete all environment variables.
         Ask for confirmation if reading from the terminal.  */
       if (!from_tty || query (_("Delete all environment variables? ")))
        {
+         /* This was handled above.  */
          if (env == nullptr)
-           clearenv ();
+           {
+#ifdef HAVE_CLEARENV
+             clearenv ();
+#else
+             error (_("Cannot clear the local environment on this host."));
+#endif
+           }
          else
            env->clear ();
        }
index fedcf9bc3e4183936ca79b17b70a927079ff6927..c62ea7466354a0b29b2d13e27053c915053f8487 100644 (file)
@@ -59,12 +59,26 @@ gdb_test "show local-environment EDITOR" \
     "confirm unset environment variable worked"
 
 # Verify that we can unset all environment variables.
-gdb_test "unset local-environment" "" "unset all environment variables" \
-    "Delete all environment variables. .y or n. $" \
-    "y"
+# Note that on some platforms this is not possible.
+set can_unset_all 0
+# Disable confirmation so we don't have to deal with the question.
+gdb_test_multiple "with confirm off -- unset local-environment" \
+    "unset all environment variables" {
+       -re -wrap "Cannot clear the local environment on this host." {
+           # Nothing.
+           pass $gdb_test_name
+       }
+
+       -re -wrap "" {
+           set can_unset_all 1
+           pass $gdb_test_name
+       }
+    }
 
-gdb_test_no_output "show local-environment" \
-    "all environment variables have been unset"
+if {$can_unset_all} {
+    gdb_test_no_output "show local-environment" \
+       "all environment variables have been unset"
+}
 
 # Verify that we can set a specific environment variable.
 test_set_show_env_var "EDITOR" "emacs" "set environment variable"