From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24740 invoked by alias); 7 Dec 2012 09:22:11 -0000 Received: (qmail 24700 invoked by uid 22791); 7 Dec 2012 09:22:09 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 07 Dec 2012 09:21:58 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 4A70DCB36B1; Fri, 7 Dec 2012 10:22:02 +0100 (CET) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nxboPwWYBWUS; Fri, 7 Dec 2012 10:22:02 +0100 (CET) Received: from chelles.act-europe.fr (chelles.act-europe.fr [10.10.0.160]) by mel.act-europe.fr (Postfix) with ESMTP id 38369CB3681; Fri, 7 Dec 2012 10:22:02 +0100 (CET) Received: by chelles.act-europe.fr (Postfix, from userid 560) id 337101EA005A; Fri, 7 Dec 2012 10:22:02 +0100 (CET) Date: Fri, 07 Dec 2012 09:22:00 -0000 From: Jerome Guitton To: Eli Zaretskii Cc: gdb-patches@sourceware.org Subject: Re: [RFA/mingw32] environment variables are case-insensitive on win32 Message-ID: <20121207092202.GJ7555@adacore.com> References: <1354282597-22691-1-git-send-email-guitton@adacore.com> <834nk7urs0.fsf@gnu.org> <20121130140844.GF2768@adacore.com> <83y5hjt8ll.fsf@gnu.org> <20121130153401.GH2768@adacore.com> <83wqx3t6r9.fsf@gnu.org> <20121130162852.GD32262@adacore.com> <83pq2uudjj.fsf@gnu.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="xo44VMWPx7vlQ2+2" Content-Disposition: inline In-Reply-To: <83pq2uudjj.fsf@gnu.org> User-Agent: Mutt/1.5.21 (2010-09-15) 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: 2012-12/txt/msg00134.txt.bz2 --xo44VMWPx7vlQ2+2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 739 Eli Zaretskii (eliz@gnu.org): > Configure-time test is not good enough, as the binary could then be > run in a different environment. > > How about making it case-insensitive for Cygwin as well? I ended up implementing Pedro's suggestion (a run-time test) but it does not work in the case of Cygwin; getenv/setenv acts as if we add a case-sensitive environment, but we use CreateProcess to create the inferior, so we end up with a case-insensitive environment for the inferior. So making it case-insensitive is indeed what makes sense. Last versions of the patch in attachment, along with the testcase. Fully tested on x86_64-linux; partially tested on Cygwin (e.g. without gdb.threads) amd mingw32 (testenv.exp only). Any comments? --xo44VMWPx7vlQ2+2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="path_case.diff" Content-length: 4403 commit b67dcf26ae8f9ae0390c229518fe34456b4dfe20 Author: Jerome Guitton Date: Wed Dec 5 15:48:29 2012 +0100 Add test for case sensitivity in env vars gdb/testsuite/ChangeLog: * gdb.base/testenv.exp: Check consistent case sensitivity of env variables. diff --git a/gdb/testsuite/gdb.base/testenv.exp b/gdb/testsuite/gdb.base/testenv.exp index 55e3088..4b681a5 100644 --- a/gdb/testsuite/gdb.base/testenv.exp +++ b/gdb/testsuite/gdb.base/testenv.exp @@ -123,3 +123,40 @@ gdb_exit # Clear environment in case we're doing multiple runs unset env(TEST_GDB_GLOBAL) +# Check consistent case sensitivity of env variables +# for GDB and the inferior + +clean_restart $binfile + +set upper_case_value "VAR1" +set mixed_case_value "Var1" +gdb_test_no_output "set env TEST_GDB_VAR1 $upper_case_value" \ + "Set TEST_GDB_VAR1" + +gdb_test_no_output "set env TEST_GDB_Var1 $mixed_case_value" \ + "Set TEST_GDB_Var1" + +set test "Case sensitivity for env vars in GDB" +set var1_value $upper_case_value +set nb_vars 2 +gdb_test_multiple "show env TEST_GDB_VAR1" $test { + -re ".*TEST_GDB_VAR1 = $upper_case_value.*$gdb_prompt $" { + set nb_vars 2 + pass $test + } + -re ".*TEST_GDB_VAR1 = $mixed_case_value.*$gdb_prompt $" { + set nb_vars 1 + pass $test + } +} + +# make sure $pc is sane, in case we're talking to a board. +if { ![runto_main] } { + gdb_suppress_tests; +} + +gdb_breakpoint $bp_line +gdb_test "continue" \ + ".*Program found ${nb_vars} variables starting with TEST_GDB.*" \ + "Case sensitivity for env vars in inferior" +gdb_exit commit df61bd719e348f530419215ce71f344198231d7f Author: Jerome Guitton Date: Thu May 24 18:19:23 2012 +0200 environment variables are case-insensitive on win32 gdb/ChangeLog: * environ.c (host_has_case_sensitive_env_vars) (env_var_name_ncmp): New functions. (get_in_environ, set_in_environ, unset_in_environ): Use env_var_name_ncmp instead of strncmp. diff --git a/gdb/environ.c b/gdb/environ.c index 33426eb..e4cc30c 100644 --- a/gdb/environ.c +++ b/gdb/environ.c @@ -96,6 +96,57 @@ environ_vector (struct gdb_environ *e) return e->vector; } + +/* Return 1 if the names of environ variables are case sensitive + on host. */ + +static int +host_has_case_sensitive_env_vars() +{ + static int result = -1; + char *value; + + if (result != -1) + return result; + + /* On Cygwin, setenv/getenv supports case-sensitive environment + variables; so the run-time check would return 1. However, GDB + uses the windows API to create the inferior, which is case + insensitive. So override the check. */ + +#if defined (__CYGWIN__) + result = 0; + return result; + +#elif defined(_WIN32) && !defined(__CYGWIN__) + putenv ("__GDB_TEST_CASE_SENSITIVITY=set"); + +#else + setenv ("__GDB_TEST_CASE_SENSITIVITY", "set", 1); +#endif + + value = getenv ("__GDB_test_CASE_Sensitivity"); + + if (value && (strcmp (value, "set") == 0)) + result = 0; + else + result = 1; + + return result; +} + +/* Compare the first LENGTH characters of the names of two + environment variable A and B. */ + +static int +env_var_name_ncmp(const char *a, const char *b, int length) +{ + if (host_has_case_sensitive_env_vars()) + return strncmp(a, b, length); + else + return strncasecmp (a, b, length); +} + /* Return the value in environment E of variable VAR. */ char * @@ -106,7 +157,7 @@ get_in_environ (const struct gdb_environ *e, const char *var) char *s; for (; (s = *vector) != NULL; vector++) - if (strncmp (s, var, len) == 0 && s[len] == '=') + if (env_var_name_ncmp (s, var, len) == 0 && s[len] == '=') return &s[len + 1]; return 0; @@ -123,7 +174,7 @@ set_in_environ (struct gdb_environ *e, const char *var, const char *value) char *s; for (i = 0; (s = vector[i]) != NULL; i++) - if (strncmp (s, var, len) == 0 && s[len] == '=') + if (env_var_name_ncmp (s, var, len) == 0 && s[len] == '=') break; if (s == 0) @@ -170,7 +221,7 @@ unset_in_environ (struct gdb_environ *e, char *var) for (; (s = *vector) != NULL; vector++) { - if (strncmp (s, var, len) == 0 && s[len] == '=') + if (env_var_name_ncmp (s, var, len) == 0 && s[len] == '=') { xfree (s); /* Walk through the vector, shuffling args down by one, including --xo44VMWPx7vlQ2+2--