This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [ping] [PATCH] Different outputs affected by locale
- From: Pedro Alves <palves at redhat dot com>
- To: Yao Qi <yao at codesourcery dot com>
- Cc: Tom Tromey <tromey at redhat dot com>, Joel Brobecker <brobecker at adacore dot com>, gdb-patches at sourceware dot org
- Date: Mon, 09 Jun 2014 11:11:46 +0100
- Subject: Re: [ping] [PATCH] Different outputs affected by locale
- Authentication-results: sourceware.org; auth=none
- References: <1401192650-29688-1-git-send-email-yao at codesourcery dot com> <538EAEE5 dot 2080708 at codesourcery dot com> <20140604124708 dot GR4289 at adacore dot com> <538F1CC3 dot 9090605 at codesourcery dot com> <87oay8a0t6 dot fsf at fleche dot redhat dot com> <538F803A dot 9020007 at redhat dot com> <538FE412 dot 1050806 at codesourcery dot com> <53903119 dot 6000204 at redhat dot com> <53903EE5 dot 8090107 at codesourcery dot com> <539042A2 dot 4050409 at redhat dot com> <539571C6 dot 40605 at codesourcery dot com>
On 06/09/2014 09:35 AM, Yao Qi wrote:
> LC_CTYPE isn't set on the Windows machine I am using. set LC_CTYPE=C,
> but the output is unchanged.
>
> I dive into locale stuff, and find something more, in
> main.c:captured_main, gdb does
>
> #if defined (HAVE_SETLOCALE)
> setlocale (LC_CTYPE, "");
> #endif
>
> the man page of setlocale says
>
> If locale is "", each part of the locale that should be modified is set
> according to the environment variables.
>
> That is why we can pass env var to change gdb's locale.
>
> However, looks setlocale on Windows behaves differently when locale is
> "". The msdn about setlocale
> <http://msdn.microsoft.com/en-us/library/x99tb11d.aspx> says "If locale
> points to an empty string, the locale is the implementation-defined
> native environment.", but it doesn't say much on the
> "implementation-defined native environment". The following example
> in the same page gives me some hints,
>
> setlocale( LC_ALL, "" );
> Sets the locale to the default, which is the user-default ANSI code page
> obtained from the operating system.
>
> As far as I can see, windows doesn't consider any env var with
> setlocale(FOO, "").
Correct.
> If I am correct, we can't set gdb's locale by means
> of setting env var,
Not true. It just means that GDB should be doing more
on native Windows, instead of assuming setlocale on Windows
behaves like the POSIX counterpart. See e.g.,
src/intl/localename.c (gettext):
...
/* Let the user override the system settings through environment
variables, as on POSIX systems. */
retval = getenv ("LC_ALL");
if (retval != NULL && retval[0] != '\0')
return retval;
retval = getenv (categoryname);
if (retval != NULL && retval[0] != '\0')
return retval;
retval = getenv ("LANG");
if (retval != NULL && retval[0] != '\0')
return retval;
/* Use native Win32 API locale ID. */
lcid = GetThreadLocale ();
...
etc.
But that code has evolved upstream, and we have the solution
already in gnulib. See:
http://lists.gnu.org/archive/html/bug-gnulib/2011-02/msg00154.html
Newer versions of intl/gettext override setlocale like that too:
http://git.savannah.gnu.org/cgit/gettext.git/tree/gettext-runtime/intl/setlocale.c
> instead, we have to match all the possibilities in
> the testcase. WDYT?
I think the test caught a real GDB bug on Windows, and we
should fix GDB to make it look at the environment variables,
as is expected of GNU programs. And that the best way
to handle this is to import the gnulib setlocale module.
--
Pedro Alves