1 /* Character set conversion support for GDB.
3 Copyright (C) 2001-2014 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_assert.h"
24 #include "gdb_obstack.h"
26 #include "charset-list.h"
29 #include "arch-utils.h"
39 /* How GDB's character set support works
41 GDB has three global settings:
43 - The `current host character set' is the character set GDB should
44 use in talking to the user, and which (hopefully) the user's
45 terminal knows how to display properly. Most users should not
48 - The `current target character set' is the character set the
49 program being debugged uses.
51 - The `current target wide character set' is the wide character set
52 the program being debugged uses, that is, the encoding used for
55 There are commands to set each of these, and mechanisms for
56 choosing reasonable default values. GDB has a global list of
57 character sets that it can use as its host or target character
60 The header file `charset.h' declares various functions that
61 different pieces of GDB need to perform tasks like:
63 - printing target strings and characters to the user's terminal
64 (mostly target->host conversions),
66 - building target-appropriate representations of strings and
67 characters the user enters in expressions (mostly host->target
72 To avoid excessive code duplication and maintenance efforts,
73 GDB simply requires a capable iconv function. Users on platforms
74 without a suitable iconv can use the GNU iconv library. */
79 /* Provide a phony iconv that does as little as possible. Also,
80 arrange for there to be a single available character set. */
82 #undef GDB_DEFAULT_HOST_CHARSET
83 #define GDB_DEFAULT_HOST_CHARSET "ISO-8859-1"
84 #define GDB_DEFAULT_TARGET_CHARSET "ISO-8859-1"
85 #define GDB_DEFAULT_TARGET_WIDE_CHARSET "ISO-8859-1"
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 /* Some systems don't have EILSEQ, so we define it here, but not as
102 EINVAL, because callers of `iconv' want to distinguish EINVAL and
103 EILSEQ. This is what iconv.h from libiconv does as well. Note
104 that wchar.h may also define EILSEQ, so this needs to be after we
105 include wchar.h, which happens in defs.h through gdb_wchar.h. */
107 #define EILSEQ ENOENT
111 phony_iconv_open (const char *to
, const char *from
)
113 /* We allow conversions from UTF-32BE, wchar_t, and the host charset.
114 We allow conversions to wchar_t and the host charset. */
115 if (strcmp (from
, "UTF-32BE") && strcmp (from
, "wchar_t")
116 && strcmp (from
, GDB_DEFAULT_HOST_CHARSET
))
118 if (strcmp (to
, "wchar_t") && strcmp (to
, GDB_DEFAULT_HOST_CHARSET
))
121 /* Return 1 if we are converting from UTF-32BE, 0 otherwise. This is
122 used as a flag in calls to iconv. */
123 return !strcmp (from
, "UTF-32BE");
127 phony_iconv_close (iconv_t arg
)
133 phony_iconv (iconv_t utf_flag
, const char **inbuf
, size_t *inbytesleft
,
134 char **outbuf
, size_t *outbytesleft
)
138 while (*inbytesleft
>= 4)
143 for (j
= 0; j
< 4; ++j
)
146 c
+= (*inbuf
)[j
] & 0xff;
161 if (*inbytesleft
< 4)
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
;
188 /* The number of non-reversible conversions -- but they were all
197 /* The global lists of character sets and translations. */
200 #ifndef GDB_DEFAULT_TARGET_CHARSET
201 #define GDB_DEFAULT_TARGET_CHARSET "ISO-8859-1"
204 #ifndef GDB_DEFAULT_TARGET_WIDE_CHARSET
205 #define GDB_DEFAULT_TARGET_WIDE_CHARSET "UTF-32"
208 static const char *auto_host_charset_name
= GDB_DEFAULT_HOST_CHARSET
;
209 static const char *host_charset_name
= "auto";
211 show_host_charset_name (struct ui_file
*file
, int from_tty
,
212 struct cmd_list_element
*c
,
215 if (!strcmp (value
, "auto"))
216 fprintf_filtered (file
,
217 _("The host character set is \"auto; currently %s\".\n"),
218 auto_host_charset_name
);
220 fprintf_filtered (file
, _("The host character set is \"%s\".\n"), value
);
223 static const char *target_charset_name
= "auto";
225 show_target_charset_name (struct ui_file
*file
, int from_tty
,
226 struct cmd_list_element
*c
, const char *value
)
228 if (!strcmp (value
, "auto"))
229 fprintf_filtered (file
,
230 _("The target character set is \"auto; "
231 "currently %s\".\n"),
232 gdbarch_auto_charset (get_current_arch ()));
234 fprintf_filtered (file
, _("The target character set is \"%s\".\n"),
238 static const char *target_wide_charset_name
= "auto";
240 show_target_wide_charset_name (struct ui_file
*file
,
242 struct cmd_list_element
*c
,
245 if (!strcmp (value
, "auto"))
246 fprintf_filtered (file
,
247 _("The target wide character set is \"auto; "
248 "currently %s\".\n"),
249 gdbarch_auto_wide_charset (get_current_arch ()));
251 fprintf_filtered (file
, _("The target wide character set is \"%s\".\n"),
255 static const char *default_charset_names
[] =
257 DEFAULT_CHARSET_NAMES
261 static const char **charset_enum
;
264 /* If the target wide character set has big- or little-endian
265 variants, these are the corresponding names. */
266 static const char *target_wide_charset_be_name
;
267 static const char *target_wide_charset_le_name
;
269 /* The architecture for which the BE- and LE-names are valid. */
270 static struct gdbarch
*be_le_arch
;
272 /* A helper function which sets the target wide big- and little-endian
273 character set names, if possible. */
276 set_be_le_names (struct gdbarch
*gdbarch
)
279 const char *target_wide
;
281 if (be_le_arch
== gdbarch
)
283 be_le_arch
= gdbarch
;
285 target_wide_charset_le_name
= NULL
;
286 target_wide_charset_be_name
= NULL
;
288 target_wide
= target_wide_charset_name
;
289 if (!strcmp (target_wide
, "auto"))
290 target_wide
= gdbarch_auto_wide_charset (gdbarch
);
292 len
= strlen (target_wide
);
293 for (i
= 0; charset_enum
[i
]; ++i
)
295 if (strncmp (target_wide
, charset_enum
[i
], len
))
297 if ((charset_enum
[i
][len
] == 'B'
298 || charset_enum
[i
][len
] == 'L')
299 && charset_enum
[i
][len
+ 1] == 'E'
300 && charset_enum
[i
][len
+ 2] == '\0')
302 if (charset_enum
[i
][len
] == 'B')
303 target_wide_charset_be_name
= charset_enum
[i
];
305 target_wide_charset_le_name
= charset_enum
[i
];
310 /* 'Set charset', 'set host-charset', 'set target-charset', 'set
311 target-wide-charset', 'set charset' sfunc's. */
314 validate (struct gdbarch
*gdbarch
)
317 const char *host_cset
= host_charset ();
318 const char *target_cset
= target_charset (gdbarch
);
319 const char *target_wide_cset
= target_wide_charset_name
;
321 if (!strcmp (target_wide_cset
, "auto"))
322 target_wide_cset
= gdbarch_auto_wide_charset (gdbarch
);
324 desc
= iconv_open (target_wide_cset
, host_cset
);
325 if (desc
== (iconv_t
) -1)
326 error (_("Cannot convert between character sets `%s' and `%s'"),
327 target_wide_cset
, host_cset
);
330 desc
= iconv_open (target_cset
, host_cset
);
331 if (desc
== (iconv_t
) -1)
332 error (_("Cannot convert between character sets `%s' and `%s'"),
333 target_cset
, host_cset
);
336 /* Clear the cache. */
340 /* This is the sfunc for the 'set charset' command. */
342 set_charset_sfunc (char *charset
, int from_tty
,
343 struct cmd_list_element
*c
)
345 /* CAREFUL: set the target charset here as well. */
346 target_charset_name
= host_charset_name
;
347 validate (get_current_arch ());
350 /* 'set host-charset' command sfunc. We need a wrapper here because
351 the function needs to have a specific signature. */
353 set_host_charset_sfunc (char *charset
, int from_tty
,
354 struct cmd_list_element
*c
)
356 validate (get_current_arch ());
359 /* Wrapper for the 'set target-charset' command. */
361 set_target_charset_sfunc (char *charset
, int from_tty
,
362 struct cmd_list_element
*c
)
364 validate (get_current_arch ());
367 /* Wrapper for the 'set target-wide-charset' command. */
369 set_target_wide_charset_sfunc (char *charset
, int from_tty
,
370 struct cmd_list_element
*c
)
372 validate (get_current_arch ());
375 /* sfunc for the 'show charset' command. */
377 show_charset (struct ui_file
*file
, int from_tty
,
378 struct cmd_list_element
*c
,
381 show_host_charset_name (file
, from_tty
, c
, host_charset_name
);
382 show_target_charset_name (file
, from_tty
, c
, target_charset_name
);
383 show_target_wide_charset_name (file
, from_tty
, c
,
384 target_wide_charset_name
);
388 /* Accessor functions. */
393 if (!strcmp (host_charset_name
, "auto"))
394 return auto_host_charset_name
;
395 return host_charset_name
;
399 target_charset (struct gdbarch
*gdbarch
)
401 if (!strcmp (target_charset_name
, "auto"))
402 return gdbarch_auto_charset (gdbarch
);
403 return target_charset_name
;
407 target_wide_charset (struct gdbarch
*gdbarch
)
409 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
411 set_be_le_names (gdbarch
);
412 if (byte_order
== BFD_ENDIAN_BIG
)
414 if (target_wide_charset_be_name
)
415 return target_wide_charset_be_name
;
419 if (target_wide_charset_le_name
)
420 return target_wide_charset_le_name
;
423 if (!strcmp (target_wide_charset_name
, "auto"))
424 return gdbarch_auto_wide_charset (gdbarch
);
426 return target_wide_charset_name
;
430 /* Host character set management. For the time being, we assume that
431 the host character set is some superset of ASCII. */
434 host_letter_to_control_character (char c
)
441 /* Convert a host character, C, to its hex value. C must already have
442 been validated using isxdigit. */
445 host_hex_value (char c
)
449 if (c
>= 'a' && c
<= 'f')
451 gdb_assert (c
>= 'A' && c
<= 'F');
456 /* Public character management functions. */
458 /* A cleanup function which is run to close an iconv descriptor. */
461 cleanup_iconv (void *p
)
464 iconv_close (*descp
);
468 convert_between_encodings (const char *from
, const char *to
,
469 const gdb_byte
*bytes
, unsigned int num_bytes
,
470 int width
, struct obstack
*output
,
471 enum transliterations translit
)
474 struct cleanup
*cleanups
;
476 ICONV_CONST
char *inp
;
477 unsigned int space_request
;
479 /* Often, the host and target charsets will be the same. */
480 if (!strcmp (from
, to
))
482 obstack_grow (output
, bytes
, num_bytes
);
486 desc
= iconv_open (to
, from
);
487 if (desc
== (iconv_t
) -1)
488 perror_with_name (_("Converting character sets"));
489 cleanups
= make_cleanup (cleanup_iconv
, &desc
);
492 inp
= (ICONV_CONST
char *) bytes
;
494 space_request
= num_bytes
;
502 old_size
= obstack_object_size (output
);
503 obstack_blank (output
, space_request
);
505 outp
= (char *) obstack_base (output
) + old_size
;
506 outleft
= space_request
;
508 r
= iconv (desc
, &inp
, &inleft
, &outp
, &outleft
);
510 /* Now make sure that the object on the obstack only includes
511 bytes we have converted. */
512 obstack_blank (output
, - (int) outleft
);
514 if (r
== (size_t) -1)
522 /* Invalid input sequence. */
523 if (translit
== translit_none
)
524 error (_("Could not convert character "
525 "to `%s' character set"), to
);
527 /* We emit escape sequence for the bytes, skip them,
529 for (i
= 0; i
< width
; ++i
)
533 xsnprintf (octal
, sizeof (octal
), "\\%.3o", *inp
& 0xff);
534 obstack_grow_str (output
, octal
);
543 /* We ran out of space in the output buffer. Make it
544 bigger next time around. */
549 /* Incomplete input sequence. FIXME: ought to report this
550 to the caller somehow. */
555 perror_with_name (_("Internal error while "
556 "converting character sets"));
561 do_cleanups (cleanups
);
566 /* An iterator that returns host wchar_t's from a target string. */
567 struct wchar_iterator
569 /* The underlying iconv descriptor. */
572 /* The input string. This is updated as convert characters. */
573 const gdb_byte
*input
;
574 /* The number of bytes remaining in the input. */
577 /* The width of an input character. */
580 /* The output buffer and its size. */
585 /* Create a new iterator. */
586 struct wchar_iterator
*
587 make_wchar_iterator (const gdb_byte
*input
, size_t bytes
,
588 const char *charset
, size_t width
)
590 struct wchar_iterator
*result
;
593 desc
= iconv_open (INTERMEDIATE_ENCODING
, charset
);
594 if (desc
== (iconv_t
) -1)
595 perror_with_name (_("Converting character sets"));
597 result
= XNEW (struct wchar_iterator
);
599 result
->input
= input
;
600 result
->bytes
= bytes
;
601 result
->width
= width
;
603 result
->out
= XNEW (gdb_wchar_t
);
604 result
->out_size
= 1;
610 do_cleanup_iterator (void *p
)
612 struct wchar_iterator
*iter
= p
;
614 iconv_close (iter
->desc
);
620 make_cleanup_wchar_iterator (struct wchar_iterator
*iter
)
622 return make_cleanup (do_cleanup_iterator
, iter
);
626 wchar_iterate (struct wchar_iterator
*iter
,
627 enum wchar_iterate_result
*out_result
,
628 gdb_wchar_t
**out_chars
,
629 const gdb_byte
**ptr
,
634 /* Try to convert some characters. At first we try to convert just
635 a single character. The reason for this is that iconv does not
636 necessarily update its outgoing arguments when it encounters an
637 invalid input sequence -- but we want to reliably report this to
638 our caller so it can emit an escape sequence. */
640 while (iter
->bytes
> 0)
642 ICONV_CONST
char *inptr
= (ICONV_CONST
char *) iter
->input
;
643 char *outptr
= (char *) &iter
->out
[0];
644 const gdb_byte
*orig_inptr
= iter
->input
;
645 size_t orig_in
= iter
->bytes
;
646 size_t out_avail
= out_request
* sizeof (gdb_wchar_t
);
648 size_t r
= iconv (iter
->desc
, &inptr
, &iter
->bytes
, &outptr
, &out_avail
);
650 iter
->input
= (gdb_byte
*) inptr
;
652 if (r
== (size_t) -1)
657 /* Invalid input sequence. We still might have
658 converted a character; if so, return it. */
659 if (out_avail
< out_request
* sizeof (gdb_wchar_t
))
662 /* Otherwise skip the first invalid character, and let
663 the caller know about it. */
664 *out_result
= wchar_iterate_invalid
;
667 iter
->input
+= iter
->width
;
668 iter
->bytes
-= iter
->width
;
672 /* We ran out of space. We still might have converted a
673 character; if so, return it. Otherwise, grow the
674 buffer and try again. */
675 if (out_avail
< out_request
* sizeof (gdb_wchar_t
))
679 if (out_request
> iter
->out_size
)
681 iter
->out_size
= out_request
;
682 iter
->out
= xrealloc (iter
->out
,
683 out_request
* sizeof (gdb_wchar_t
));
688 /* Incomplete input sequence. Let the caller know, and
689 arrange for future calls to see EOF. */
690 *out_result
= wchar_iterate_incomplete
;
697 perror_with_name (_("Internal error while "
698 "converting character sets"));
702 /* We converted something. */
703 num
= out_request
- out_avail
/ sizeof (gdb_wchar_t
);
704 *out_result
= wchar_iterate_ok
;
705 *out_chars
= iter
->out
;
707 *len
= orig_in
- iter
->bytes
;
712 *out_result
= wchar_iterate_eof
;
717 /* The charset.c module initialization function. */
719 extern initialize_file_ftype _initialize_charset
; /* -Wmissing-prototype */
721 static VEC (char_ptr
) *charsets
;
726 find_charset_names (void)
728 VEC_safe_push (char_ptr
, charsets
, GDB_DEFAULT_HOST_CHARSET
);
729 VEC_safe_push (char_ptr
, charsets
, NULL
);
732 #else /* PHONY_ICONV */
734 /* Sometimes, libiconv redefines iconvlist as libiconvlist -- but
735 provides different symbols in the static and dynamic libraries.
736 So, configure may see libiconvlist but not iconvlist. But, calling
737 iconvlist is the right thing to do and will work. Hence we do a
738 check here but unconditionally call iconvlist below. */
739 #if defined (HAVE_ICONVLIST) || defined (HAVE_LIBICONVLIST)
741 /* A helper function that adds some character sets to the vector of
742 all character sets. This is a callback function for iconvlist. */
745 add_one (unsigned int count
, const char *const *names
, void *data
)
749 for (i
= 0; i
< count
; ++i
)
750 VEC_safe_push (char_ptr
, charsets
, xstrdup (names
[i
]));
756 find_charset_names (void)
758 iconvlist (add_one
, NULL
);
759 VEC_safe_push (char_ptr
, charsets
, NULL
);
764 /* Return non-zero if LINE (output from iconv) should be ignored.
765 Older iconv programs (e.g. 2.2.2) include the human readable
766 introduction even when stdout is not a tty. Newer versions omit
767 the intro if stdout is not a tty. */
770 ignore_line_p (const char *line
)
772 /* This table is used to filter the output. If this text appears
773 anywhere in the line, it is ignored (strstr is used). */
774 static const char * const ignore_lines
[] =
779 "listed with several",
784 for (i
= 0; ignore_lines
[i
] != NULL
; ++i
)
786 if (strstr (line
, ignore_lines
[i
]) != NULL
)
794 find_charset_names (void)
796 struct pex_obj
*child
;
801 struct gdb_environ
*iconv_env
;
804 /* Older iconvs, e.g. 2.2.2, don't omit the intro text if stdout is
805 not a tty. We need to recognize it and ignore it. This text is
806 subject to translation, so force LANGUAGE=C. */
807 iconv_env
= make_environ ();
808 init_environ (iconv_env
);
809 set_in_environ (iconv_env
, "LANGUAGE", "C");
810 set_in_environ (iconv_env
, "LC_ALL", "C");
812 child
= pex_init (PEX_USE_PIPES
, "iconv", NULL
);
816 char *iconv_dir
= relocate_gdb_directory (ICONV_BIN
,
817 ICONV_BIN_RELOCATABLE
);
818 iconv_program
= concat (iconv_dir
, SLASH_STRING
, "iconv", NULL
);
822 iconv_program
= xstrdup ("iconv");
824 args
[0] = iconv_program
;
827 flags
= PEX_STDERR_TO_STDOUT
;
831 /* Note that we simply ignore errors here. */
832 if (!pex_run_in_environment (child
, flags
,
833 args
[0], args
, environ_vector (iconv_env
),
836 FILE *in
= pex_read_output (child
, 0);
838 /* POSIX says that iconv -l uses an unspecified format. We
839 parse the glibc and libiconv formats; feel free to add others
842 while (in
!= NULL
&& !feof (in
))
844 /* The size of buf is chosen arbitrarily. */
849 r
= fgets (buf
, sizeof (buf
), in
);
855 if (ignore_line_p (r
))
858 /* Strip off the newline. */
860 /* Strip off one or two '/'s. glibc will print lines like
861 "8859_7//", but also "10646-1:1993/UCS4/". */
862 if (buf
[len
- 1] == '/')
864 if (buf
[len
- 1] == '/')
868 /* libiconv will print multiple entries per line, separated
869 by spaces. Older iconvs will print multiple entries per
870 line, indented by two spaces, and separated by ", "
871 (i.e. the human readable form). */
878 /* Skip leading blanks. */
879 for (p
= start
; *p
&& *p
== ' '; ++p
)
882 /* Find the next space, comma, or end-of-line. */
883 for ( ; *p
&& *p
!= ' ' && *p
!= ','; ++p
)
885 /* Ignore an empty result. */
890 VEC_safe_push (char_ptr
, charsets
, xstrdup (start
));
893 /* Skip any extra spaces. */
894 for (start
= p
+ 1; *start
&& *start
== ' '; ++start
)
899 if (pex_get_status (child
, 1, &status
)
900 && WIFEXITED (status
) && !WEXITSTATUS (status
))
905 xfree (iconv_program
);
907 free_environ (iconv_env
);
911 /* Some error occurred, so drop the vector. */
912 free_char_ptr_vec (charsets
);
916 VEC_safe_push (char_ptr
, charsets
, NULL
);
919 #endif /* HAVE_ICONVLIST || HAVE_LIBICONVLIST */
920 #endif /* PHONY_ICONV */
922 /* The "auto" target charset used by default_auto_charset. */
923 static const char *auto_target_charset_name
= GDB_DEFAULT_TARGET_CHARSET
;
926 default_auto_charset (void)
928 return auto_target_charset_name
;
932 default_auto_wide_charset (void)
934 return GDB_DEFAULT_TARGET_WIDE_CHARSET
;
938 #ifdef USE_INTERMEDIATE_ENCODING_FUNCTION
939 /* Macro used for UTF or UCS endianness suffix. */
941 #define ENDIAN_SUFFIX "BE"
943 #define ENDIAN_SUFFIX "LE"
946 /* The code below serves to generate a compile time error if
947 gdb_wchar_t type is not of size 2 nor 4, despite the fact that
948 macro __STDC_ISO_10646__ is defined.
949 This is better than a gdb_assert call, because GDB cannot handle
950 strings correctly if this size is different. */
952 extern char your_gdb_wchar_t_is_bogus
[(sizeof (gdb_wchar_t
) == 2
953 || sizeof (gdb_wchar_t
) == 4)
956 /* intermediate_encoding returns the charset used internally by
957 GDB to convert between target and host encodings. As the test above
958 compiled, sizeof (gdb_wchar_t) is either 2 or 4 bytes.
959 UTF-16/32 is tested first, UCS-2/4 is tested as a second option,
960 otherwise an error is generated. */
963 intermediate_encoding (void)
966 static const char *stored_result
= NULL
;
970 return stored_result
;
971 result
= xstrprintf ("UTF-%d%s", (int) (sizeof (gdb_wchar_t
) * 8),
973 /* Check that the name is supported by iconv_open. */
974 desc
= iconv_open (result
, host_charset ());
975 if (desc
!= (iconv_t
) -1)
978 stored_result
= result
;
981 /* Not valid, free the allocated memory. */
983 /* Second try, with UCS-2 type. */
984 result
= xstrprintf ("UCS-%d%s", (int) sizeof (gdb_wchar_t
),
986 /* Check that the name is supported by iconv_open. */
987 desc
= iconv_open (result
, host_charset ());
988 if (desc
!= (iconv_t
) -1)
991 stored_result
= result
;
994 /* Not valid, free the allocated memory. */
996 /* No valid charset found, generate error here. */
997 error (_("Unable to find a vaild charset for string conversions"));
1000 #endif /* USE_INTERMEDIATE_ENCODING_FUNCTION */
1003 _initialize_charset (void)
1005 /* The first element is always "auto". */
1006 VEC_safe_push (char_ptr
, charsets
, xstrdup ("auto"));
1007 find_charset_names ();
1009 if (VEC_length (char_ptr
, charsets
) > 1)
1010 charset_enum
= (const char **) VEC_address (char_ptr
, charsets
);
1012 charset_enum
= default_charset_names
;
1015 #ifdef HAVE_LANGINFO_CODESET
1016 /* The result of nl_langinfo may be overwritten later. This may
1017 leak a little memory, if the user later changes the host charset,
1018 but that doesn't matter much. */
1019 auto_host_charset_name
= xstrdup (nl_langinfo (CODESET
));
1020 /* Solaris will return `646' here -- but the Solaris iconv then does
1021 not accept this. Darwin (and maybe FreeBSD) may return "" here,
1022 which GNU libiconv doesn't like (infinite loop). */
1023 if (!strcmp (auto_host_charset_name
, "646") || !*auto_host_charset_name
)
1024 auto_host_charset_name
= "ASCII";
1025 auto_target_charset_name
= auto_host_charset_name
;
1026 #elif defined (USE_WIN32API)
1028 /* "CP" + x<=5 digits + paranoia. */
1029 static char w32_host_default_charset
[16];
1031 snprintf (w32_host_default_charset
, sizeof w32_host_default_charset
,
1033 auto_host_charset_name
= w32_host_default_charset
;
1034 auto_target_charset_name
= auto_host_charset_name
;
1039 add_setshow_enum_cmd ("charset", class_support
,
1040 charset_enum
, &host_charset_name
, _("\
1041 Set the host and target character sets."), _("\
1042 Show the host and target character sets."), _("\
1043 The `host character set' is the one used by the system GDB is running on.\n\
1044 The `target character set' is the one used by the program being debugged.\n\
1045 You may only use supersets of ASCII for your host character set; GDB does\n\
1046 not support any others.\n\
1047 To see a list of the character sets GDB supports, type `set charset <TAB>'."),
1048 /* Note that the sfunc below needs to set
1049 target_charset_name, because the 'set
1050 charset' command sets two variables. */
1053 &setlist
, &showlist
);
1055 add_setshow_enum_cmd ("host-charset", class_support
,
1056 charset_enum
, &host_charset_name
, _("\
1057 Set the host character set."), _("\
1058 Show the host character set."), _("\
1059 The `host character set' is the one used by the system GDB is running on.\n\
1060 You may only use supersets of ASCII for your host character set; GDB does\n\
1061 not support any others.\n\
1062 To see a list of the character sets GDB supports, type `set host-charset <TAB>'."),
1063 set_host_charset_sfunc
,
1064 show_host_charset_name
,
1065 &setlist
, &showlist
);
1067 add_setshow_enum_cmd ("target-charset", class_support
,
1068 charset_enum
, &target_charset_name
, _("\
1069 Set the target character set."), _("\
1070 Show the target character set."), _("\
1071 The `target character set' is the one used by the program being debugged.\n\
1072 GDB translates characters and strings between the host and target\n\
1073 character sets as needed.\n\
1074 To see a list of the character sets GDB supports, type `set target-charset'<TAB>"),
1075 set_target_charset_sfunc
,
1076 show_target_charset_name
,
1077 &setlist
, &showlist
);
1079 add_setshow_enum_cmd ("target-wide-charset", class_support
,
1080 charset_enum
, &target_wide_charset_name
,
1082 Set the target wide character set."), _("\
1083 Show the target wide character set."), _("\
1084 The `target wide character set' is the one used by the program being debugged.\
1085 \nIn particular it is the encoding used by `wchar_t'.\n\
1086 GDB translates characters and strings between the host and target\n\
1087 character sets as needed.\n\
1088 To see a list of the character sets GDB supports, type\n\
1089 `set target-wide-charset'<TAB>"),
1090 set_target_wide_charset_sfunc
,
1091 show_target_wide_charset_name
,
1092 &setlist
, &showlist
);