From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17233 invoked by alias); 28 Sep 2011 09:15:43 -0000 Received: (qmail 17213 invoked by uid 22791); 28 Sep 2011 09:15:41 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL,BAYES_00,SPF_SOFTFAIL,TW_CP,TW_NV X-Spam-Check-By: sourceware.org Received: from mtaout20.012.net.il (HELO mtaout20.012.net.il) (80.179.55.166) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 28 Sep 2011 09:15:26 +0000 Received: from conversion-daemon.a-mtaout20.012.net.il by a-mtaout20.012.net.il (HyperSendmail v2007.08) id <0LS800D006XO8R00@a-mtaout20.012.net.il> for gdb-patches@sourceware.org; Wed, 28 Sep 2011 12:15:25 +0300 (IDT) Received: from HOME-C4E4A596F7 ([84.228.8.215]) by a-mtaout20.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0LS800DRP71O9000@a-mtaout20.012.net.il>; Wed, 28 Sep 2011 12:15:25 +0300 (IDT) Date: Wed, 28 Sep 2011 09:39:00 -0000 From: Eli Zaretskii Subject: Re: [RFA] Environment variables passed to inferior by MinGW build (PR 10989) In-reply-to: <8339fjgqy3.fsf@gnu.org> To: brobecker@adacore.com, gdb-patches@sourceware.org Reply-to: Eli Zaretskii Message-id: <83d3elf2oh.fsf@gnu.org> References: <4E7FBF9E.20000@earthlink.net> <20110926171511.GJ17681@adacore.com> <8339fjgqy3.fsf@gnu.org> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-09/txt/msg00469.txt.bz2 > Date: Mon, 26 Sep 2011 20:21:24 +0300 > From: Eli Zaretskii > Cc: gdb-patches@sourceware.org > > > Date: Mon, 26 Sep 2011 10:15:11 -0700 > > From: Joel Brobecker > > Cc: gdb-patches@sourceware.org > > > > Just a few comments: > > Thanks, I will fix all of these. (They came from the original code.) Done. The actual patch I committed is below. I replaced env_sort with envvar_cmp. The last comment, viz.: > > >>>+ for (envlen = 0, i = 0; in_env[i]&& *in_env[i]; i++) > ^^^ formatting of the `&&' ? > didn't need any change, because there's no such problem in the patch I sent. Joel, you were replying to Stan's mail, so I'm guessing that Stan's mail software tried to be overly smart about the formatting of the patch. Thanks for the review and the approval. Could someone with the appropriate authority please close bug #10989, or instruct me how to do that? Index: gdb/ChangeLog =================================================================== RCS file: /cvs/src/src/gdb/ChangeLog,v retrieving revision 1.13362 retrieving revision 1.13363 diff -u -r1.13362 -r1.13363 --- gdb/ChangeLog 27 Sep 2011 15:30:12 -0000 1.13362 +++ gdb/ChangeLog 28 Sep 2011 09:07:54 -0000 1.13363 @@ -1,3 +1,11 @@ +2011-09-28 Eli Zaretskii + + * 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. + 2011-09-27 Tristan Gingold * target.h (enum target_object): Add TARGET_OBJECT_DARWIN_DYLD_INFO. Index: gdb/windows-nat.c =================================================================== RCS file: /cvs/src/src/gdb/windows-nat.c,v retrieving revision 1.218 retrieving revision 1.219 diff -u -p -r1.218 -r1.219 --- gdb/windows-nat.c 9 May 2011 14:25:37 -0000 1.218 +++ gdb/windows-nat.c 28 Sep 2011 09:07:54 -0000 1.219 @@ -1951,6 +1951,18 @@ windows_set_console_info (STARTUPINFO *s *flags |= CREATE_NEW_CONSOLE; } +#ifndef __CYGWIN__ +/* Function called by qsort to sort environment strings. */ + +static int +envvar_cmp (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 +1989,12 @@ windows_create_inferior (struct target_o 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 +2142,31 @@ windows_create_inferior (struct target_o } } + /* 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 *), envvar_cmp); + + 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 +2174,7 @@ windows_create_inferior (struct target_o NULL, /* thread */ TRUE, /* inherit handles */ flags, /* start flags */ - NULL, /* environment */ + w32env, /* environment */ NULL, /* current directory */ &si, &pi);