Re: [ping] [PATCH] Different outputs affected by locale

Yao Qi
2014-06-09T08:37:20Z

On 06/05/2014 06:12 PM, Pedro Alves wrote:
> On 06/05/2014 10:56 AM, Yao Qi wrote:
>> On 06/05/2014 04:58 PM, Pedro Alves wrote:
>
>>>>>>> Does testing GDB manually directly on a Windows console show the same
>>>>>>> issue?
>>>>>
>>>>> Yes, here is the output I got on Windows 7 (running gdb.exe in Windows console).
>>>>> However, I didn't investigate why 'Ã³' is printed.
>>> But was that with LC_CTYPE set to C?
>>
>> I don't know how check LC_CTYPE on Windows. :(
>
> Try "set", and "set /?".
>

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, ""). If I am correct, we can't set gdb's locale by means
of setting env var, instead, we have to match all the possibilities in
the testcase. WDYT?

--
Yao (é½å°§)