This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RE: [RFA] testsuite: Add a test for passing of environment variables to inferior
- From: "Pierre Muller" <pierre dot muller at ics-cnrs dot unistra dot fr>
- To: <gdb-patches at sourceware dot org>
- Date: Tue, 4 Oct 2011 16:49:52 +0200
- Subject: RE: [RFA] testsuite: Add a test for passing of environment variables to inferior
- References: <006301cc8292$367539b0$a35fad10$@muller@ics-cnrs.unistra.fr> <20111004134506.GB24369@calimero.vinschen.de>
> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Corinna Vinschen
> Envoyà : mardi 4 octobre 2011 15:45
> Ã : gdb-patches@sourceware.org
> Objet : Re: [RFA] testsuite: Add a test for passing of environment variables
> to inferior
>
> On Oct 4 14:36, Pierre Muller wrote:
> > Following Eli's comment that it was not clear
> > what I wanted to achieve, I wrote a new test.
> >
> > Manually checking CVS GDB for mingw, Eli's patch
> > gives the correct output.
> > But Stock Cygwin GDB currently passes none of these
> > TEST_GDB_XXX variables to inferior.
> > Even the patch that I sent earlier is not correct:
> > it still fails for the last test,
> > once TEST_GDB_VAR1 has been set into GDB environment list,
> > it doesn't get removed on the last start of the inferior...
> >
> > Corinna, I think this is the reason why I wanted to restore
> > the original environment layout (to avoid leaving unset
> > variables around.)
>
> Yes, that would be necessary. I'm wondering if we can't just utilze the
> global environ variable for this and spare us all the hassle. Something
> along these lines:
>
> char **old_env = environ;
> environ = in_env;
> cygwin_internal (CW_SYNC_WINENV);
> CreateProcessW (NULL environment pointer);
> environ = old_env;
I checked it out, but it still
fails for the last test, the missing TEST_GDB_VAR1
variable doesn't get removed from GDB environment list
apparently (This is probably related to the internals
of cygwin_internal (CW_SYNC_WINENV), no?
Manually resetting all variables should help...
The patch below does not generate any failure on my test,
but I am still not sure what happens if you try to
remove an environment variable that was set when GDB started...
Following Elis's comment, I also checked what happens
if I only call cygwin_internal (CW_SYNC_WINENV)
after resetting environ to the GDB value, but
the TEST_GDB_VAR1 doesn't get removed and the last test
fails.
Pierre
ChangeLog entry:
2011-10-04 Pierre Muller <muller@ics.u-strasbg.fr>
* windows-nat.c (windows_create_inferior): Handle in_env
array for Cygwin GDB.
Index: windows-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/windows-nat.c,v
retrieving revision 1.219
diff -u -p -r1.219 windows-nat.c
--- windows-nat.c 28 Sep 2011 09:07:54 -0000 1.219
+++ windows-nat.c 4 Oct 2011 14:40:59 -0000
@@ -1980,8 +1980,9 @@ windows_create_inferior (struct target_o
cygwin_buf_t *toexec;
cygwin_buf_t *cygallargs;
cygwin_buf_t *args;
+ char **old_env;
size_t len;
- int tty;
+ int tty, i;
int ostdin, ostdout, ostderr;
#else
char real_path[__PMAX];
@@ -2066,6 +2067,8 @@ windows_create_inferior (struct target_o
strcat (args, cygallargs);
#endif
+ old_env = environ;
+ environ = in_env;
/* Prepare the environment vars for CreateProcess. */
cygwin_internal (CW_SYNC_WINENV);
@@ -2101,6 +2104,21 @@ windows_create_inferior (struct target_o
NULL, /* current directory */
&si,
&pi);
+
+ /* Reset all environment variables to avoid leftover on next run. */
+ for (i = 0; in_env[i] && *in_env[i]; i++)
+ {
+ char *equalpos = strchr (in_env[i], '=');
+ if (equalpos)
+ *equalpos = '\0';
+ SetEnvironmentVariableA (in_env[i], NULL);
+ if (equalpos)
+ *equalpos = '=';
+ }
+ /* Restore normal GDB environment variables. */
+ environ = old_env;
+ cygwin_internal (CW_SYNC_WINENV);
+
if (tty >= 0)
{
close (tty);