79 #undef GDB_DEFAULT_HOST_CHARSET 81 # define GDB_DEFAULT_HOST_CHARSET "CP1252" 83 # define GDB_DEFAULT_HOST_CHARSET "ISO-8859-1" 85 #define GDB_DEFAULT_TARGET_CHARSET GDB_DEFAULT_HOST_CHARSET 86 #define GDB_DEFAULT_TARGET_WIDE_CHARSET "UTF-32" 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 113 if (!strcmp (from,
"UTF-32BE") || !strcmp (from,
"UTF-32"))
116 if (!strcmp (from,
"UTF-32LE"))
133 char **outbuf,
size_t *outbytesleft)
137 enum bfd_endian endian
138 = utf_flag == 1 ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
139 while (*inbytesleft >= 4)
149 if (*outbytesleft < 1)
172 size_t amt = *inbytesleft;
174 if (amt > *outbytesleft)
176 memcpy (*outbuf, *inbuf, amt);
180 *outbytesleft -= amt;
201 char **outbuf,
size_t *outbytesleft)
205 ret =
iconv (utf_flag, inbuf, inbytesleft, outbuf, outbytesleft);
212 #define iconv gdb_iconv 220 #ifndef GDB_DEFAULT_TARGET_CHARSET 221 #define GDB_DEFAULT_TARGET_CHARSET "ISO-8859-1" 224 #ifndef GDB_DEFAULT_TARGET_WIDE_CHARSET 225 #define GDB_DEFAULT_TARGET_WIDE_CHARSET "UTF-32" 235 if (!strcmp (
value,
"auto"))
237 _(
"The host character set is \"auto; currently %s\".\n"),
248 if (!strcmp (
value,
"auto"))
250 _(
"The target character set is \"auto; " 251 "currently %s\".\n"),
265 if (!strcmp (
value,
"auto"))
267 _(
"The target wide character set is \"auto; " 268 "currently %s\".\n"),
299 const char *target_wide;
314 if (!strcmp (target_wide,
"auto"))
317 len = strlen (target_wide);
347 if (!strcmp (target_wide_cset,
"auto"))
350 desc =
iconv_open (target_wide_cset, host_cset);
352 error (
_(
"Cannot convert between character sets `%s' and `%s'"),
353 target_wide_cset, host_cset);
358 error (
_(
"Cannot convert between character sets `%s' and `%s'"),
359 target_cset, host_cset);
475 if (c >=
'a' && c <=
'f')
513 const gdb_byte *bytes,
unsigned int num_bytes,
514 int width,
struct obstack *output,
519 unsigned int space_request;
522 if (!strcmp (from, to))
524 obstack_grow (output, bytes, num_bytes);
533 space_request = num_bytes;
541 old_size = obstack_object_size (output);
542 obstack_blank (output, space_request);
544 outp = (
char *) obstack_base (output) + old_size;
545 outleft = space_request;
547 r = desc.
convert (&inp, &inleft, &outp, &outleft);
551 obstack_blank_fast (output, -outleft);
553 if (r == (
size_t) -1)
563 error (
_(
"Could not convert character " 564 "to `%s' character set"), to);
568 for (i = 0; i < width; ++i)
572 xsnprintf (octal,
sizeof (octal),
"\\%.3o", *inp & 0xff);
595 "converting character sets"));
605 const char *charset,
size_t width)
639 char *outptr = (
char *)
m_out.data ();
642 size_t out_avail = out_request *
sizeof (
gdb_wchar_t);
648 if (r == (
size_t) -1)
655 if (out_avail < out_request *
sizeof (
gdb_wchar_t))
671 if (out_avail < out_request *
sizeof (
gdb_wchar_t))
675 if (out_request >
m_out.size ())
676 m_out.resize (out_request);
690 "converting character sets"));
695 num = out_request - out_avail /
sizeof (
gdb_wchar_t);
697 *out_chars =
m_out.data ();
715 find_charset_names (
void)
732 #if defined (HAVE_ICONVLIST) || defined (HAVE_LIBICONVLIST) 738 add_one (
unsigned int count,
const char *
const *names,
void *data)
742 for (i = 0; i < count; ++i)
749 find_charset_names (
void)
751 iconvlist (add_one, NULL);
763 ignore_line_p (
const char *line)
767 static const char *
const ignore_lines[] =
772 "listed with several",
777 for (i = 0; ignore_lines[i] != NULL; ++i)
779 if (strstr (line, ignore_lines[i]) != NULL)
787 find_charset_names (
void)
789 struct pex_obj *child;
800 iconv_env.
set (
"LANGUAGE",
"C");
801 iconv_env.
set (
"LC_ALL",
"C");
803 child = pex_init (PEX_USE_PIPES,
"iconv", NULL);
808 ICONV_BIN_RELOCATABLE);
809 iconv_program = concat (iconv_dir,
SLASH_STRING,
"iconv", NULL);
813 iconv_program = xstrdup (
"iconv");
815 args[0] = iconv_program;
818 flags = PEX_STDERR_TO_STDOUT;
823 if (!pex_run_in_environment (child,
flags,
824 args[0], const_cast<char **> (args),
828 FILE *in = pex_read_output (child, 0);
834 while (in != NULL && !feof (in))
841 r = fgets (buf,
sizeof (buf), in);
847 if (ignore_line_p (r))
854 if (buf[len - 1] ==
'/')
856 if (buf[len - 1] ==
'/')
871 for (p = start; *p && *p ==
' '; ++p)
875 for ( ; *p && *p !=
' ' && *p !=
','; ++p)
886 for (start = p + 1; *start && *start ==
' '; ++start)
891 if (pex_get_status (child, 1, &
status)
897 xfree (iconv_program);
929 #ifdef USE_INTERMEDIATE_ENCODING_FUNCTION 932 #define ENDIAN_SUFFIX "BE" 934 #define ENDIAN_SUFFIX "LE" 943 extern char your_gdb_wchar_t_is_bogus[(
sizeof (
gdb_wchar_t) == 2
954 intermediate_encoding (
void)
957 static const char *stored_result = NULL;
961 return stored_result;
969 stored_result = result;
982 stored_result = result;
988 error (
_(
"Unable to find a vaild charset for string conversions"));
998 find_charset_names ();
1006 #ifdef HAVE_LANGINFO_CODESET 1017 #elif defined (USE_WIN32API) 1020 static char w32_host_default_charset[16];
1022 snprintf (w32_host_default_charset,
sizeof w32_host_default_charset,
1032 Set the host and target character sets."),
_(
"\ 1033 Show the host and target character sets."),
_(
"\ 1034 The `host character set' is the one used by the system GDB is running on.\n\ 1035 The `target character set' is the one used by the program being debugged.\n\ 1036 You may only use supersets of ASCII for your host character set; GDB does\n\ 1037 not support any others.\n\ 1038 To see a list of the character sets GDB supports, type `set charset <TAB>'."),
1048 Set the host character set."),
_(
"\ 1049 Show the host character set."),
_(
"\ 1050 The `host character set' is the one used by the system GDB is running on.\n\ 1051 You may only use supersets of ASCII for your host character set; GDB does\n\ 1052 not support any others.\n\ 1053 To see a list of the character sets GDB supports, type `set host-charset <TAB>'."),
1060 Set the target character set."),
_(
"\ 1061 Show the target character set."),
_(
"\ 1062 The `target character set' is the one used by the program being debugged.\n\ 1063 GDB translates characters and strings between the host and target\n\ 1064 character sets as needed.\n\ 1065 To see a list of the character sets GDB supports, type `set target-charset'<TAB>"),
1073 Set the target wide character set."),
_(
"\ 1074 Show the target wide character set."),
_(
"\ 1075 The `target wide character set' is the one used by the program being debugged.\ 1076 \nIn particular it is the encoding used by `wchar_t'.\n\ 1077 GDB translates characters and strings between the host and target\n\ 1078 character sets as needed.\n\ 1079 To see a list of the character sets GDB supports, type\n\ 1080 `set target-wide-charset'<TAB>"),
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
wchar_iterator(const gdb_byte *input, size_t bytes, const char *charset, size_t width)
static const char * target_wide_charset_be_name
const char * target_charset(struct gdbarch *gdbarch)
char * nl_langinfo(nl_item)
static void set_host_charset_sfunc(const char *charset, int from_tty, struct cmd_list_element *c)
void _initialize_charset(void)
#define DEFAULT_CHARSET_NAMES
void set(const char *var, const char *value)
void 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_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
#define GDB_DEFAULT_HOST_CHARSET
#define VEC_safe_push(T, V, O)
static void keep_going(struct execution_control_state *ecs)
const char * gdbarch_auto_wide_charset(struct gdbarch *gdbarch)
static gdb_environ from_host_environ()
static void set_target_wide_charset_sfunc(const char *charset, int from_tty, struct cmd_list_element *c)
static void show_charset(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *name)
mach_port_t kern_return_t mach_port_t msgports 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
static void set_be_le_names(struct gdbarch *gdbarch)
struct cmd_list_element * setlist
const char * default_auto_charset(void)
static size_t phony_iconv(iconv_t utf_flag, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
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)
static void validate(struct gdbarch *gdbarch)
#define GDB_DEFAULT_TARGET_WIDE_CHARSET
void fprintf_filtered(struct ui_file *stream, const char *format,...)
const char * default_auto_wide_charset(void)
const char * target_wide_charset(struct gdbarch *gdbarch)
static const char * target_wide_charset_name
void free_char_ptr_vec(VEC(char_ptr) *char_ptr_vec)
static ULONGEST extract_unsigned_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
static void show_target_charset_name(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
struct cmd_list_element * showlist
static struct gdbarch * be_le_arch
static const char * auto_host_charset_name
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
static int phony_iconv_close(iconv_t arg)
static void show_host_charset_name(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static const char * host_charset_name
char host_letter_to_control_character(char c)
struct gdbarch * get_current_arch(void)
int host_hex_value(char c)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
int iterate(enum wchar_iterate_result *out_result, gdb_wchar_t **out_chars, const gdb_byte **ptr, size_t *len)
char * xstrprintf(const char *format,...)
gdb::def_vector< gdb_wchar_t > m_out
static iconv_t phony_iconv_open(const char *to, const char *from)
size_t convert(ICONV_CONST char **inp, size_t *inleft, char **outp, size_t *outleft)
#define GDB_DEFAULT_TARGET_CHARSET
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
static void set_target_charset_sfunc(const char *charset, int from_tty, struct cmd_list_element *c)
static const char * target_charset_name
static const char ** charset_enum
int xsnprintf(char *str, size_t size, const char *format,...)
#define obstack_grow_str(OBSTACK, STRING)
static void show_target_wide_charset_name(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
#define VEC_address(T, V)
static const char * target_wide_charset_le_name
#define INTERMEDIATE_ENCODING
static void set_charset_sfunc(const char *charset, int from_tty, struct cmd_list_element *c)
static const char * auto_target_charset_name
char * relocate_gdb_directory(const char *initial, int flag)
const char * host_charset(void)
enum bfd_endian byte_order
void error(const char *fmt,...)
const char * gdbarch_auto_charset(struct gdbarch *gdbarch)
iconv_wrapper(const char *to, const char *from)
static const char * default_charset_names[]