From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17145 invoked by alias); 21 Apr 2011 09:02:31 -0000 Received: (qmail 17137 invoked by uid 22791); 21 Apr 2011 09:02:29 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_00,MSGID_MULTIPLE_AT X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.156) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 21 Apr 2011 09:02:06 +0000 Received: from md2.u-strasbg.fr (md2.u-strasbg.fr [IPv6:2001:660:2402::187]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id p3L91sxm094140 ; Thu, 21 Apr 2011 11:01:54 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms2.u-strasbg.fr [130.79.204.11]) by md2.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p3L91rMU015932 ; Thu, 21 Apr 2011 11:01:53 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from E6510Muller (gw-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p3L91qM0061752 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) ; Thu, 21 Apr 2011 11:01:52 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: Cc: "'Pedro Alves'" , "'Tom Tromey'" References: <5928.31498147479$1302882967@news.gmane.org> <000201cbff30$e2266030$a6732090$@muller@ics-cnrs.unistra.fr> <201104202208.15956.pedro@codesourcery.com> <002c01cbfff1$53197690$f94c63b0$@muller@ics-cnrs.unistra.fr> <003e01cbfff4$18f602f0$4ae208d0$@muller@ics-cnrs.unistra.fr> In-Reply-To: <003e01cbfff4$18f602f0$4ae208d0$@muller@ics-cnrs.unistra.fr> Subject: RE: [RFA-v6] Handle cygwin wchar_t specifics Date: Thu, 21 Apr 2011 09:02:00 -0000 Message-ID: <005001cc0002$c2839680$478ac380$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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-04/txt/msg00383.txt.bz2 Whoops, I just ran a test on a Compile farm machine x86_64-unknown-linux-gnu., there was one more problem : sizeof return type seems to be a "long unsigned int" at least on x86_64 linux. Thus we do need two typecasts around sizeof (gdb_wchar_t) * 8 and sizeof (gdb_wchar_t) in the xstrprintf parameters. After that change, no char related testsuite changes appear. Below is the modified patch that also included the needed typecasts. Pierre 2011-04-21 Pierre Muller * gdb_wchar.h (USE_INTERMEDIATE_ENCODING_FUNCTION): New macro. (INTERMEDIATE_ENCODING): Change value to intermediate_encoding function call if __STDC_ISO_10646__ macro is defined. (intermediate_encoding): New prototype. * charset.c (your_gdb_wchar_t_is_bogus): New extern test variable to generate compile time error for unsupported gdb_wchar_t size. (ENDIAN_SUFFIX): New macro. (intermediate_encoding): New function. Index: src/gdb/gdb_wchar.h =================================================================== RCS file: /cvs/src/src/gdb/gdb_wchar.h,v retrieving revision 1.6 diff -u -p -r1.6 gdb_wchar.h --- src/gdb/gdb_wchar.h 1 Jan 2011 15:33:05 -0000 1.6 +++ src/gdb/gdb_wchar.h 21 Apr 2011 07:35:52 -0000 @@ -78,11 +78,10 @@ typedef wint_t gdb_wint_t; iconv_open. We put the endianness into the encoding name to avoid hosts that emit a BOM when the unadorned name is used. */ #if defined (__STDC_ISO_10646__) -#if WORDS_BIGENDIAN -#define INTERMEDIATE_ENCODING "UCS-4BE" -#else -#define INTERMEDIATE_ENCODING "UCS-4LE" -#endif +#define USE_INTERMEDIATE_ENCODING_FUNCTION +#define INTERMEDIATE_ENCODING intermediate_encoding () +const char *intermediate_encoding (void); + #elif defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108 #define INTERMEDIATE_ENCODING "wchar_t" #else Index: src/gdb/charset.c =================================================================== RCS file: /cvs/src/src/gdb/charset.c,v retrieving revision 1.43 diff -u -p -r1.43 charset.c --- src/gdb/charset.c 11 Jan 2011 15:10:01 -0000 1.43 +++ src/gdb/charset.c 21 Apr 2011 07:35:52 -0000 @@ -922,6 +922,72 @@ default_auto_wide_charset (void) return GDB_DEFAULT_TARGET_WIDE_CHARSET; } + +#ifdef USE_INTERMEDIATE_ENCODING_FUNCTION +/* Macro used for UTF or UCS endianness suffix. */ +#if WORDS_BIGENDIAN +#define ENDIAN_SUFFIX "BE" +#else +#define ENDIAN_SUFFIX "LE" +#endif + +/* The code below serves to generate a compile time error if + gdb_wchar_t type is not of size 2 nor 4, despite the fact that + macro __STDC_ISO_10646__ is defined. + This is better than a gdb_assert call, because GDB cannot handle + strings correctly if this size is different. */ + +extern char your_gdb_wchar_t_is_bogus[(sizeof (gdb_wchar_t) == 2 + || sizeof (gdb_wchar_t) == 4) + ? 1 : -1]; + +/* intermediate_encoding returns the charset unsed internally by + GDB to convert between target and host encodings. As the test above + compiled, sizeof (gdb_wchar_t) is either 2 or 4 bytes. + UTF-16/32 is tested first, UCS-2/4 is tested as a second option, + otherwise an error is generated. */ + +const char * +intermediate_encoding (void) +{ + iconv_t desc; + static const char *stored_result = NULL; + char *result; + int i; + + if (stored_result) + return stored_result; + result = xstrprintf ("UTF-%d%s", (int) (sizeof (gdb_wchar_t) * 8), + ENDIAN_SUFFIX); + /* Check that the name is supported by iconv_open. */ + desc = iconv_open (result, host_charset ()); + if (desc != (iconv_t) -1) + { + iconv_close (desc); + stored_result = result; + return result; + } + /* Not valid, free the allocated memory. */ + xfree (result); + /* Second try, with UCS-2 type. */ + result = xstrprintf ("UCS-%d%s", (int) sizeof (gdb_wchar_t), + ENDIAN_SUFFIX); + /* Check that the name is supported by iconv_open. */ + desc = iconv_open (result, host_charset ()); + if (desc != (iconv_t) -1) + { + iconv_close (desc); + stored_result = result; + return result; + } + /* Not valid, free the allocated memory. */ + xfree (result); + /* No valid charset found, generate error here. */ + error (_("Unable to find a vaild charset for string conversions")); +} + +#endif /* USE_INTERMEDIATE_ENCODING_FUNCTION */ + void _initialize_charset (void) {