1 /* Character set conversion support for GDB.
3 Copyright (C) 2001-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "gdb_obstack.h"
24 #include "gdbsupport/gdb_wait.h"
25 #include "charset-list.h"
26 #include "gdbsupport/environ.h"
27 #include "arch-utils.h"
28 #include "gdbsupport/gdb_vecs.h"
35 /* How GDB's character set support works
37 GDB has three global settings:
39 - The `current host character set' is the character set GDB should
40 use in talking to the user, and which (hopefully) the user's
41 terminal knows how to display properly. Most users should not
44 - The `current target character set' is the character set the
45 program being debugged uses.
47 - The `current target wide character set' is the wide character set
48 the program being debugged uses, that is, the encoding used for
51 There are commands to set each of these, and mechanisms for
52 choosing reasonable default values. GDB has a global list of
53 character sets that it can use as its host or target character
56 The header file `charset.h' declares various functions that
57 different pieces of GDB need to perform tasks like:
59 - printing target strings and characters to the user's terminal
60 (mostly target->host conversions),
62 - building target-appropriate representations of strings and
63 characters the user enters in expressions (mostly host->target
68 To avoid excessive code duplication and maintenance efforts,
69 GDB simply requires a capable iconv function. Users on platforms
70 without a suitable iconv can use the GNU iconv library. */
75 /* Provide a phony iconv that does as little as possible. Also,
76 arrange for there to be a single available character set. */
78 #undef GDB_DEFAULT_HOST_CHARSET
80 # define GDB_DEFAULT_HOST_CHARSET "CP1252"
82 # define GDB_DEFAULT_HOST_CHARSET "ISO-8859-1"
84 #define GDB_DEFAULT_TARGET_CHARSET GDB_DEFAULT_HOST_CHARSET
85 #define GDB_DEFAULT_TARGET_WIDE_CHARSET "UTF-32"
86 #undef DEFAULT_CHARSET_NAMES
87 #define DEFAULT_CHARSET_NAMES GDB_DEFAULT_HOST_CHARSET ,
92 #define iconv_open phony_iconv_open
94 #define iconv phony_iconv
96 #define iconv_close phony_iconv_close
99 #define ICONV_CONST const
101 /* We allow conversions from UTF-32, wchar_t, and the host charset.
102 We allow conversions to wchar_t and the host charset.
103 Return 1 if we are converting from UTF-32BE, 2 if from UTF32-LE,
104 0 otherwise. This is used as a flag in calls to iconv. */
107 phony_iconv_open (const char *to
, const char *from
)
109 if (strcmp (to
, "wchar_t") && strcmp (to
, GDB_DEFAULT_HOST_CHARSET
))
112 if (!strcmp (from
, "UTF-32BE") || !strcmp (from
, "UTF-32"))
115 if (!strcmp (from
, "UTF-32LE"))
118 if (strcmp (from
, "wchar_t") && strcmp (from
, GDB_DEFAULT_HOST_CHARSET
))
125 phony_iconv_close (iconv_t arg
)
131 phony_iconv (iconv_t utf_flag
, const char **inbuf
, size_t *inbytesleft
,
132 char **outbuf
, size_t *outbytesleft
)
136 enum bfd_endian endian
137 = utf_flag
== 1 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
138 while (*inbytesleft
>= 4)
141 = extract_unsigned_integer ((const gdb_byte
*)*inbuf
, 4, endian
);
148 if (*outbytesleft
< 1)
162 /* Partial sequence on input. */
169 /* In all other cases we simply copy input bytes to the
171 size_t amt
= *inbytesleft
;
173 if (amt
> *outbytesleft
)
175 memcpy (*outbuf
, *inbuf
, amt
);
179 *outbytesleft
-= amt
;
187 /* The number of non-reversible conversions -- but they were all
192 #else /* PHONY_ICONV */
194 /* On systems that don't have EILSEQ, GNU iconv's iconv.h defines it
195 to ENOENT, while gnulib defines it to a different value. Always
196 map ENOENT to gnulib's EILSEQ, leaving callers agnostic. */
199 gdb_iconv (iconv_t utf_flag
, ICONV_CONST
char **inbuf
, size_t *inbytesleft
,
200 char **outbuf
, size_t *outbytesleft
)
204 ret
= iconv (utf_flag
, inbuf
, inbytesleft
, outbuf
, outbytesleft
);
211 #define iconv gdb_iconv
213 #endif /* PHONY_ICONV */
216 /* The global lists of character sets and translations. */
219 #ifndef GDB_DEFAULT_TARGET_CHARSET
220 #define GDB_DEFAULT_TARGET_CHARSET "ISO-8859-1"
223 #ifndef GDB_DEFAULT_TARGET_WIDE_CHARSET
224 #define GDB_DEFAULT_TARGET_WIDE_CHARSET "UTF-32"
227 static const char *auto_host_charset_name
= GDB_DEFAULT_HOST_CHARSET
;
228 static const char *host_charset_name
= "auto";
230 show_host_charset_name (struct ui_file
*file
, int from_tty
,
231 struct cmd_list_element
*c
,
234 if (!strcmp (value
, "auto"))
235 fprintf_filtered (file
,
236 _("The host character set is \"auto; currently %s\".\n"),
237 auto_host_charset_name
);
239 fprintf_filtered (file
, _("The host character set is \"%s\".\n"), value
);
242 static const char *target_charset_name
= "auto";
244 show_target_charset_name (struct ui_file
*file
, int from_tty
,
245 struct cmd_list_element
*c
, const char *value
)
247 if (!strcmp (value
, "auto"))
248 fprintf_filtered (file
,
249 _("The target character set is \"auto; "
250 "currently %s\".\n"),
251 gdbarch_auto_charset (get_current_arch ()));
253 fprintf_filtered (file
, _("The target character set is \"%s\".\n"),
257 static const char *target_wide_charset_name
= "auto";
259 show_target_wide_charset_name (struct ui_file
*file
,
261 struct cmd_list_element
*c
,
264 if (!strcmp (value
, "auto"))
265 fprintf_filtered (file
,
266 _("The target wide character set is \"auto; "
267 "currently %s\".\n"),
268 gdbarch_auto_wide_charset (get_current_arch ()));
270 fprintf_filtered (file
, _("The target wide character set is \"%s\".\n"),
274 static const char *default_charset_names
[] =
276 DEFAULT_CHARSET_NAMES
280 static const char **charset_enum
;
283 /* If the target wide character set has big- or little-endian
284 variants, these are the corresponding names. */
285 static const char *target_wide_charset_be_name
;
286 static const char *target_wide_charset_le_name
;
288 /* The architecture for which the BE- and LE-names are valid. */
289 static struct gdbarch
*be_le_arch
;
291 /* A helper function which sets the target wide big- and little-endian
292 character set names, if possible. */
295 set_be_le_names (struct gdbarch
*gdbarch
)
297 if (be_le_arch
== gdbarch
)
299 be_le_arch
= gdbarch
;
302 /* Match the wide charset names recognized by phony_iconv_open. */
303 target_wide_charset_le_name
= "UTF-32LE";
304 target_wide_charset_be_name
= "UTF-32BE";
307 const char *target_wide
;
309 target_wide_charset_le_name
= NULL
;
310 target_wide_charset_be_name
= NULL
;
312 target_wide
= target_wide_charset_name
;
313 if (!strcmp (target_wide
, "auto"))
314 target_wide
= gdbarch_auto_wide_charset (gdbarch
);
316 len
= strlen (target_wide
);
317 for (i
= 0; charset_enum
[i
]; ++i
)
319 if (strncmp (target_wide
, charset_enum
[i
], len
))
321 if ((charset_enum
[i
][len
] == 'B'
322 || charset_enum
[i
][len
] == 'L')
323 && charset_enum
[i
][len
+ 1] == 'E'
324 && charset_enum
[i
][len
+ 2] == '\0')
326 if (charset_enum
[i
][len
] == 'B')
327 target_wide_charset_be_name
= charset_enum
[i
];
329 target_wide_charset_le_name
= charset_enum
[i
];
332 # endif /* PHONY_ICONV */
335 /* 'Set charset', 'set host-charset', 'set target-charset', 'set
336 target-wide-charset', 'set charset' sfunc's. */
339 validate (struct gdbarch
*gdbarch
)
342 const char *host_cset
= host_charset ();
343 const char *target_cset
= target_charset (gdbarch
);
344 const char *target_wide_cset
= target_wide_charset_name
;
346 if (!strcmp (target_wide_cset
, "auto"))
347 target_wide_cset
= gdbarch_auto_wide_charset (gdbarch
);
349 desc
= iconv_open (target_wide_cset
, host_cset
);
350 if (desc
== (iconv_t
) -1)
351 error (_("Cannot convert between character sets `%s' and `%s'"),
352 target_wide_cset
, host_cset
);
355 desc
= iconv_open (target_cset
, host_cset
);
356 if (desc
== (iconv_t
) -1)
357 error (_("Cannot convert between character sets `%s' and `%s'"),
358 target_cset
, host_cset
);
361 /* Clear the cache. */
365 /* This is the sfunc for the 'set charset' command. */
367 set_charset_sfunc (const char *charset
, int from_tty
,
368 struct cmd_list_element
*c
)
370 /* CAREFUL: set the target charset here as well. */
371 target_charset_name
= host_charset_name
;
372 validate (get_current_arch ());
375 /* 'set host-charset' command sfunc. We need a wrapper here because
376 the function needs to have a specific signature. */
378 set_host_charset_sfunc (const char *charset
, int from_tty
,
379 struct cmd_list_element
*c
)
381 validate (get_current_arch ());
384 /* Wrapper for the 'set target-charset' command. */
386 set_target_charset_sfunc (const char *charset
, int from_tty
,
387 struct cmd_list_element
*c
)
389 validate (get_current_arch ());
392 /* Wrapper for the 'set target-wide-charset' command. */
394 set_target_wide_charset_sfunc (const char *charset
, int from_tty
,
395 struct cmd_list_element
*c
)
397 validate (get_current_arch ());
400 /* sfunc for the 'show charset' command. */
402 show_charset (struct ui_file
*file
, int from_tty
,
403 struct cmd_list_element
*c
,
406 show_host_charset_name (file
, from_tty
, c
, host_charset_name
);
407 show_target_charset_name (file
, from_tty
, c
, target_charset_name
);
408 show_target_wide_charset_name (file
, from_tty
, c
,
409 target_wide_charset_name
);
413 /* Accessor functions. */
418 if (!strcmp (host_charset_name
, "auto"))
419 return auto_host_charset_name
;
420 return host_charset_name
;
424 target_charset (struct gdbarch
*gdbarch
)
426 if (!strcmp (target_charset_name
, "auto"))
427 return gdbarch_auto_charset (gdbarch
);
428 return target_charset_name
;
432 target_wide_charset (struct gdbarch
*gdbarch
)
434 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
436 set_be_le_names (gdbarch
);
437 if (byte_order
== BFD_ENDIAN_BIG
)
439 if (target_wide_charset_be_name
)
440 return target_wide_charset_be_name
;
444 if (target_wide_charset_le_name
)
445 return target_wide_charset_le_name
;
448 if (!strcmp (target_wide_charset_name
, "auto"))
449 return gdbarch_auto_wide_charset (gdbarch
);
451 return target_wide_charset_name
;
455 /* Host character set management. For the time being, we assume that
456 the host character set is some superset of ASCII. */
459 host_letter_to_control_character (char c
)
466 /* Convert a host character, C, to its hex value. C must already have
467 been validated using isxdigit. */
470 host_hex_value (char c
)
474 if (c
>= 'a' && c
<= 'f')
476 gdb_assert (c
>= 'A' && c
<= 'F');
481 /* Public character management functions. */
487 iconv_wrapper (const char *to
, const char *from
)
489 m_desc
= iconv_open (to
, from
);
490 if (m_desc
== (iconv_t
) -1)
491 perror_with_name (_("Converting character sets"));
496 iconv_close (m_desc
);
499 size_t convert (ICONV_CONST
char **inp
, size_t *inleft
, char **outp
,
502 return iconv (m_desc
, inp
, inleft
, outp
, outleft
);
511 convert_between_encodings (const char *from
, const char *to
,
512 const gdb_byte
*bytes
, unsigned int num_bytes
,
513 int width
, struct obstack
*output
,
514 enum transliterations translit
)
517 ICONV_CONST
char *inp
;
518 unsigned int space_request
;
520 /* Often, the host and target charsets will be the same. */
521 if (!strcmp (from
, to
))
523 obstack_grow (output
, bytes
, num_bytes
);
527 iconv_wrapper
desc (to
, from
);
530 inp
= (ICONV_CONST
char *) bytes
;
532 space_request
= num_bytes
;
540 old_size
= obstack_object_size (output
);
541 obstack_blank (output
, space_request
);
543 outp
= (char *) obstack_base (output
) + old_size
;
544 outleft
= space_request
;
546 r
= desc
.convert (&inp
, &inleft
, &outp
, &outleft
);
548 /* Now make sure that the object on the obstack only includes
549 bytes we have converted. */
550 obstack_blank_fast (output
, -(ssize_t
) outleft
);
552 if (r
== (size_t) -1)
560 /* Invalid input sequence. */
561 if (translit
== translit_none
)
562 error (_("Could not convert character "
563 "to `%s' character set"), to
);
565 /* We emit escape sequence for the bytes, skip them,
567 for (i
= 0; i
< width
; ++i
)
571 xsnprintf (octal
, sizeof (octal
), "\\%.3o", *inp
& 0xff);
572 obstack_grow_str (output
, octal
);
581 /* We ran out of space in the output buffer. Make it
582 bigger next time around. */
587 /* Incomplete input sequence. FIXME: ought to report this
588 to the caller somehow. */
593 perror_with_name (_("Internal error while "
594 "converting character sets"));
602 /* Create a new iterator. */
603 wchar_iterator::wchar_iterator (const gdb_byte
*input
, size_t bytes
,
604 const char *charset
, size_t width
)
610 m_desc
= iconv_open (INTERMEDIATE_ENCODING
, charset
);
611 if (m_desc
== (iconv_t
) -1)
612 perror_with_name (_("Converting character sets"));
615 wchar_iterator::~wchar_iterator ()
617 if (m_desc
!= (iconv_t
) -1)
618 iconv_close (m_desc
);
622 wchar_iterator::iterate (enum wchar_iterate_result
*out_result
,
623 gdb_wchar_t
**out_chars
,
624 const gdb_byte
**ptr
,
629 /* Try to convert some characters. At first we try to convert just
630 a single character. The reason for this is that iconv does not
631 necessarily update its outgoing arguments when it encounters an
632 invalid input sequence -- but we want to reliably report this to
633 our caller so it can emit an escape sequence. */
637 ICONV_CONST
char *inptr
= (ICONV_CONST
char *) m_input
;
638 char *outptr
= (char *) m_out
.data ();
639 const gdb_byte
*orig_inptr
= m_input
;
640 size_t orig_in
= m_bytes
;
641 size_t out_avail
= out_request
* sizeof (gdb_wchar_t
);
643 size_t r
= iconv (m_desc
, &inptr
, &m_bytes
, &outptr
, &out_avail
);
645 m_input
= (gdb_byte
*) inptr
;
647 if (r
== (size_t) -1)
652 /* Invalid input sequence. We still might have
653 converted a character; if so, return it. */
654 if (out_avail
< out_request
* sizeof (gdb_wchar_t
))
657 /* Otherwise skip the first invalid character, and let
658 the caller know about it. */
659 *out_result
= wchar_iterate_invalid
;
667 /* We ran out of space. We still might have converted a
668 character; if so, return it. Otherwise, grow the
669 buffer and try again. */
670 if (out_avail
< out_request
* sizeof (gdb_wchar_t
))
674 if (out_request
> m_out
.size ())
675 m_out
.resize (out_request
);
679 /* Incomplete input sequence. Let the caller know, and
680 arrange for future calls to see EOF. */
681 *out_result
= wchar_iterate_incomplete
;
688 perror_with_name (_("Internal error while "
689 "converting character sets"));
693 /* We converted something. */
694 num
= out_request
- out_avail
/ sizeof (gdb_wchar_t
);
695 *out_result
= wchar_iterate_ok
;
696 *out_chars
= m_out
.data ();
698 *len
= orig_in
- m_bytes
;
703 *out_result
= wchar_iterate_eof
;
707 struct charset_vector
716 for (char *c
: charsets
)
722 std::vector
<char *> charsets
;
725 static charset_vector charsets
;
730 find_charset_names (void)
732 charsets
.charsets
.push_back (xstrdup (GDB_DEFAULT_HOST_CHARSET
));
733 charsets
.charsets
.push_back (NULL
);
736 #else /* PHONY_ICONV */
738 /* Sometimes, libiconv redefines iconvlist as libiconvlist -- but
739 provides different symbols in the static and dynamic libraries.
740 So, configure may see libiconvlist but not iconvlist. But, calling
741 iconvlist is the right thing to do and will work. Hence we do a
742 check here but unconditionally call iconvlist below. */
743 #if defined (HAVE_ICONVLIST) || defined (HAVE_LIBICONVLIST)
745 /* A helper function that adds some character sets to the vector of
746 all character sets. This is a callback function for iconvlist. */
749 add_one (unsigned int count
, const char *const *names
, void *data
)
753 for (i
= 0; i
< count
; ++i
)
754 charsets
.charsets
.push_back (xstrdup (names
[i
]));
760 find_charset_names (void)
762 iconvlist (add_one
, NULL
);
764 charsets
.charsets
.push_back (NULL
);
769 /* Return non-zero if LINE (output from iconv) should be ignored.
770 Older iconv programs (e.g. 2.2.2) include the human readable
771 introduction even when stdout is not a tty. Newer versions omit
772 the intro if stdout is not a tty. */
775 ignore_line_p (const char *line
)
777 /* This table is used to filter the output. If this text appears
778 anywhere in the line, it is ignored (strstr is used). */
779 static const char * const ignore_lines
[] =
784 "listed with several",
789 for (i
= 0; ignore_lines
[i
] != NULL
; ++i
)
791 if (strstr (line
, ignore_lines
[i
]) != NULL
)
799 find_charset_names (void)
801 struct pex_obj
*child
;
806 gdb_environ iconv_env
= gdb_environ::from_host_environ ();
809 /* Older iconvs, e.g. 2.2.2, don't omit the intro text if stdout is
810 not a tty. We need to recognize it and ignore it. This text is
811 subject to translation, so force LANGUAGE=C. */
812 iconv_env
.set ("LANGUAGE", "C");
813 iconv_env
.set ("LC_ALL", "C");
815 child
= pex_init (PEX_USE_PIPES
, "iconv", NULL
);
819 std::string iconv_dir
= relocate_gdb_directory (ICONV_BIN
,
820 ICONV_BIN_RELOCATABLE
);
821 iconv_program
= concat (iconv_dir
.c_str(), SLASH_STRING
, "iconv", NULL
);
824 iconv_program
= xstrdup ("iconv");
826 args
[0] = iconv_program
;
829 flags
= PEX_STDERR_TO_STDOUT
;
833 /* Note that we simply ignore errors here. */
834 if (!pex_run_in_environment (child
, flags
,
835 args
[0], const_cast<char **> (args
),
839 FILE *in
= pex_read_output (child
, 0);
841 /* POSIX says that iconv -l uses an unspecified format. We
842 parse the glibc and libiconv formats; feel free to add others
845 while (in
!= NULL
&& !feof (in
))
847 /* The size of buf is chosen arbitrarily. */
852 r
= fgets (buf
, sizeof (buf
), in
);
858 if (ignore_line_p (r
))
861 /* Strip off the newline. */
863 /* Strip off one or two '/'s. glibc will print lines like
864 "8859_7//", but also "10646-1:1993/UCS4/". */
865 if (buf
[len
- 1] == '/')
867 if (buf
[len
- 1] == '/')
871 /* libiconv will print multiple entries per line, separated
872 by spaces. Older iconvs will print multiple entries per
873 line, indented by two spaces, and separated by ", "
874 (i.e. the human readable form). */
881 /* Skip leading blanks. */
882 for (p
= start
; *p
&& *p
== ' '; ++p
)
885 /* Find the next space, comma, or end-of-line. */
886 for ( ; *p
&& *p
!= ' ' && *p
!= ','; ++p
)
888 /* Ignore an empty result. */
893 charsets
.charsets
.push_back (xstrdup (start
));
896 /* Skip any extra spaces. */
897 for (start
= p
+ 1; *start
&& *start
== ' '; ++start
)
902 if (pex_get_status (child
, 1, &status
)
903 && WIFEXITED (status
) && !WEXITSTATUS (status
))
908 xfree (iconv_program
);
913 /* Some error occurred, so drop the vector. */
917 charsets
.charsets
.push_back (NULL
);
920 #endif /* HAVE_ICONVLIST || HAVE_LIBICONVLIST */
921 #endif /* PHONY_ICONV */
923 /* The "auto" target charset used by default_auto_charset. */
924 static const char *auto_target_charset_name
= GDB_DEFAULT_TARGET_CHARSET
;
927 default_auto_charset (void)
929 return auto_target_charset_name
;
933 default_auto_wide_charset (void)
935 return GDB_DEFAULT_TARGET_WIDE_CHARSET
;
939 #ifdef USE_INTERMEDIATE_ENCODING_FUNCTION
940 /* Macro used for UTF or UCS endianness suffix. */
942 #define ENDIAN_SUFFIX "BE"
944 #define ENDIAN_SUFFIX "LE"
947 /* GDB cannot handle strings correctly if this size is different. */
949 gdb_static_assert (sizeof (gdb_wchar_t
) == 2 || sizeof (gdb_wchar_t
) == 4);
951 /* intermediate_encoding returns the charset used internally by
952 GDB to convert between target and host encodings. As the test above
953 compiled, sizeof (gdb_wchar_t) is either 2 or 4 bytes.
954 UTF-16/32 is tested first, UCS-2/4 is tested as a second option,
955 otherwise an error is generated. */
958 intermediate_encoding (void)
961 static const char *stored_result
= NULL
;
965 return stored_result
;
966 result
= xstrprintf ("UTF-%d%s", (int) (sizeof (gdb_wchar_t
) * 8),
968 /* Check that the name is supported by iconv_open. */
969 desc
= iconv_open (result
, host_charset ());
970 if (desc
!= (iconv_t
) -1)
973 stored_result
= result
;
976 /* Not valid, free the allocated memory. */
978 /* Second try, with UCS-2 type. */
979 result
= xstrprintf ("UCS-%d%s", (int) sizeof (gdb_wchar_t
),
981 /* Check that the name is supported by iconv_open. */
982 desc
= iconv_open (result
, host_charset ());
983 if (desc
!= (iconv_t
) -1)
986 stored_result
= result
;
989 /* Not valid, free the allocated memory. */
991 /* No valid charset found, generate error here. */
992 error (_("Unable to find a vaild charset for string conversions"));
995 #endif /* USE_INTERMEDIATE_ENCODING_FUNCTION */
998 _initialize_charset (void)
1000 /* The first element is always "auto". */
1001 charsets
.charsets
.push_back (xstrdup ("auto"));
1002 find_charset_names ();
1004 if (charsets
.charsets
.size () > 1)
1005 charset_enum
= (const char **) charsets
.charsets
.data ();
1007 charset_enum
= default_charset_names
;
1010 #ifdef HAVE_LANGINFO_CODESET
1011 /* The result of nl_langinfo may be overwritten later. This may
1012 leak a little memory, if the user later changes the host charset,
1013 but that doesn't matter much. */
1014 auto_host_charset_name
= xstrdup (nl_langinfo (CODESET
));
1015 /* Solaris will return `646' here -- but the Solaris iconv then does
1016 not accept this. Darwin (and maybe FreeBSD) may return "" here,
1017 which GNU libiconv doesn't like (infinite loop). */
1018 if (!strcmp (auto_host_charset_name
, "646") || !*auto_host_charset_name
)
1019 auto_host_charset_name
= "ASCII";
1020 auto_target_charset_name
= auto_host_charset_name
;
1021 #elif defined (USE_WIN32API)
1023 /* "CP" + x<=5 digits + paranoia. */
1024 static char w32_host_default_charset
[16];
1026 snprintf (w32_host_default_charset
, sizeof w32_host_default_charset
,
1028 auto_host_charset_name
= w32_host_default_charset
;
1029 auto_target_charset_name
= auto_host_charset_name
;
1034 add_setshow_enum_cmd ("charset", class_support
,
1035 charset_enum
, &host_charset_name
, _("\
1036 Set the host and target character sets."), _("\
1037 Show the host and target character sets."), _("\
1038 The `host character set' is the one used by the system GDB is running on.\n\
1039 The `target character set' is the one used by the program being debugged.\n\
1040 You may only use supersets of ASCII for your host character set; GDB does\n\
1041 not support any others.\n\
1042 To see a list of the character sets GDB supports, type `set charset <TAB>'."),
1043 /* Note that the sfunc below needs to set
1044 target_charset_name, because the 'set
1045 charset' command sets two variables. */
1048 &setlist
, &showlist
);
1050 add_setshow_enum_cmd ("host-charset", class_support
,
1051 charset_enum
, &host_charset_name
, _("\
1052 Set the host character set."), _("\
1053 Show the host character set."), _("\
1054 The `host character set' is the one used by the system GDB is running on.\n\
1055 You may only use supersets of ASCII for your host character set; GDB does\n\
1056 not support any others.\n\
1057 To see a list of the character sets GDB supports, type `set host-charset <TAB>'."),
1058 set_host_charset_sfunc
,
1059 show_host_charset_name
,
1060 &setlist
, &showlist
);
1062 add_setshow_enum_cmd ("target-charset", class_support
,
1063 charset_enum
, &target_charset_name
, _("\
1064 Set the target character set."), _("\
1065 Show the target character set."), _("\
1066 The `target character set' is the one used by the program being debugged.\n\
1067 GDB translates characters and strings between the host and target\n\
1068 character sets as needed.\n\
1069 To see a list of the character sets GDB supports, type `set target-charset'<TAB>"),
1070 set_target_charset_sfunc
,
1071 show_target_charset_name
,
1072 &setlist
, &showlist
);
1074 add_setshow_enum_cmd ("target-wide-charset", class_support
,
1075 charset_enum
, &target_wide_charset_name
,
1077 Set the target wide character set."), _("\
1078 Show the target wide character set."), _("\
1079 The `target wide character set' is the one used by the program being debugged.\
1080 \nIn particular it is the encoding used by `wchar_t'.\n\
1081 GDB translates characters and strings between the host and target\n\
1082 character sets as needed.\n\
1083 To see a list of the character sets GDB supports, type\n\
1084 `set target-wide-charset'<TAB>"),
1085 set_target_wide_charset_sfunc
,
1086 show_target_wide_charset_name
,
1087 &setlist
, &showlist
);