aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorPierre Muller <muller@sourceware.org>2011-04-21 14:26:38 +0000
committerPierre Muller <muller@sourceware.org>2011-04-21 14:26:38 +0000
commitbcb28afc532c6defc36fd52db211f3a785a8a6ef (patch)
tree21e6e1cf639d937d7b8810b1724d67ed4d33fa80 /gdb
parent9165b2bff2916b808c29501af6a7f0b48ab794b8 (diff)
downloadgdb-bcb28afc532c6defc36fd52db211f3a785a8a6ef.zip
gdb-bcb28afc532c6defc36fd52db211f3a785a8a6ef.tar.gz
gdb-bcb28afc532c6defc36fd52db211f3a785a8a6ef.tar.bz2
* 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.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog11
-rw-r--r--gdb/charset.c66
-rw-r--r--gdb/gdb_wchar.h9
3 files changed, 81 insertions, 5 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e8c3860..4c81d3a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,14 @@
+2011-04-21 Pierre Muller <muller@ics.u-strasbg.fr>
+
+ * 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.
+
2011-04-20 Jan Kratochvil <jan.kratochvil@redhat.com>
* ada-lang.c (struct add_partial_datum): Update the comment for
diff --git a/gdb/charset.c b/gdb/charset.c
index 41cbc43..a84085a 100644
--- a/gdb/charset.c
+++ b/gdb/charset.c
@@ -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)
{
diff --git a/gdb/gdb_wchar.h b/gdb/gdb_wchar.h
index 4c1b795..daf64ba 100644
--- a/gdb/gdb_wchar.h
+++ b/gdb/gdb_wchar.h
@@ -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