1 /* Character set conversion support for GDB.
3 Copyright (C) 2001, 2003, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_assert.h"
25 #include "gdb_obstack.h"
27 #include "charset-list.h"
30 #include "arch-utils.h"
33 #include "gdb_string.h"
40 /* How GDB's character set support works
42 GDB has three global settings:
44 - The `current host character set' is the character set GDB should
45 use in talking to the user, and which (hopefully) the user's
46 terminal knows how to display properly. Most users should not
49 - The `current target character set' is the character set the
50 program being debugged uses.
52 - The `current target wide character set' is the wide character set
53 the program being debugged uses, that is, the encoding used for
56 There are commands to set each of these, and mechanisms for
57 choosing reasonable default values. GDB has a global list of
58 character sets that it can use as its host or target character
61 The header file `charset.h' declares various functions that
62 different pieces of GDB need to perform tasks like:
64 - printing target strings and characters to the user's terminal
65 (mostly target->host conversions),
67 - building target-appropriate representations of strings and
68 characters the user enters in expressions (mostly host->target
73 To avoid excessive code duplication and maintenance efforts,
74 GDB simply requires a capable iconv function. Users on platforms
75 without a suitable iconv can use the GNU iconv library. */
80 /* Provide a phony iconv that does as little as possible. Also,
81 arrange for there to be a single available character set. */
83 #undef GDB_DEFAULT_HOST_CHARSET
84 #define GDB_DEFAULT_HOST_CHARSET "ISO-8859-1"
85 #define GDB_DEFAULT_TARGET_CHARSET "ISO-8859-1"
86 #define GDB_DEFAULT_TARGET_WIDE_CHARSET "ISO-8859-1"
87 #undef DEFAULT_CHARSET_NAMES
88 #define DEFAULT_CHARSET_NAMES GDB_DEFAULT_HOST_CHARSET ,
93 #define iconv_open phony_iconv_open
95 #define iconv phony_iconv
97 #define iconv_close phony_iconv_close
100 #define ICONV_CONST const
102 /* Some systems don't have EILSEQ, so we define it here, but not as
103 EINVAL, because callers of `iconv' want to distinguish EINVAL and
104 EILSEQ. This is what iconv.h from libiconv does as well. Note
105 that wchar.h may also define EILSEQ, so this needs to be after we
106 include wchar.h, which happens in defs.h through gdb_wchar.h. */
108 #define EILSEQ ENOENT
112 phony_iconv_open (const char *to, const char *from)
114 /* We allow conversions from UTF-32BE, wchar_t, and the host charset.
115 We allow conversions to wchar_t and the host charset. */
116 if (strcmp (from, "UTF-32BE") && strcmp (from, "wchar_t")
117 && strcmp (from, GDB_DEFAULT_HOST_CHARSET))
119 if (strcmp (to, "wchar_t") && strcmp (to, GDB_DEFAULT_HOST_CHARSET))
122 /* Return 1 if we are converting from UTF-32BE, 0 otherwise. This is
123 used as a flag in calls to iconv. */
124 return !strcmp (from, "UTF-32BE");
128 phony_iconv_close (iconv_t arg)
134 phony_iconv (iconv_t utf_flag, const char **inbuf, size_t *inbytesleft,
135 char **outbuf, size_t *outbytesleft)
139 while (*inbytesleft >= 4)
144 for (j = 0; j < 4; ++j)
147 c += (*inbuf)[j] & 0xff;
162 if (*inbytesleft < 4)
170 /* In all other cases we simply copy input bytes to the
172 size_t amt = *inbytesleft;
174 if (amt > *outbytesleft)
176 memcpy (*outbuf, *inbuf, amt);
180 *outbytesleft -= amt;
189 /* The number of non-reversible conversions -- but they were all
198 /* The global lists of character sets and translations. */
201 #ifndef GDB_DEFAULT_TARGET_CHARSET
202 #define GDB_DEFAULT_TARGET_CHARSET "ISO-8859-1"
205 #ifndef GDB_DEFAULT_TARGET_WIDE_CHARSET
206 #define GDB_DEFAULT_TARGET_WIDE_CHARSET "UTF-32"
209 static const char *auto_host_charset_name = GDB_DEFAULT_HOST_CHARSET;
210 static const char *host_charset_name = "auto";
212 show_host_charset_name (struct ui_file *file, int from_tty,
213 struct cmd_list_element *c,
216 if (!strcmp (value, "auto"))
217 fprintf_filtered (file,
218 _("The host character set is \"auto; currently %s\".\n"),
219 auto_host_charset_name);
221 fprintf_filtered (file, _("The host character set is \"%s\".\n"), value);
224 static const char *target_charset_name = "auto";
226 show_target_charset_name (struct ui_file *file, int from_tty,
227 struct cmd_list_element *c, const char *value)
229 if (!strcmp (value, "auto"))
230 fprintf_filtered (file,
231 _("The target character set is \"auto; "
232 "currently %s\".\n"),
233 gdbarch_auto_charset (get_current_arch ()));
235 fprintf_filtered (file, _("The target character set is \"%s\".\n"),
239 static const char *target_wide_charset_name = "auto";
241 show_target_wide_charset_name (struct ui_file *file,
243 struct cmd_list_element *c,
246 if (!strcmp (value, "auto"))
247 fprintf_filtered (file,
248 _("The target wide character set is \"auto; "
249 "currently %s\".\n"),
250 gdbarch_auto_wide_charset (get_current_arch ()));
252 fprintf_filtered (file, _("The target wide character set is \"%s\".\n"),
256 static const char *default_charset_names[] =
258 DEFAULT_CHARSET_NAMES
262 static const char **charset_enum;
265 /* If the target wide character set has big- or little-endian
266 variants, these are the corresponding names. */
267 static const char *target_wide_charset_be_name;
268 static const char *target_wide_charset_le_name;
270 /* The architecture for which the BE- and LE-names are valid. */
271 static struct gdbarch *be_le_arch;
273 /* A helper function which sets the target wide big- and little-endian
274 character set names, if possible. */
277 set_be_le_names (struct gdbarch *gdbarch)
280 const char *target_wide;
282 if (be_le_arch == gdbarch)
284 be_le_arch = gdbarch;
286 target_wide_charset_le_name = NULL;
287 target_wide_charset_be_name = NULL;
289 target_wide = target_wide_charset_name;
290 if (!strcmp (target_wide, "auto"))
291 target_wide = gdbarch_auto_wide_charset (gdbarch);
293 len = strlen (target_wide);
294 for (i = 0; charset_enum[i]; ++i)
296 if (strncmp (target_wide, charset_enum[i], len))
298 if ((charset_enum[i][len] == 'B'
299 || charset_enum[i][len] == 'L')
300 && charset_enum[i][len + 1] == 'E'
301 && charset_enum[i][len + 2] == '\0')
303 if (charset_enum[i][len] == 'B')
304 target_wide_charset_be_name = charset_enum[i];
306 target_wide_charset_le_name = charset_enum[i];
311 /* 'Set charset', 'set host-charset', 'set target-charset', 'set
312 target-wide-charset', 'set charset' sfunc's. */
315 validate (struct gdbarch *gdbarch)
318 const char *host_cset = host_charset ();
319 const char *target_cset = target_charset (gdbarch);
320 const char *target_wide_cset = target_wide_charset_name;
322 if (!strcmp (target_wide_cset, "auto"))
323 target_wide_cset = gdbarch_auto_wide_charset (gdbarch);
325 desc = iconv_open (target_wide_cset, host_cset);
326 if (desc == (iconv_t) -1)
327 error (_("Cannot convert between character sets `%s' and `%s'"),
328 target_wide_cset, host_cset);
331 desc = iconv_open (target_cset, host_cset);
332 if (desc == (iconv_t) -1)
333 error (_("Cannot convert between character sets `%s' and `%s'"),
334 target_cset, host_cset);
337 /* Clear the cache. */
341 /* This is the sfunc for the 'set charset' command. */
343 set_charset_sfunc (char *charset, int from_tty,
344 struct cmd_list_element *c)
346 /* CAREFUL: set the target charset here as well. */
347 target_charset_name = host_charset_name;
348 validate (get_current_arch ());
351 /* 'set host-charset' command sfunc. We need a wrapper here because
352 the function needs to have a specific signature. */
354 set_host_charset_sfunc (char *charset, int from_tty,
355 struct cmd_list_element *c)
357 validate (get_current_arch ());
360 /* Wrapper for the 'set target-charset' command. */
362 set_target_charset_sfunc (char *charset, int from_tty,
363 struct cmd_list_element *c)
365 validate (get_current_arch ());
368 /* Wrapper for the 'set target-wide-charset' command. */
370 set_target_wide_charset_sfunc (char *charset, int from_tty,
371 struct cmd_list_element *c)
373 validate (get_current_arch ());
376 /* sfunc for the 'show charset' command. */
378 show_charset (struct ui_file *file, int from_tty,
379 struct cmd_list_element *c,
382 show_host_charset_name (file, from_tty, c, host_charset_name);
383 show_target_charset_name (file, from_tty, c, target_charset_name);
384 show_target_wide_charset_name (file, from_tty, c,
385 target_wide_charset_name);
389 /* Accessor functions. */
394 if (!strcmp (host_charset_name, "auto"))
395 return auto_host_charset_name;
396 return host_charset_name;
400 target_charset (struct gdbarch *gdbarch)
402 if (!strcmp (target_charset_name, "auto"))
403 return gdbarch_auto_charset (gdbarch);
404 return target_charset_name;
408 target_wide_charset (struct gdbarch *gdbarch)
410 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
412 set_be_le_names (gdbarch);
413 if (byte_order == BFD_ENDIAN_BIG)
415 if (target_wide_charset_be_name)
416 return target_wide_charset_be_name;
420 if (target_wide_charset_le_name)
421 return target_wide_charset_le_name;
424 if (!strcmp (target_wide_charset_name, "auto"))
425 return gdbarch_auto_wide_charset (gdbarch);
427 return target_wide_charset_name;
431 /* Host character set management. For the time being, we assume that
432 the host character set is some superset of ASCII. */
435 host_letter_to_control_character (char c)
442 /* Convert a host character, C, to its hex value. C must already have
443 been validated using isxdigit. */
446 host_hex_value (char c)
450 if (c >= 'a' && c <= 'f')
452 gdb_assert (c >= 'A' && c <= 'F');
457 /* Public character management functions. */
459 /* A cleanup function which is run to close an iconv descriptor. */
462 cleanup_iconv (void *p)
465 iconv_close (*descp);
469 convert_wchar (gdb_wchar_t **pinp, size_t *pinleft, char **poutp, size_t *poutleft)
471 char tmp[MB_CUR_MAX];
474 while (*pinleft >= sizeof(gdb_wchar_t))
476 r = wctomb(tmp, **pinp);
479 perror_with_name ("Internal error while converting character sets");
487 memcpy(*poutp, tmp, r);
491 *pinleft -= sizeof(gdb_wchar_t);
501 convert_between_encodings (const char *from, const char *to,
502 const gdb_byte *bytes, unsigned int num_bytes,
503 int width, struct obstack *output,
504 enum transliterations translit)
507 struct cleanup *cleanups;
510 unsigned int space_request;
513 /* Often, the host and target charsets will be the same. */
514 if (!strcmp (from, to))
516 obstack_grow (output, bytes, num_bytes);
520 if (!strcmp (from, "wchar_t"))
522 if (strcmp (to, host_charset ()))
523 perror_with_name (_("Converting character sets"));
524 cleanups = NULL; /* silence gcc complaints */
529 desc = iconv_open (to, from);
530 if (desc == (iconv_t) -1)
531 perror_with_name (_("Converting character sets"));
532 cleanups = make_cleanup (cleanup_iconv, &desc);
536 inp = (char *) bytes;
538 space_request = num_bytes;
546 old_size = obstack_object_size (output);
547 obstack_blank (output, space_request);
549 outp = obstack_base (output) + old_size;
550 outleft = space_request;
553 r = convert_wchar((gdb_wchar_t **)(void *)&inp, &inleft, &outp, &outleft);
555 r = iconv (desc, (ICONV_CONST char **) &inp, &inleft, &outp, &outleft);
557 /* Now make sure that the object on the obstack only includes
558 bytes we have converted. */
559 obstack_blank (output, - (int) outleft);
561 if (r == (size_t) -1)
569 /* Invalid input sequence. */
570 if (translit == translit_none)
571 error (_("Could not convert character "
572 "to `%s' character set"), to);
574 /* We emit escape sequence for the bytes, skip them,
576 for (i = 0; i < width; ++i)
580 sprintf (octal, "\\%.3o", *inp & 0xff);
581 obstack_grow_str (output, octal);
590 /* We ran out of space in the output buffer. Make it
591 bigger next time around. */
596 /* Incomplete input sequence. FIXME: ought to report this
597 to the caller somehow. */
602 perror_with_name (_("Internal error while "
603 "converting character sets"));
609 do_cleanups (cleanups);
614 /* An iterator that returns host wchar_t's from a target string. */
615 struct wchar_iterator
617 /* The underlying iconv descriptor. */
620 /* The input string. This is updated as convert characters. */
622 /* The number of bytes remaining in the input. */
625 /* The width of an input character. */
628 /* The intermediate buffer */
633 /* The output byte. */
637 /* Create a new iterator. */
638 struct wchar_iterator *
639 make_wchar_iterator (const gdb_byte *input, size_t bytes,
640 const char *charset, size_t width)
642 struct wchar_iterator *result;
645 desc = iconv_open (host_charset (), charset);
646 if (desc == (iconv_t) -1)
647 perror_with_name (_("Converting character sets"));
649 result = XNEW (struct wchar_iterator);
651 result->input = (char *) input;
652 result->bytes = bytes;
653 result->width = width;
655 result->inter = XNEW (char);
656 result->inter_size = 1;
657 result->inter_len = 0;
663 do_cleanup_iterator (void *p)
665 struct wchar_iterator *iter = p;
667 iconv_close (iter->desc);
673 make_cleanup_wchar_iterator (struct wchar_iterator *iter)
675 return make_cleanup (do_cleanup_iterator, iter);
679 wchar_iterate (struct wchar_iterator *iter,
680 enum wchar_iterate_result *out_result,
681 gdb_wchar_t **out_chars,
682 const gdb_byte **ptr,
686 char *orig_inptr = iter->input;
687 size_t orig_in = iter->bytes;
689 /* Try to convert some characters. At first we try to convert just
690 a single character. The reason for this is that iconv does not
691 necessarily update its outgoing arguments when it encounters an
692 invalid input sequence -- but we want to reliably report this to
693 our caller so it can emit an escape sequence. */
694 while (iter->inter_len == 0 && iter->bytes > 0)
697 while (iter->bytes > 0)
699 char *outptr = (char *) &iter->inter[iter->inter_len];
700 size_t out_avail = out_request;
702 size_t r = iconv (iter->desc,
703 (ICONV_CONST char **) &iter->input, &iter->bytes,
704 &outptr, &out_avail);
705 if (r == (size_t) -1)
710 /* Invalid input sequence. Skip it, and let the caller
712 *out_result = wchar_iterate_invalid;
715 iter->input += iter->width;
716 iter->bytes -= iter->width;
720 /* We ran out of space. We still might have converted a
721 character; if so, return it. Otherwise, grow the
722 buffer and try again. */
723 if (out_avail < out_request)
727 if (out_request > iter->inter_size)
729 iter->inter_size = out_request;
730 iter->inter = xrealloc (iter->inter, out_request);
735 /* Incomplete input sequence. Let the caller know, and
736 arrange for future calls to see EOF. */
737 *out_result = wchar_iterate_incomplete;
744 perror_with_name (_("Internal error while "
745 "converting character sets"));
749 /* We converted something. */
750 iter->inter_len += out_request - out_avail;
755 if (iter->inter_len > 0)
759 /* Now convert from our charset to wchar_t */
760 r = mbtowc(&iter->out, &iter->inter[0], iter->inter_len);
762 /* This must never happen: we just converted to a valid charset! */
764 perror_with_name (_("Internal error while "
765 "converting character sets"));
767 /* NUL bytes are alright */
771 iter->inter_len -= r;
772 memmove(&iter->inter[0], &iter->inter[r], iter->inter_len);
774 *out_result = wchar_iterate_ok;
775 *out_chars = &iter->out;
777 *len = orig_in - iter->bytes;
782 *out_result = wchar_iterate_eof;
787 /* The charset.c module initialization function. */
789 extern initialize_file_ftype _initialize_charset; /* -Wmissing-prototype */
791 DEF_VEC_P (char_ptr);
793 static VEC (char_ptr) *charsets;
798 find_charset_names (void)
800 VEC_safe_push (char_ptr, charsets, GDB_DEFAULT_HOST_CHARSET);
801 VEC_safe_push (char_ptr, charsets, NULL);
804 #else /* PHONY_ICONV */
806 /* Sometimes, libiconv redefines iconvlist as libiconvlist -- but
807 provides different symbols in the static and dynamic libraries.
808 So, configure may see libiconvlist but not iconvlist. But, calling
809 iconvlist is the right thing to do and will work. Hence we do a
810 check here but unconditionally call iconvlist below. */
811 #if defined (HAVE_ICONVLIST) || defined (HAVE_LIBICONVLIST)
813 /* A helper function that adds some character sets to the vector of
814 all character sets. This is a callback function for iconvlist. */
817 add_one (unsigned int count, const char *const *names, void *data)
821 for (i = 0; i < count; ++i)
822 VEC_safe_push (char_ptr, charsets, xstrdup (names[i]));
828 find_charset_names (void)
830 iconvlist (add_one, NULL);
831 VEC_safe_push (char_ptr, charsets, NULL);
836 /* Return non-zero if LINE (output from iconv) should be ignored.
837 Older iconv programs (e.g. 2.2.2) include the human readable
838 introduction even when stdout is not a tty. Newer versions omit
839 the intro if stdout is not a tty. */
842 ignore_line_p (const char *line)
844 /* This table is used to filter the output. If this text appears
845 anywhere in the line, it is ignored (strstr is used). */
846 static const char * const ignore_lines[] =
851 "listed with several",
856 for (i = 0; ignore_lines[i] != NULL; ++i)
858 if (strstr (line, ignore_lines[i]) != NULL)
866 find_charset_names (void)
868 struct pex_obj *child;
872 struct gdb_environ *iconv_env;
874 /* Older iconvs, e.g. 2.2.2, don't omit the intro text if stdout is
875 not a tty. We need to recognize it and ignore it. This text is
876 subject to translation, so force LANGUAGE=C. */
877 iconv_env = make_environ ();
878 init_environ (iconv_env);
879 set_in_environ (iconv_env, "LANGUAGE", "C");
880 set_in_environ (iconv_env, "LC_ALL", "C");
882 child = pex_init (PEX_USE_PIPES, "iconv", NULL);
887 /* Note that we simply ignore errors here. */
888 if (!pex_run_in_environment (child, PEX_SEARCH | PEX_STDERR_TO_STDOUT,
889 "iconv", args, environ_vector (iconv_env),
892 FILE *in = pex_read_output (child, 0);
894 /* POSIX says that iconv -l uses an unspecified format. We
895 parse the glibc and libiconv formats; feel free to add others
900 /* The size of buf is chosen arbitrarily. */
905 r = fgets (buf, sizeof (buf), in);
911 if (ignore_line_p (r))
914 /* Strip off the newline. */
916 /* Strip off one or two '/'s. glibc will print lines like
917 "8859_7//", but also "10646-1:1993/UCS4/". */
918 if (buf[len - 1] == '/')
920 if (buf[len - 1] == '/')
924 /* libiconv will print multiple entries per line, separated
925 by spaces. Older iconvs will print multiple entries per
926 line, indented by two spaces, and separated by ", "
927 (i.e. the human readable form). */
934 /* Skip leading blanks. */
935 for (p = start; *p && *p == ' '; ++p)
938 /* Find the next space, comma, or end-of-line. */
939 for ( ; *p && *p != ' ' && *p != ','; ++p)
941 /* Ignore an empty result. */
946 VEC_safe_push (char_ptr, charsets, xstrdup (start));
949 /* Skip any extra spaces. */
950 for (start = p + 1; *start && *start == ' '; ++start)
955 if (pex_get_status (child, 1, &status)
956 && WIFEXITED (status) && !WEXITSTATUS (status))
962 free_environ (iconv_env);
966 /* Some error occurred, so drop the vector. */
969 for (ix = 0; VEC_iterate (char_ptr, charsets, ix, elt); ++ix)
971 VEC_truncate (char_ptr, charsets, 0);
974 VEC_safe_push (char_ptr, charsets, NULL);
977 #endif /* HAVE_ICONVLIST || HAVE_LIBICONVLIST */
978 #endif /* PHONY_ICONV */
980 /* The "auto" target charset used by default_auto_charset. */
981 static const char *auto_target_charset_name = GDB_DEFAULT_TARGET_CHARSET;
984 default_auto_charset (void)
986 return auto_target_charset_name;
990 default_auto_wide_charset (void)
992 return GDB_DEFAULT_TARGET_WIDE_CHARSET;
996 #ifdef USE_INTERMEDIATE_ENCODING_FUNCTION
997 /* Macro used for UTF or UCS endianness suffix. */
999 #define ENDIAN_SUFFIX "BE"
1001 #define ENDIAN_SUFFIX "LE"
1004 /* The code below serves to generate a compile time error if
1005 gdb_wchar_t type is not of size 2 nor 4, despite the fact that
1006 macro __STDC_ISO_10646__ is defined.
1007 This is better than a gdb_assert call, because GDB cannot handle
1008 strings correctly if this size is different. */
1010 extern char your_gdb_wchar_t_is_bogus[(sizeof (gdb_wchar_t) == 2
1011 || sizeof (gdb_wchar_t) == 4)
1014 /* intermediate_encoding returns the charset unsed internally by
1015 GDB to convert between target and host encodings. As the test above
1016 compiled, sizeof (gdb_wchar_t) is either 2 or 4 bytes.
1017 UTF-16/32 is tested first, UCS-2/4 is tested as a second option,
1018 otherwise an error is generated. */
1021 intermediate_encoding (void)
1024 static const char *stored_result = NULL;
1029 return stored_result;
1030 result = xstrprintf ("UTF-%d%s", (int) (sizeof (gdb_wchar_t) * 8),
1032 /* Check that the name is supported by iconv_open. */
1033 desc = iconv_open (result, host_charset ());
1034 if (desc != (iconv_t) -1)
1037 stored_result = result;
1040 /* Not valid, free the allocated memory. */
1042 /* Second try, with UCS-2 type. */
1043 result = xstrprintf ("UCS-%d%s", (int) sizeof (gdb_wchar_t),
1045 /* Check that the name is supported by iconv_open. */
1046 desc = iconv_open (result, host_charset ());
1047 if (desc != (iconv_t) -1)
1050 stored_result = result;
1053 /* Not valid, free the allocated memory. */
1055 /* No valid charset found, generate error here. */
1056 error (_("Unable to find a vaild charset for string conversions"));
1059 #endif /* USE_INTERMEDIATE_ENCODING_FUNCTION */
1062 _initialize_charset (void)
1064 /* The first element is always "auto". */
1065 VEC_safe_push (char_ptr, charsets, xstrdup ("auto"));
1066 find_charset_names ();
1068 if (VEC_length (char_ptr, charsets) > 1)
1069 charset_enum = (const char **) VEC_address (char_ptr, charsets);
1071 charset_enum = default_charset_names;
1074 #ifdef HAVE_LANGINFO_CODESET
1075 /* The result of nl_langinfo may be overwritten later. This may
1076 leak a little memory, if the user later changes the host charset,
1077 but that doesn't matter much. */
1078 auto_host_charset_name = xstrdup (nl_langinfo (CODESET));
1079 /* Solaris will return `646' here -- but the Solaris iconv then does
1080 not accept this. Darwin (and maybe FreeBSD) may return "" here,
1081 which GNU libiconv doesn't like (infinite loop). */
1082 if (!strcmp (auto_host_charset_name, "646") || !*auto_host_charset_name)
1083 auto_host_charset_name = "ASCII";
1084 auto_target_charset_name = auto_host_charset_name;
1085 #elif defined (USE_WIN32API)
1087 /* "CP" + x<=5 digits + paranoia. */
1088 static char w32_host_default_charset[16];
1090 snprintf (w32_host_default_charset, sizeof w32_host_default_charset,
1092 auto_host_charset_name = w32_host_default_charset;
1093 auto_target_charset_name = auto_host_charset_name;
1098 add_setshow_enum_cmd ("charset", class_support,
1099 charset_enum, &host_charset_name, _("\
1100 Set the host and target character sets."), _("\
1101 Show the host and target character sets."), _("\
1102 The `host character set' is the one used by the system GDB is running on.\n\
1103 The `target character set' is the one used by the program being debugged.\n\
1104 You may only use supersets of ASCII for your host character set; GDB does\n\
1105 not support any others.\n\
1106 To see a list of the character sets GDB supports, type `set charset <TAB>'."),
1107 /* Note that the sfunc below needs to set
1108 target_charset_name, because the 'set
1109 charset' command sets two variables. */
1112 &setlist, &showlist);
1114 add_setshow_enum_cmd ("host-charset", class_support,
1115 charset_enum, &host_charset_name, _("\
1116 Set the host character set."), _("\
1117 Show the host character set."), _("\
1118 The `host character set' is the one used by the system GDB is running on.\n\
1119 You may only use supersets of ASCII for your host character set; GDB does\n\
1120 not support any others.\n\
1121 To see a list of the character sets GDB supports, type `set host-charset <TAB>'."),
1122 set_host_charset_sfunc,
1123 show_host_charset_name,
1124 &setlist, &showlist);
1126 add_setshow_enum_cmd ("target-charset", class_support,
1127 charset_enum, &target_charset_name, _("\
1128 Set the target character set."), _("\
1129 Show the target character set."), _("\
1130 The `target character set' is the one used by the program being debugged.\n\
1131 GDB translates characters and strings between the host and target\n\
1132 character sets as needed.\n\
1133 To see a list of the character sets GDB supports, type `set target-charset'<TAB>"),
1134 set_target_charset_sfunc,
1135 show_target_charset_name,
1136 &setlist, &showlist);
1138 add_setshow_enum_cmd ("target-wide-charset", class_support,
1139 charset_enum, &target_wide_charset_name,
1141 Set the target wide character set."), _("\
1142 Show the target wide character set."), _("\
1143 The `target wide character set' is the one used by the program being debugged.\
1144 \nIn particular it is the encoding used by `wchar_t'.\n\
1145 GDB translates characters and strings between the host and target\n\
1146 character sets as needed.\n\
1147 To see a list of the character sets GDB supports, type\n\
1148 `set target-wide-charset'<TAB>"),
1149 set_target_wide_charset_sfunc,
1150 show_target_wide_charset_name,
1151 &setlist, &showlist);