This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] Handle cygwin wchar_t specifics


See my email about a problem with GDB on Cygwin.

http://sourceware.org/ml/gdb/2011-04/msg00058.html

  I found out that the problem is related to the
fact that __STDC_ISO_10646__ is defined in:

$ grep -n ISO_10646  /usr/include/*/*
/usr/include/sys/features.h:185:#define __STDC_ISO_10646__ 200305L

because of this, GDB uses "UCS-4LE" 
for the macro INTERMEDIATE_ENCODING on Cygwin 
(while "wchar_t" it uses for mingw32, which works well).

  This assumes that wchar_t is 4 byte long, which is not true for
Cygwin at least...

The patch below fixes this by
explicitly setting the UCS size to two for Windows targets.

  It would probably be good to have this in branch too...

  

Pierre Muller
GDB pascal language maintainer


2011-04-15  Pierre Muller  <muller@ics.u-strasbg.fr>

	Correct INTERMEDIATE_ENCODING macro setup for Cygwin port.
	* gdb_wchar.h (UCS_SIZE): New macro.
	
Index: 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
--- gdb_wchar.h	1 Jan 2011 15:33:05 -0000	1.6
+++ gdb_wchar.h	15 Apr 2011 15:51:52 -0000
@@ -61,6 +61,7 @@
 #include <wchar.h>
 #include <wctype.h>
 
+#define wchar_size  (&(((wchar_t) (0)) + 1) - &((char *) 0))
 typedef wchar_t gdb_wchar_t;
 typedef wint_t gdb_wint_t;
 
@@ -73,18 +74,25 @@ typedef wint_t gdb_wint_t;
 #define LCST(X) L ## X
 
 /* If __STDC_ISO_10646__ is defined, then the host wchar_t is UCS-4.
+   This is not true for Cygwin at least. Windows OS seems to require
+   16-bit wchar_t type, so we handle those especially.
    We exploit this fact in the hope that there are hosts that define
    this but which do not support "wchar_t" as an encoding argument to
    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"
+#if defined (__CYGWIN__) || defined (__MINGW32__)
+#  define UCS_SIZE "2"
 #else
-#define INTERMEDIATE_ENCODING "UCS-4LE"
+#  define UCS_SIZE "4"
 #endif
+#if defined (__STDC_ISO_10646__)
+#  if WORDS_BIGENDIAN
+#    define INTERMEDIATE_ENCODING "UCS-" UCS_SIZE "BE"
+#  else
+#    define INTERMEDIATE_ENCODING "UCS-" UCS_SIZE "LE"
+#  endif
 #elif defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108
-#define INTERMEDIATE_ENCODING "wchar_t"
+#  define INTERMEDIATE_ENCODING "wchar_t"
 #else
 /* This shouldn't happen, because the earlier #if should have filtered
    out this case.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]