From: Eli Zaretskii <eliz@gnu.org>
To: gdb-patches@sourceware.org, vinschen@redhat.com
Subject: Re: [RFA] Environment variables passed to inferior by MinGW build (PR 10989)
Date: Sun, 25 Sep 2011 23:56:00 -0000 [thread overview]
Message-ID: <E1R7mEx-0003rs-PZ@fencepost.gnu.org> (raw)
In-Reply-To: <E1R5YPa-0007H0-0B@fencepost.gnu.org> (message from Eli Zaretskii on Mon, 19 Sep 2011 03:37:06 -0400)
Ping! Ping! (2 weeks)
> Date: Mon, 19 Sep 2011 03:37:06 -0400
> From: Eli Zaretskii <eliz@gnu.org>
> Reply-to: Eli Zaretskii <eliz@gnu.org>
>
> Ping!
>
> > Date: Sun, 11 Sep 2011 08:33:25 -0400
> > From: Eli Zaretskii <eliz@gnu.org>
> > CC: Corinna Vinschen <vinschen@redhat.com>
> >
> > There's some history to this issue. It was discussed at least twice
> > before:
> >
> > http://sourceware.org/ml/gdb-patches/2010-05/msg00317.html
> > http://sourceware.org/ml/gdb-patches/2011-04/msg00347.html
> >
> > The first discussion simply died because the OP never responded to
> > Joel's request to clean up the patch from weird characters.
> >
> > As for the second discussion, upon re-reading it I can only assume
> > that there was a misunderstanding of some kind, perhaps Pierre was
> > talking about both the Cygwin and the native Windows builds, while
> > Chris and Corinna replied only about the latter.
> >
> > In any case, the original problem is still there in the MinGW build of
> > GDB 7.3, and it just bit me hard enough to sit down and solve it.
> >
> > The code in the patch below is simply taken from what was there before
> > it was deleted by Corinna back in 2006, after removing from it
> > everything that was Cygwin-specific. So I don't even think I can take
> > credit for this code ;-)
> >
> > With that patch, I can add environment variables with "set
> > environment", delete them with "unset environment", and the inferior
> > gets the environment I meant it to have.
> >
> > OK to commit?
> >
> > 2011-09-11 Eli Zaretskii <eliz@gnu.org>
> >
> > * windows-nat.c (env_sort) [!__CYGWIN__]: Function restored from
> > before the change on 2006-12-09.
> > (windows_create_inferior) [!__CYGWIN__]: Restore code that
> > generates the environment block for CreateProcessA, modulo the
> > Cygwin-specific parts that are not needed here.
> >
> >
> > === modified file 'gdb/windows-nat.c'
> > --- gdb/windows-nat.c 2011-05-09 14:25:35 +0000
> > +++ gdb/windows-nat.c 2011-09-11 12:26:41 +0000
> > @@ -1951,6 +1951,17 @@
> > *flags |= CREATE_NEW_CONSOLE;
> > }
> >
> > +#ifndef __CYGWIN__
> > +/* Function called by qsort to sort environment strings. */
> > +static int
> > +env_sort (const void *a, const void *b)
> > +{
> > + const char **p = (const char **) a;
> > + const char **q = (const char **) b;
> > + return strcasecmp (*p, *q);
> > +}
> > +#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.
> > @@ -1977,6 +1988,12 @@
> > char *toexec;
> > char *args;
> > HANDLE tty;
> > + char *w32env;
> > + char *temp;
> > + size_t envlen;
> > + int i;
> > + size_t envsize;
> > + char **env;
> > #endif
> > PROCESS_INFORMATION pi;
> > BOOL ret;
> > @@ -2124,6 +2141,31 @@
> > }
> > }
> >
> > + /* CreateProcess takes the environment list as a null terminated set of
> > + strings (i.e. two nulls terminate the list). */
> > +
> > + /* Get total size for env strings. */
> > + for (envlen = 0, i = 0; in_env[i] && *in_env[i]; i++)
> > + envlen += strlen (in_env[i]) + 1;
> > +
> > + envsize = sizeof (in_env[0]) * (i + 1);
> > + env = (char **) alloca (envsize);
> > + memcpy (env, in_env, envsize);
> > + /* Windows programs expect the environment block to be sorted. */
> > + qsort (env, i, sizeof (char *), env_sort);
> > +
> > + w32env = alloca (envlen + 1);
> > +
> > + /* Copy env strings into new buffer. */
> > + for (temp = w32env, i = 0; env[i] && *env[i]; i++)
> > + {
> > + strcpy (temp, env[i]);
> > + temp += strlen (temp) + 1;
> > + }
> > +
> > + /* Final nil string to terminate new env. */
> > + *temp = 0;
> > +
> > windows_init_thread_list ();
> > ret = CreateProcessA (0,
> > args, /* command line */
> > @@ -2131,7 +2173,7 @@
> > NULL, /* thread */
> > TRUE, /* inherit handles */
> > flags, /* start flags */
> > - NULL, /* environment */
> > + w32env, /* environment */
> > NULL, /* current directory */
> > &si,
> > &pi);
> >
>
next prev parent reply other threads:[~2011-09-25 10:47 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-11 13:24 Eli Zaretskii
2011-09-11 22:03 ` asmwarrior
2011-09-19 8:04 ` Eli Zaretskii
2011-09-25 23:56 ` Eli Zaretskii [this message]
2011-09-26 5:22 ` Stan Shebs
2011-09-26 17:22 ` Joel Brobecker
2011-09-26 18:23 ` Eli Zaretskii
2011-09-28 9:39 ` Eli Zaretskii
2011-10-03 18:18 ` Tom Tromey
2011-10-03 18:25 ` Eli Zaretskii
2011-10-04 7:54 ` Corinna Vinschen
2011-10-04 9:29 ` Eli Zaretskii
2011-10-04 11:13 ` Corinna Vinschen
2011-10-04 9:56 ` [RFC] Environment variables passed to inferior for Cygwin build ( follow up on mingw fix for PR 10989) Pierre Muller
2011-10-04 10:40 ` Eli Zaretskii
2011-10-04 11:16 ` Corinna Vinschen
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=E1R7mEx-0003rs-PZ@fencepost.gnu.org \
--to=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=vinschen@redhat.com \
/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