diff options
author | Eli Zaretskii <eliz@gnu.org> | 2011-09-28 09:07:54 +0000 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2011-09-28 09:07:54 +0000 |
commit | c93dbcba1610184a86722f2b547e19467c7635c8 (patch) | |
tree | 9f8ebaca1dbe0b6976dd76bcded1f3fd292d6598 /gdb/windows-nat.c | |
parent | a82526dd007744ca9ccb07226c934d7d70ef93fb (diff) | |
download | gdb-c93dbcba1610184a86722f2b547e19467c7635c8.zip gdb-c93dbcba1610184a86722f2b547e19467c7635c8.tar.gz gdb-c93dbcba1610184a86722f2b547e19467c7635c8.tar.bz2 |
Support "set environment" and "unset environment" in MinGW builds.
* 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.
Diffstat (limited to 'gdb/windows-nat.c')
-rw-r--r-- | gdb/windows-nat.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 8096f95..731fc3e 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1951,6 +1951,18 @@ windows_set_console_info (STARTUPINFO *si, DWORD *flags) *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_ops *ops, char *exec_file, 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_ops *ops, char *exec_file, } } + /* 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_ops *ops, char *exec_file, NULL, /* thread */ TRUE, /* inherit handles */ flags, /* start flags */ - NULL, /* environment */ + w32env, /* environment */ NULL, /* current directory */ &si, &pi); |