From: Corinna Vinschen <vinschen@redhat.com>
To: gdb-patches@sourceware.org
Subject: Re: [RFA] testsuite: Add a test for passing of environment variables to inferior
Date: Wed, 05 Oct 2011 12:52:00 -0000 [thread overview]
Message-ID: <20111005125157.GA24105@calimero.vinschen.de> (raw)
In-Reply-To: <004401cc8357$74fd1c00$5ef75400$@muller@ics-cnrs.unistra.fr>
On Oct 5 14:08, Pierre Muller wrote:
> Hi Corinna,
> I didn't know about the charset problem...
>
> > Here's my proposal, based on your patch. I'll work on using the
> > yet-to-be-created new cygwin_internal call after I implemented it in
> > Cygwin.
>
> I think that your approach is OK,
> I checked that it does also pass all
> the tests in my gdb.base/testenv.exp
> (11 passes instead of 7 passes/4 failures for current Cygwin GDB 7.3.50 20110821cvs).
>
> Your patch proposal thus supersedes mine.
>
> We just need an approval from Christopher Faylor...
Right. Here's a new version of the patch which uses the new
cygwin_internal(CW_CVT_ENV_TO_WINENV) which will be available starting
with the next Cygwin 1.7.10. The patch allows to build GDB under older
versions of Cygwin and it will fallback to the CW_SYNC_WINENV method if
the cygwin_internal (CW_CVT_ENV_TO_WINENV) call returns with an error.
That allows to run a GDB built under 1.7.10 to run under older Cygwin
versions (provided all other DLL dependencies still work). Tested under
Cygwin 1.7.9 and current CVS.
Corinna
* windows-nat.c: Include wchar.h to avoid compiler warnings.
Include cygwin/version.h to get version information.
(clear_win32_environment): New function for Cygwin to clear out
Win32 environment.
(windows_create_inferior): Prepare new environment from in_env
for Cygwin, too. Use cygwin_internal (CW_CVT_ENV_TO_WINENV) call
to get a Win32 copy of the desired POSIX environment if available,
fall back to changing the GDB environment otherwise.
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 5 Oct 2011 12:47:40 -0000
@@ -40,7 +40,9 @@
#include <imagehlp.h>
#include <psapi.h>
#ifdef __CYGWIN__
+#include <wchar.h>
#include <sys/cygwin.h>
+#include <cygwin/version.h>
#endif
#include <signal.h>
@@ -1963,6 +1965,28 @@ envvar_cmp (const void *a, const void *b
}
#endif
+#ifdef __CYGWIN__
+static void
+clear_win32_environment (char **env)
+{
+ int i;
+ size_t len;
+ wchar_t *copy = NULL, *equalpos;
+
+ for (i = 0; env[i] && *env[i]; i++)
+ {
+ len = mbstowcs (NULL, env[i], 0) + 1;
+ copy = (wchar_t *) xrealloc (copy, len * sizeof (wchar_t));
+ mbstowcs (copy, env[i], len);
+ equalpos = wcschr (copy, L'=');
+ if (equalpos)
+ *equalpos = L'\0';
+ SetEnvironmentVariableW (copy, NULL);
+ }
+ xfree (copy);
+}
+#endif
+
/* Start an inferior windows child process and sets inferior_ptid to its pid.
EXEC_FILE is the file to run.
ALLARGS is a string containing the arguments to the program.
@@ -1980,6 +2004,8 @@ windows_create_inferior (struct target_o
cygwin_buf_t *toexec;
cygwin_buf_t *cygallargs;
cygwin_buf_t *args;
+ char **old_env;
+ PWCHAR w32_env;
size_t len;
int tty;
int ostdin, ostdout, ostderr;
@@ -2066,8 +2092,23 @@ windows_create_inferior (struct target_o
strcat (args, cygallargs);
#endif
- /* Prepare the environment vars for CreateProcess. */
- cygwin_internal (CW_SYNC_WINENV);
+#if CYGWIN_VERSION_API_MAJOR > 0 || CYGWIN_VERSION_API_MINOR >= 252
+ /* First try to create a direct Win32 copy of the POSIX environment. */
+ w32_env = (PWCHAR) cygwin_internal (CW_CVT_ENV_TO_WINENV, in_env);
+ if (w32_env != (PWCHAR) -1)
+ flags |= CREATE_UNICODE_ENVIRONMENT;
+ else
+ /* If that fails, fall back to old method tweaking GDB's environment. */
+#endif
+ {
+ /* Reset all Win32 environment variables to avoid leftover on next run. */
+ clear_win32_environment (environ);
+ /* Prepare the environment vars for CreateProcess. */
+ old_env = environ;
+ environ = in_env;
+ cygwin_internal (CW_SYNC_WINENV);
+ w32_env = NULL;
+ }
if (!inferior_io_terminal)
tty = ostdin = ostdout = ostderr = -1;
@@ -2097,10 +2138,22 @@ windows_create_inferior (struct target_o
NULL, /* thread */
TRUE, /* inherit handles */
flags, /* start flags */
- NULL, /* environment */
+ w32_env, /* environment */
NULL, /* current directory */
&si,
&pi);
+ if (w32_env)
+ /* Just free the Win32 environment, if it could be created. */
+ free (w32_env);
+ else
+ {
+ /* Reset all environment variables to avoid leftover on next run. */
+ clear_win32_environment (in_env);
+ /* Restore normal GDB environment variables. */
+ environ = old_env;
+ cygwin_internal (CW_SYNC_WINENV);
+ }
+
if (tty >= 0)
{
close (tty);
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat
next prev parent reply other threads:[~2011-10-05 12:52 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-04 12:36 Pierre Muller
2011-10-04 13:45 ` Corinna Vinschen
2011-10-04 14:43 ` Eli Zaretskii
2011-10-04 14:48 ` Pierre Muller
2011-10-04 14:50 ` Pierre Muller
2011-10-04 15:13 ` Corinna Vinschen
2011-10-04 16:09 ` [RFA-v2] " Pierre Muller
2011-10-04 16:11 ` [RFA] " Pierre Muller
2011-10-05 11:40 ` Corinna Vinschen
2011-10-05 12:08 ` Pierre Muller
2011-10-05 12:52 ` Corinna Vinschen [this message]
2011-10-06 14:51 ` Christopher Faylor
2011-10-06 15:03 ` Corinna Vinschen
2011-10-07 12:26 ` Christopher Faylor
2011-10-07 13:53 ` Corinna Vinschen
[not found] ` <12954.5351061553$1317744599@news.gmane.org>
2011-10-04 17:27 ` [RFA-v2] " Tom Tromey
2011-10-04 21:35 ` [RFA-v3] " Pierre Muller
[not found] ` <29288.743020925$1317764135@news.gmane.org>
2011-10-05 13:53 ` Tom Tromey
2011-10-05 14:25 ` Pierre Muller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111005125157.GA24105@calimero.vinschen.de \
--to=vinschen@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox