23#include "gdbsupport/gdb_obstack.h"
24#include "gdbsupport/gdb_wait.h"
26#include "gdbsupport/environ.h"
28#include "gdbsupport/gdb_vecs.h"
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
112 if (!strcmp (from,
"UTF-32BE") || !strcmp (from,
"UTF-32"))
115 if (!strcmp (from,
"UTF-32LE"))
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)
148 if (*outbytesleft < 1)
171 size_t amt = *inbytesleft;
173 if (amt > *outbytesleft)
175 memcpy (*outbuf, *inbuf, amt);
179 *outbytesleft -= amt;
200 char **outbuf,
size_t *outbytesleft)
204 ret =
iconv (utf_flag, inbuf, inbytesleft, outbuf, outbytesleft);
211#define iconv gdb_iconv
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"
234 if (!strcmp (
value,
"auto"))
236 _(
"The host character set is \"auto; currently %s\".\n"),
247 if (!strcmp (
value,
"auto"))
249 _(
"The target character set is \"auto; "
250 "currently %s\".\n"),
253 gdb_printf (file, _(
"The target character set is \"%s\".\n"),
264 if (!strcmp (
value,
"auto"))
266 _(
"The target wide character set is \"auto; "
267 "currently %s\".\n"),
270 gdb_printf (file, _(
"The target wide character set is \"%s\".\n"),
307 const char *target_wide;
313 if (!strcmp (target_wide,
"auto"))
316 len = strlen (target_wide);
346 if (!strcmp (target_wide_cset,
"auto"))
349 desc =
iconv_open (target_wide_cset, host_cset);
351 error (_(
"Cannot convert between character sets `%s' and `%s'"),
352 target_wide_cset, host_cset);
357 error (_(
"Cannot convert between character sets `%s' and `%s'"),
358 target_cset, host_cset);
437 if (byte_order == BFD_ENDIAN_BIG)
477 perror_with_name (_(
"Converting character sets"));
498 const gdb_byte *bytes,
unsigned int num_bytes,
499 int width,
struct obstack *output,
504 unsigned int space_request;
507 if (!strcmp (from, to))
509 obstack_grow (output, bytes, num_bytes);
518 space_request = num_bytes;
526 old_size = obstack_object_size (output);
527 obstack_blank (output, space_request);
529 outp = (
char *) obstack_base (output) + old_size;
530 outleft = space_request;
532 r = desc.
convert (&inp, &inleft, &outp, &outleft);
536 obstack_blank_fast (output, -(ssize_t) outleft);
538 if (r == (
size_t) -1)
548 error (_(
"Could not convert character "
549 "to `%s' character set"), to);
553 for (i = 0; i < width; ++i)
557 xsnprintf (octal,
sizeof (octal),
"\\%.3o", *inp & 0xff);
558 obstack_grow_str (output, octal);
579 perror_with_name (_(
"Internal error while "
580 "converting character sets"));
590 const char *charset,
size_t width)
598 perror_with_name (_(
"Converting character sets"));
610 const gdb_byte **ptr,
624 char *outptr = (
char *)
m_out.data ();
625 const gdb_byte *orig_inptr =
m_input;
627 size_t out_avail = out_request *
sizeof (
gdb_wchar_t);
633 if (r == (
size_t) -1)
640 if (out_avail < out_request *
sizeof (
gdb_wchar_t))
656 if (out_avail < out_request *
sizeof (
gdb_wchar_t))
660 if (out_request >
m_out.size ())
661 m_out.resize (out_request);
674 perror_with_name (_(
"Internal error while "
675 "converting character sets"));
680 num = out_request - out_avail /
sizeof (
gdb_wchar_t);
682 *out_chars =
m_out.data ();
735#if defined (HAVE_ICONVLIST) || defined (HAVE_LIBICONVLIST)
741add_one (
unsigned int count,
const char *
const *names,
void *data)
745 for (i = 0; i < count; ++i)
754 iconvlist (add_one, NULL);
767ignore_line_p (
const char *line)
771 static const char *
const ignore_lines[] =
776 "listed with several",
781 for (i = 0; ignore_lines[i] != NULL; ++i)
783 if (strstr (line, ignore_lines[i]) != NULL)
793 struct pex_obj *child;
798 gdb_environ iconv_env = gdb_environ::from_host_environ ();
804 iconv_env.set (
"LANGUAGE",
"C");
805 iconv_env.set (
"LC_ALL",
"C");
807 child = pex_init (PEX_USE_PIPES,
"iconv", NULL);
812 ICONV_BIN_RELOCATABLE);
814 = concat (iconv_dir.c_str(), SLASH_STRING,
"iconv", (
char *) NULL);
817 iconv_program = xstrdup (
"iconv");
819 args[0] = iconv_program;
822 flags = PEX_STDERR_TO_STDOUT;
827 if (!pex_run_in_environment (child,
flags,
828 args[0],
const_cast<char **
> (args),
832 FILE *in = pex_read_output (child, 0);
838 while (in != NULL && !feof (in))
845 r = fgets (buf,
sizeof (buf), in);
851 if (ignore_line_p (r))
858 if (buf[len - 1] ==
'/')
860 if (buf[len - 1] ==
'/')
875 for (p = start; *p && *p ==
' '; ++p)
879 for ( ; *p && *p !=
' ' && *p !=
','; ++p)
890 for (start = p + 1; *start && *start ==
' '; ++start)
895 if (pex_get_status (child, 1, &
status)
901 xfree (iconv_program);
932#ifdef USE_INTERMEDIATE_ENCODING_FUNCTION
935#define ENDIAN_SUFFIX "BE"
937#define ENDIAN_SUFFIX "LE"
951intermediate_encoding (
void)
954 static const char *stored_result = NULL;
955 gdb::unique_xmalloc_ptr<char> result;
958 return stored_result;
959 result = xstrprintf (
"UTF-%d%s", (
int) (
sizeof (
gdb_wchar_t) * 8),
966 stored_result = result.release ();
967 return stored_result;
970 result = xstrprintf (
"UCS-%d%s", (
int)
sizeof (
gdb_wchar_t),
977 stored_result = result.release ();
978 return stored_result;
981 error (_(
"Unable to find a valid charset for string conversions"));
1000#ifdef HAVE_LANGINFO_CODESET
1011#elif defined (USE_WIN32API)
1014 static char w32_host_default_charset[16];
1016 snprintf (w32_host_default_charset,
sizeof w32_host_default_charset,
1029Set the host and target character sets."), _(
"\
1030Show the host and target character sets."), _(
"\
1031The `host character set' is the one used by the system GDB is running on.\n\
1032The `target character set' is the one used by the program being debugged.\n\
1033You may only use supersets of ASCII for your host character set; GDB does\n\
1034not support any others.\n\
1035To see a list of the character sets GDB supports, type `set charset <TAB>'."),
1045Set the host character set."), _(
"\
1046Show the host character set."), _(
"\
1047The `host character set' is the one used by the system GDB is running on.\n\
1048You may only use supersets of ASCII for your host character set; GDB does\n\
1049not support any others.\n\
1050To see a list of the character sets GDB supports, type `set host-charset <TAB>'."),
1060Set the target character set."), _(
"\
1061Show the target character set."), _(
"\
1062The `target character set' is the one used by the program being debugged.\n\
1063GDB translates characters and strings between the host and target\n\
1064character sets as needed.\n\
1065To see a list of the character sets GDB supports, type `set target-charset'<TAB>"),
1076Set the target wide character set."), _(
"\
1077Show the target wide character set."), _(
"\
1078The `target wide character set' is the one used by the program being debugged.\
1079\nIn particular it is the encoding used by `wchar_t'.\n\
1080GDB translates characters and strings between the host and target\n\
1081character sets as needed.\n\
1082To see a list of the character sets GDB supports, type\n\
1083`set target-wide-charset'<TAB>"),
gdb_static_assert(sizeof(splay_tree_key) >=sizeof(CORE_ADDR *))
struct gdbarch * get_current_arch(void)
#define GDB_DEFAULT_TARGET_WIDE_CHARSET
static const char * auto_host_charset_name
static const char * auto_target_charset_name
static const char * target_wide_charset_le_name
static size_t phony_iconv(iconv_t utf_flag, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
#define GDB_DEFAULT_TARGET_CHARSET
const char * default_auto_charset(void)
void _initialize_charset()
static const char * target_wide_charset_name
const char * target_wide_charset(struct gdbarch *gdbarch)
static void set_target_charset_sfunc(const char *charset, int from_tty, struct cmd_list_element *c)
static const char * target_charset_name
static void show_host_charset_name(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
const char * host_charset(void)
static struct gdbarch * be_le_arch
static void find_charset_names(void)
static void show_target_charset_name(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static int phony_iconv_close(iconv_t arg)
static void validate(struct gdbarch *gdbarch)
static void set_be_le_names(struct gdbarch *gdbarch)
static void set_charset_sfunc(const char *charset, int from_tty, struct cmd_list_element *c)
#define DEFAULT_CHARSET_NAMES
static void show_target_wide_charset_name(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static iconv_t phony_iconv_open(const char *to, const char *from)
static void set_target_wide_charset_sfunc(const char *charset, int from_tty, struct cmd_list_element *c)
static const char *const * charset_enum
static charset_vector charsets
static const char *const default_charset_names[]
static void show_charset(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *name)
#define GDB_DEFAULT_HOST_CHARSET
const char * default_auto_wide_charset(void)
char host_letter_to_control_character(char c)
static const char * host_charset_name
static void set_host_charset_sfunc(const char *charset, int from_tty, struct cmd_list_element *c)
void convert_between_encodings(const char *from, const char *to, const gdb_byte *bytes, unsigned int num_bytes, int width, struct obstack *output, enum transliterations translit)
const char * target_charset(struct gdbarch *gdbarch)
static const char * target_wide_charset_be_name
@ wchar_iterate_incomplete
size_t convert(ICONV_CONST char **inp, size_t *inleft, char **outp, size_t *outleft)
iconv_wrapper(const char *to, const char *from)
wchar_iterator(const gdb_byte *input, size_t bytes, const char *charset, size_t width)
int iterate(enum wchar_iterate_result *out_result, gdb_wchar_t **out_chars, const gdb_byte **ptr, size_t *len)
gdb::def_vector< gdb_wchar_t > m_out
struct cmd_list_element * showlist
struct cmd_list_element * setlist
set_show_commands add_setshow_enum_cmd(const char *name, enum command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
std::string relocate_gdb_directory(const char *initial, bool relocatable)
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
#define INTERMEDIATE_ENCODING
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
const char * gdbarch_auto_charset(struct gdbarch *gdbarch)
const char * gdbarch_auto_wide_charset(struct gdbarch *gdbarch)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
static void keep_going(struct execution_control_state *ecs)
char * nl_langinfo(nl_item)
std::vector< char * > charsets
void gdb_printf(struct ui_file *stream, const char *format,...)