79 #undef GDB_DEFAULT_HOST_CHARSET
80 #define GDB_DEFAULT_HOST_CHARSET "ISO-8859-1"
81 #define GDB_DEFAULT_TARGET_CHARSET "ISO-8859-1"
82 #define GDB_DEFAULT_TARGET_WIDE_CHARSET "ISO-8859-1"
83 #undef DEFAULT_CHARSET_NAMES
84 #define DEFAULT_CHARSET_NAMES GDB_DEFAULT_HOST_CHARSET ,
89 #define iconv_open phony_iconv_open
91 #define iconv phony_iconv
93 #define iconv_close phony_iconv_close
96 #define ICONV_CONST const
103 if (strcmp (from,
"UTF-32BE") && strcmp (from,
"wchar_t")
111 return !strcmp (from,
"UTF-32BE");
122 char **outbuf,
size_t *outbytesleft)
126 while (*inbytesleft >= 4)
131 for (j = 0; j < 4; ++j)
134 c += (*inbuf)[j] & 0xff;
149 if (*inbytesleft < 4)
159 size_t amt = *inbytesleft;
161 if (amt > *outbytesleft)
163 memcpy (*outbuf, *inbuf, amt);
167 *outbytesleft -= amt;
189 char **outbuf,
size_t *outbytesleft)
193 ret =
iconv (utf_flag, inbuf, inbytesleft, outbuf, outbytesleft);
200 #define iconv gdb_iconv
208 #ifndef GDB_DEFAULT_TARGET_CHARSET
209 #define GDB_DEFAULT_TARGET_CHARSET "ISO-8859-1"
212 #ifndef GDB_DEFAULT_TARGET_WIDE_CHARSET
213 #define GDB_DEFAULT_TARGET_WIDE_CHARSET "UTF-32"
217 static const char *host_charset_name =
"auto";
223 if (!strcmp (value,
"auto"))
225 _(
"The host character set is \"auto; currently %s\".\n"),
226 auto_host_charset_name);
231 static const char *target_charset_name =
"auto";
236 if (!strcmp (value,
"auto"))
238 _(
"The target character set is \"auto; "
239 "currently %s\".\n"),
246 static const char *target_wide_charset_name =
"auto";
253 if (!strcmp (value,
"auto"))
255 _(
"The target wide character set is \"auto; "
256 "currently %s\".\n"),
263 static const char *default_charset_names[] =
287 const char *target_wide;
289 if (be_le_arch == gdbarch)
291 be_le_arch = gdbarch;
293 target_wide_charset_le_name = NULL;
294 target_wide_charset_be_name = NULL;
297 if (!strcmp (target_wide,
"auto"))
300 len = strlen (target_wide);
301 for (i = 0; charset_enum[i]; ++i)
303 if (strncmp (target_wide, charset_enum[i], len))
305 if ((charset_enum[i][len] ==
'B'
306 || charset_enum[i][len] ==
'L')
307 && charset_enum[i][len + 1] ==
'E'
308 && charset_enum[i][len + 2] ==
'\0')
310 if (charset_enum[i][len] ==
'B')
311 target_wide_charset_be_name = charset_enum[i];
313 target_wide_charset_le_name = charset_enum[i];
329 if (!strcmp (target_wide_cset,
"auto"))
332 desc =
iconv_open (target_wide_cset, host_cset);
334 error (
_(
"Cannot convert between character sets `%s' and `%s'"),
335 target_wide_cset, host_cset);
340 error (
_(
"Cannot convert between character sets `%s' and `%s'"),
341 target_cset, host_cset);
392 target_wide_charset_name);
401 if (!strcmp (host_charset_name,
"auto"))
409 if (!strcmp (target_charset_name,
"auto"))
420 if (byte_order == BFD_ENDIAN_BIG)
422 if (target_wide_charset_be_name)
427 if (target_wide_charset_le_name)
431 if (!strcmp (target_wide_charset_name,
"auto"))
457 if (c >=
'a' && c <=
'f')
477 const gdb_byte *bytes,
unsigned int num_bytes,
478 int width,
struct obstack *output,
485 unsigned int space_request;
488 if (!strcmp (from, to))
490 obstack_grow (output, bytes, num_bytes);
502 space_request = num_bytes;
510 old_size = obstack_object_size (output);
511 obstack_blank (output, space_request);
513 outp = (
char *) obstack_base (output) + old_size;
514 outleft = space_request;
516 r =
iconv (desc, &inp, &inleft, &outp, &outleft);
520 obstack_blank_fast (output, -outleft);
522 if (r == (
size_t) -1)
532 error (
_(
"Could not convert character "
533 "to `%s' character set"), to);
537 for (i = 0; i < width; ++i)
541 xsnprintf (octal,
sizeof (octal),
"\\%.3o", *inp & 0xff);
564 "converting character sets"));
596 const char *charset,
size_t width)
648 while (iter->
bytes > 0)
651 char *outptr = (
char *) &iter->
out[0];
653 size_t orig_in = iter->
bytes;
654 size_t out_avail = out_request *
sizeof (
gdb_wchar_t);
656 size_t r =
iconv (iter->
desc, &inptr, &iter->
bytes, &outptr, &out_avail);
660 if (r == (
size_t) -1)
667 if (out_avail < out_request *
sizeof (
gdb_wchar_t))
683 if (out_avail < out_request *
sizeof (
gdb_wchar_t))
706 "converting character sets"));
711 num = out_request - out_avail /
sizeof (
gdb_wchar_t);
713 *out_chars = iter->
out;
715 *len = orig_in - iter->
bytes;
734 find_charset_names (
void)
747 #if defined (HAVE_ICONVLIST) || defined (HAVE_LIBICONVLIST)
753 add_one (
unsigned int count,
const char *
const *names,
void *data)
757 for (i = 0; i < count; ++i)
764 find_charset_names (
void)
766 iconvlist (add_one, NULL);
778 ignore_line_p (
const char *line)
782 static const char *
const ignore_lines[] =
787 "listed with several",
792 for (i = 0; ignore_lines[i] != NULL; ++i)
794 if (strstr (line, ignore_lines[i]) != NULL)
802 find_charset_names (
void)
804 struct pex_obj *child;
820 child = pex_init (PEX_USE_PIPES,
"iconv", NULL);
825 ICONV_BIN_RELOCATABLE);
826 iconv_program = concat (iconv_dir,
SLASH_STRING,
"iconv", NULL);
830 iconv_program = xstrdup (
"iconv");
832 args[0] = iconv_program;
835 flags = PEX_STDERR_TO_STDOUT;
840 if (!pex_run_in_environment (child, flags,
844 FILE *in = pex_read_output (child, 0);
850 while (in != NULL && !feof (in))
857 r = fgets (buf,
sizeof (buf), in);
863 if (ignore_line_p (r))
870 if (buf[len - 1] ==
'/')
872 if (buf[len - 1] ==
'/')
887 for (p = start; *p && *p ==
' '; ++p)
891 for ( ; *p && *p !=
' ' && *p !=
','; ++p)
902 for (start = p + 1; *start && *start ==
' '; ++start)
907 if (pex_get_status (child, 1, &status)
913 xfree (iconv_program);
946 #ifdef USE_INTERMEDIATE_ENCODING_FUNCTION
949 #define ENDIAN_SUFFIX "BE"
951 #define ENDIAN_SUFFIX "LE"
960 extern char your_gdb_wchar_t_is_bogus[(
sizeof (
gdb_wchar_t) == 2
971 intermediate_encoding (
void)
974 static const char *stored_result = NULL;
978 return stored_result;
986 stored_result = result;
999 stored_result = result;
1005 error (
_(
"Unable to find a vaild charset for string conversions"));
1015 find_charset_names ();
1023 #ifdef HAVE_LANGINFO_CODESET
1031 if (!strcmp (auto_host_charset_name,
"646") || !*auto_host_charset_name)
1032 auto_host_charset_name =
"ASCII";
1034 #elif defined (USE_WIN32API)
1037 static char w32_host_default_charset[16];
1039 snprintf (w32_host_default_charset,
sizeof w32_host_default_charset,
1041 auto_host_charset_name = w32_host_default_charset;
1048 charset_enum, &host_charset_name,
_(
"\
1049 Set the host and target character sets."),
_(
"\
1050 Show the host and target character sets."),
_(
"\
1051 The `host character set' is the one used by the system GDB is running on.\n\
1052 The `target character set' is the one used by the program being debugged.\n\
1053 You may only use supersets of ASCII for your host character set; GDB does\n\
1054 not support any others.\n\
1055 To see a list of the character sets GDB supports, type `set charset <TAB>'."),
1064 charset_enum, &host_charset_name,
_(
"\
1065 Set the host character set."),
_(
"\
1066 Show the host character set."),
_(
"\
1067 The `host character set' is the one used by the system GDB is running on.\n\
1068 You may only use supersets of ASCII for your host character set; GDB does\n\
1069 not support any others.\n\
1070 To see a list of the character sets GDB supports, type `set host-charset <TAB>'."),
1076 charset_enum, &target_charset_name,
_(
"\
1077 Set the target character set."),
_(
"\
1078 Show the target character set."),
_(
"\
1079 The `target character set' is the one used by the program being debugged.\n\
1080 GDB translates characters and strings between the host and target\n\
1081 character sets as needed.\n\
1082 To see a list of the character sets GDB supports, type `set target-charset'<TAB>"),
1088 charset_enum, &target_wide_charset_name,
1090 Set the target wide character set."),
_(
"\
1091 Show the target wide character set."),
_(
"\
1092 The `target wide character set' is the one used by the program being debugged.\
1093 \nIn particular it is the encoding used by `wchar_t'.\n\
1094 GDB translates characters and strings between the host and target\n\
1095 character sets as needed.\n\
1096 To see a list of the character sets GDB supports, type\n\
1097 `set target-wide-charset'<TAB>"),
static const char * target_wide_charset_be_name
const char * target_charset(struct gdbarch *gdbarch)
char * nl_langinfo(nl_item)
void free_char_ptr_vec(VEC(char_ptr)*char_ptr_vec)
static void set_charset_sfunc(char *charset, int from_tty, struct cmd_list_element *c)
static void set_target_wide_charset_sfunc(char *charset, int from_tty, struct cmd_list_element *c)
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_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static void cleanup_iconv(void *p)
#define DEFAULT_CHARSET_NAMES
#define GDB_DEFAULT_HOST_CHARSET
void init_environ(struct gdb_environ *e)
#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)
void set_in_environ(struct gdb_environ *e, const char *var, const char *value)
struct cleanup * make_cleanup_wchar_iterator(struct wchar_iterator *iter)
static void show_charset(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *name)
void free_environ(struct gdb_environ *e)
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)
static void set_host_charset_sfunc(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)
static void set_target_charset_sfunc(char *charset, int from_tty, struct cmd_list_element *c)
char ** environ_vector(struct gdb_environ *e)
static void validate(struct gdbarch *gdbarch)
#define GDB_DEFAULT_TARGET_WIDE_CHARSET
struct gdb_environ * make_environ(void)
void initialize_file_ftype(void)
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
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t err
static void do_cleanup_iterator(void *p)
static void show_target_charset_name(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
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)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
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)
char * xstrprintf(const char *format,...)
static iconv_t phony_iconv_open(const char *to, const char *from)
#define GDB_DEFAULT_TARGET_CHARSET
PTR xrealloc(PTR ptr, size_t size)
struct wchar_iterator * make_wchar_iterator(const gdb_byte *input, size_t bytes, const char *charset, size_t width)
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
static const char * target_charset_name
static const char ** charset_enum
int xsnprintf(char *str, size_t size, const char *format,...)
initialize_file_ftype _initialize_charset
#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 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
int wchar_iterate(struct wchar_iterator *iter, enum wchar_iterate_result *out_result, gdb_wchar_t **out_chars, const gdb_byte **ptr, size_t *len)
void error(const char *fmt,...)
const char * gdbarch_auto_charset(struct gdbarch *gdbarch)
void do_cleanups(struct cleanup *old_chain)
const ULONGEST const LONGEST len
static const char * default_charset_names[]