Fix PR gdb/21954: make 'unset environment' work again
authorSergio Durigan Junior <sergiodj@redhat.com>
Tue, 15 Aug 2017 17:49:18 +0000 (13:49 -0400)
committerSergio Durigan Junior <sergiodj@redhat.com>
Tue, 15 Aug 2017 17:49:18 +0000 (13:49 -0400)
When I made commit 9a6c7d9c021cfeb290d76584db7a01e57e7c3d4e, which
C++-fied gdb/common/environ.[ch], I mistakenly altered the behaviour
of the 'unset environment' command.  This command, which should delete
all environment variables, is now resetting the list of variables to
the state they were when GDB was started.

This commit fixes this regression, and also adds a test on
gdb.base/environ.exp which really checks if 'unset environment'
worked.

gdb/ChangeLog:
2017-08-15  Sergio Durigan Junior  <sergiodj@redhat.com>

PR gdb/21954
* infcmd.c (unset_environment_command): Use the 'clear' method on
the environment instead of resetting it.

gdb/testsuite/ChangeLog:
2017-08-15  Sergio Durigan Junior  <sergiodj@redhat.com>

PR gdb/21954
* gdb.base/environ.exp: Add test to check if 'unset environment'
works.

gdb/ChangeLog
gdb/infcmd.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/environ.exp

index fbf14dd4d62e32522a6cbfa9ccd0068e185f433f..94155f51d0c86b70e148844ac5c84f741d830241 100644 (file)
@@ -1,3 +1,9 @@
+2017-08-15  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+       PR gdb/21954
+       * infcmd.c (unset_environment_command): Use the 'clear' method on
+       the environment instead of resetting it.
+
 2017-08-15  John Baldwin  <jhb@FreeBSD.org>
 
        * fbsd-nat.c (fbsd_convert_siginfo): Fix compile on big-endian
index defa7b0c48cd3a1a90786ba3d883a986247a3b5d..c8a82db4552a40ca8402c1ad6be7eca617502725 100644 (file)
@@ -2230,7 +2230,7 @@ unset_environment_command (char *var, int from_tty)
       /* 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? ")))
-       current_inferior ()->environment = gdb_environ::from_host_environ ();
+       current_inferior ()->environment.clear ();
     }
   else
     current_inferior ()->environment.unset (var);
index f9494af9386546b5e1a616de5c28ab4bcd69540e..39c49b8d0eaf275e0b361bcae7a55d3f0550b68e 100644 (file)
@@ -1,3 +1,9 @@
+2017-08-15  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+       PR gdb/21954
+       * gdb.base/environ.exp: Add test to check if 'unset environment'
+       works.
+
 2017-08-14  Andreas Arnez  <arnez@linux.vnet.ibm.com>
 
        * lib/gdb.exp (universal_compile_options): New caching proc.
index 0b69a80a902a2cd568939031705a723dd888401b..bb52063b2979280e1fd7dfd37165af2b0dfed6b2 100644 (file)
@@ -46,6 +46,9 @@ gdb_test "unset environment" "" "unset all environment variables" \
     "Delete all environment variables. .y or n. $" \
     "y"
 
+gdb_test_no_output "show 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"