1 /* Character set conversion support for GDB.
3 Copyright 2001, 2003 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "gdb_assert.h"
28 #include "gdb_string.h"
36 /* How GDB's character set support works
38 GDB has two global settings:
40 - The `current host character set' is the character set GDB should
41 use in talking to the user, and which (hopefully) the user's
42 terminal knows how to display properly.
44 - The `current target character set' is the character set the
45 program being debugged uses.
47 There are commands to set each of these, and mechanisms for
48 choosing reasonable default values. GDB has a global list of
49 character sets that it can use as its host or target character
52 The header file `charset.h' declares various functions that
53 different pieces of GDB need to perform tasks like:
55 - printing target strings and characters to the user's terminal
56 (mostly target->host conversions),
58 - building target-appropriate representations of strings and
59 characters the user enters in expressions (mostly host->target
64 Now, many of these operations are specific to a particular
65 host/target character set pair. If GDB supports N character sets,
66 there are N^2 possible pairs. This means that, the larger GDB's
67 repertoire of character sets gets, the more expensive it gets to add
70 To make sure that GDB can do the right thing for every possible
71 pairing of host and target character set, while still allowing
72 GDB's repertoire to scale, we use a two-tiered approach:
74 - We maintain a global table of "translations" --- groups of
75 functions specific to a particular pair of character sets.
77 - However, a translation can be incomplete: some functions can be
78 omitted. Where there is not a translation to specify exactly
79 what function to use, we provide reasonable defaults. The
80 default behaviors try to use the "iconv" library functions, which
81 support a wide range of character sets. However, even if iconv
82 is not available, there are fallbacks to support trivial
83 translations: when the host and target character sets are the
87 /* The character set and translation structures. */
90 /* A character set GDB knows about. GDB only supports character sets
91 with stateless encodings, in which every character is one byte
95 /* A singly-linked list of all known charsets. */
98 /* The name of the character set. Comparisons on character set
99 names are case-sensitive. */
102 /* Non-zero iff this character set can be used as a host character
103 set. At present, GDB basically assumes that the host character
104 set is a superset of ASCII. */
105 int valid_host_charset
;
107 /* Pointers to charset-specific functions that depend only on a
108 single character set, and data pointers to pass to them. */
109 int (*host_char_print_literally
) (void *baton
,
111 void *host_char_print_literally_baton
;
113 int (*target_char_to_control_char
) (void *baton
,
115 int *target_ctrl_char
);
116 void *target_char_to_control_char_baton
;
120 /* A translation from one character set to another. */
123 /* A singly-linked list of all known translations. */
124 struct translation
*next
;
126 /* This structure describes functions going from the FROM character
127 set to the TO character set. Comparisons on character set names
128 are case-sensitive. */
129 const char *from
, *to
;
131 /* Pointers to translation-specific functions, and data pointers to
132 pass to them. These pointers can be zero, indicating that GDB
133 should fall back on the default behavior. We hope the default
134 behavior will be correct for many from/to pairs, reducing the
135 number of translations that need to be registered explicitly. */
137 /* TARGET_CHAR is in the `from' charset.
138 Returns a string in the `to' charset. */
139 const char *(*c_target_char_has_backslash_escape
) (void *baton
,
141 void *c_target_char_has_backslash_escape_baton
;
143 /* HOST_CHAR is in the `from' charset.
144 TARGET_CHAR points to a char in the `to' charset. */
145 int (*c_parse_backslash
) (void *baton
, int host_char
, int *target_char
);
146 void *c_parse_backslash_baton
;
148 /* This is used for the host_char_to_target and target_char_to_host
150 int (*convert_char
) (void *baton
, int from
, int *to
);
151 void *convert_char_baton
;
156 /* The global lists of character sets and translations. */
159 #ifndef GDB_DEFAULT_HOST_CHARSET
160 #define GDB_DEFAULT_HOST_CHARSET "ISO-8859-1"
163 #ifndef GDB_DEFAULT_TARGET_CHARSET
164 #define GDB_DEFAULT_TARGET_CHARSET "ISO-8859-1"
167 static const char *host_charset_name
= GDB_DEFAULT_HOST_CHARSET
;
168 static const char *target_charset_name
= GDB_DEFAULT_TARGET_CHARSET
;
170 static const char *host_charset_enum
[] =
177 static const char *target_charset_enum
[] =
186 /* The global list of all the charsets GDB knows about. */
187 static struct charset
*all_charsets
;
191 register_charset (struct charset
*cs
)
193 struct charset
**ptr
;
195 /* Put the new charset on the end, so that the list ends up in the
196 same order as the registrations in the _initialize function. */
197 for (ptr
= &all_charsets
; *ptr
; ptr
= &(*ptr
)->next
)
205 static struct charset
*
206 lookup_charset (const char *name
)
210 for (cs
= all_charsets
; cs
; cs
= cs
->next
)
211 if (! strcmp (name
, cs
->name
))
218 /* The global list of translations. */
219 static struct translation
*all_translations
;
223 register_translation (struct translation
*t
)
225 t
->next
= all_translations
;
226 all_translations
= t
;
230 static struct translation
*
231 lookup_translation (const char *from
, const char *to
)
233 struct translation
*t
;
235 for (t
= all_translations
; t
; t
= t
->next
)
236 if (! strcmp (from
, t
->from
)
237 && ! strcmp (to
, t
->to
))
245 /* Constructing charsets. */
247 /* Allocate, initialize and return a straightforward charset.
248 Use this function, rather than creating the structures yourself,
249 so that we can add new fields to the structure in the future without
250 having to tweak all the old charset descriptions. */
251 static struct charset
*
252 simple_charset (const char *name
,
253 int valid_host_charset
,
254 int (*host_char_print_literally
) (void *baton
, int host_char
),
255 void *host_char_print_literally_baton
,
256 int (*target_char_to_control_char
) (void *baton
,
258 int *target_ctrl_char
),
259 void *target_char_to_control_char_baton
)
261 struct charset
*cs
= xmalloc (sizeof (*cs
));
263 memset (cs
, 0, sizeof (*cs
));
265 cs
->valid_host_charset
= valid_host_charset
;
266 cs
->host_char_print_literally
= host_char_print_literally
;
267 cs
->host_char_print_literally_baton
= host_char_print_literally_baton
;
268 cs
->target_char_to_control_char
= target_char_to_control_char
;
269 cs
->target_char_to_control_char_baton
= target_char_to_control_char_baton
;
276 /* ASCII functions. */
279 ascii_print_literally (void *baton
, int c
)
283 return (0x20 <= c
&& c
<= 0x7e);
288 ascii_to_control (void *baton
, int c
, int *ctrl_char
)
290 *ctrl_char
= (c
& 037);
295 /* ISO-8859 family functions. */
299 iso_8859_print_literally (void *baton
, int c
)
303 return ((0x20 <= c
&& c
<= 0x7e) /* ascii printables */
304 || (! sevenbit_strings
&& 0xA0 <= c
)); /* iso 8859 printables */
309 iso_8859_to_control (void *baton
, int c
, int *ctrl_char
)
311 *ctrl_char
= (c
& 0200) | (c
& 037);
316 /* Construct an ISO-8859-like character set. */
317 static struct charset
*
318 iso_8859_family_charset (const char *name
)
320 return simple_charset (name
, 1,
321 iso_8859_print_literally
, 0,
322 iso_8859_to_control
, 0);
327 /* EBCDIC family functions. */
331 ebcdic_print_literally (void *baton
, int c
)
335 return (64 <= c
&& c
<= 254);
340 ebcdic_to_control (void *baton
, int c
, int *ctrl_char
)
342 /* There are no control character equivalents in EBCDIC. Use
348 /* Construct an EBCDIC-like character set. */
349 static struct charset
*
350 ebcdic_family_charset (const char *name
)
352 return simple_charset (name
, 0,
353 ebcdic_print_literally
, 0,
354 ebcdic_to_control
, 0);
361 /* Fallback functions using iconv. */
363 #if defined(HAVE_ICONV)
365 struct cached_iconv
{
366 struct charset
*from
, *to
;
371 /* Make sure the iconv cache *CI contains an iconv descriptor
372 translating from FROM to TO. If it already does, fine; otherwise,
373 close any existing descriptor, and open up a new one. On success,
374 return zero; on failure, return -1 and set errno. */
376 check_iconv_cache (struct cached_iconv
*ci
,
377 struct charset
*from
,
382 /* Does the cached iconv descriptor match the conversion we're trying
386 && ci
->i
!= (iconv_t
) 0)
389 /* It doesn't. If we actually had any iconv descriptor open at
390 all, close it now. */
391 if (ci
->i
!= (iconv_t
) 0)
396 if (iconv_close (i
) == -1)
397 error ("Error closing `iconv' descriptor for "
398 "`%s'-to-`%s' character conversion: %s",
399 ci
->from
->name
, ci
->to
->name
, safe_strerror (errno
));
402 /* Open a new iconv descriptor for the required conversion. */
403 i
= iconv_open (to
->name
, from
->name
);
404 if (i
== (iconv_t
) -1)
415 /* Convert FROM_CHAR using the cached iconv conversion *CI. Return
416 non-zero if the conversion was successful, zero otherwise. */
418 cached_iconv_convert (struct cached_iconv
*ci
, int from_char
, int *to_char
)
421 ICONV_CONST
char *from_ptr
= &from
;
422 char to
, *to_ptr
= &to
;
423 size_t from_left
= sizeof (from
), to_left
= sizeof (to
);
425 gdb_assert (ci
->i
!= (iconv_t
) 0);
428 if (iconv (ci
->i
, &from_ptr
, &from_left
, &to_ptr
, &to_left
)
431 /* These all suggest that the input or output character sets
432 have multi-byte encodings of some characters, which means
433 it's unsuitable for use as a GDB character set. We should
434 never have selected it. */
435 gdb_assert (errno
!= E2BIG
&& errno
!= EINVAL
);
437 /* This suggests a bug in the code managing *CI. */
438 gdb_assert (errno
!= EBADF
);
440 /* This seems to mean that there is no equivalent character in
441 the `to' character set. */
445 /* Anything else is mysterious. */
446 internal_error ("Error converting character `%d' from `%s' to `%s' "
448 from_char
, ci
->from
->name
, ci
->to
->name
,
449 safe_strerror (errno
));
452 /* If the pointers weren't advanced across the input, that also
453 suggests something was wrong. */
454 gdb_assert (from_left
== 0 && to_left
== 0);
456 *to_char
= (unsigned char) to
;
462 register_iconv_charsets (void)
464 /* Here we should check whether various character sets were
465 recognized by the local iconv implementation.
467 The first implementation registered a bunch of character sets
468 recognized by iconv, but then we discovered that iconv on Solaris
469 and iconv on GNU/Linux had no character sets in common. So we
470 replaced them with the hard-coded tables that appear later in the
474 #endif /* defined (HAVE_ICONV) */
477 /* Fallback routines for systems without iconv. */
479 #if ! defined (HAVE_ICONV)
480 struct cached_iconv
{ char nothing
; };
483 check_iconv_cache (struct cached_iconv
*ci
,
484 struct charset
*from
,
492 cached_iconv_convert (struct cached_iconv
*ci
, int from_char
, int *to_char
)
494 /* This function should never be called. */
499 register_iconv_charsets (void)
503 #endif /* ! defined(HAVE_ICONV) */
506 /* Default trivial conversion functions. */
509 identity_either_char_to_other (void *baton
, int either_char
, int *other_char
)
511 *other_char
= either_char
;
517 /* Default non-trivial conversion functions. */
520 static char backslashable
[] = "abefnrtv";
521 static char *backslashed
[] = {"a", "b", "e", "f", "n", "r", "t", "v", "0"};
522 static char represented
[] = "\a\b\e\f\n\r\t\v";
525 /* Translate TARGET_CHAR into the host character set, and see if it
526 matches any of our standard escape sequences. */
528 default_c_target_char_has_backslash_escape (void *baton
, int target_char
)
533 /* If target_char has no equivalent in the host character set,
534 assume it doesn't have a backslashed form. */
535 if (! target_char_to_host (target_char
, &host_char
))
538 ix
= strchr (represented
, host_char
);
540 return backslashed
[ix
- represented
];
546 /* Translate the backslash the way we would in the host character set,
547 and then try to translate that into the target character set. */
549 default_c_parse_backslash (void *baton
, int host_char
, int *target_char
)
553 ix
= strchr (backslashable
, host_char
);
558 return host_char_to_target (represented
[ix
- backslashable
],
563 /* Convert using a cached iconv descriptor. */
565 iconv_convert (void *baton
, int from_char
, int *to_char
)
567 struct cached_iconv
*ci
= baton
;
568 return cached_iconv_convert (ci
, from_char
, to_char
);
573 /* Conversion tables. */
576 /* I'd much rather fall back on iconv whenever possible. But the
577 character set names you use with iconv aren't standardized at all,
578 a lot of platforms have really meager character set coverage, etc.
579 I wanted to have at least something we could use to exercise the
580 test suite on all platforms.
582 In the long run, we should have a configure-time process explore
583 somehow which character sets the host platform supports, and some
584 arrangement that allows GDB users to use platform-indepedent names
585 for character sets. */
588 /* We generated these tables using iconv on a GNU/Linux machine. */
591 static int ascii_to_iso_8859_1_table
[] = {
592 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 16 */
593 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 32 */
594 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 48 */
595 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 64 */
596 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 80 */
597 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* 96 */
598 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, /* 112 */
599 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, /* 128 */
600 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 144 */
601 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 160 */
602 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 176 */
603 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */
604 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 208 */
605 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224 */
606 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 240 */
607 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 256 */
611 static int ascii_to_ebcdic_us_table
[] = {
612 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, /* 16 */
613 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31, /* 32 */
614 64, 90,127,123, 91,108, 80,125, 77, 93, 92, 78,107, 96, 75, 97, /* 48 */
615 240,241,242,243,244,245,246,247,248,249,122, 94, 76,126,110,111, /* 64 */
616 124,193,194,195,196,197,198,199,200,201,209,210,211,212,213,214, /* 80 */
617 215,216,217,226,227,228,229,230,231,232,233, -1,224, -1, -1,109, /* 96 */
618 121,129,130,131,132,133,134,135,136,137,145,146,147,148,149,150, /* 112 */
619 151,152,153,162,163,164,165,166,167,168,169,192, 79,208,161, 7, /* 128 */
620 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 144 */
621 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 160 */
622 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 176 */
623 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */
624 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 208 */
625 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224 */
626 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 240 */
627 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 256 */
631 static int ascii_to_ibm1047_table
[] = {
632 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, /* 16 */
633 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31, /* 32 */
634 64, 90,127,123, 91,108, 80,125, 77, 93, 92, 78,107, 96, 75, 97, /* 48 */
635 240,241,242,243,244,245,246,247,248,249,122, 94, 76,126,110,111, /* 64 */
636 124,193,194,195,196,197,198,199,200,201,209,210,211,212,213,214, /* 80 */
637 215,216,217,226,227,228,229,230,231,232,233,173,224,189, 95,109, /* 96 */
638 121,129,130,131,132,133,134,135,136,137,145,146,147,148,149,150, /* 112 */
639 151,152,153,162,163,164,165,166,167,168,169,192, 79,208,161, 7, /* 128 */
640 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 144 */
641 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 160 */
642 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 176 */
643 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */
644 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 208 */
645 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224 */
646 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 240 */
647 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 256 */
651 static int iso_8859_1_to_ascii_table
[] = {
652 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 16 */
653 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 32 */
654 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 48 */
655 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 64 */
656 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 80 */
657 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* 96 */
658 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, /* 112 */
659 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, /* 128 */
660 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 144 */
661 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 160 */
662 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 176 */
663 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */
664 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 208 */
665 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224 */
666 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 240 */
667 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 256 */
671 static int iso_8859_1_to_ebcdic_us_table
[] = {
672 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, /* 16 */
673 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31, /* 32 */
674 64, 90,127,123, 91,108, 80,125, 77, 93, 92, 78,107, 96, 75, 97, /* 48 */
675 240,241,242,243,244,245,246,247,248,249,122, 94, 76,126,110,111, /* 64 */
676 124,193,194,195,196,197,198,199,200,201,209,210,211,212,213,214, /* 80 */
677 215,216,217,226,227,228,229,230,231,232,233, -1,224, -1, -1,109, /* 96 */
678 121,129,130,131,132,133,134,135,136,137,145,146,147,148,149,150, /* 112 */
679 151,152,153,162,163,164,165,166,167,168,169,192, 79,208,161, 7, /* 128 */
680 32, 33, 34, 35, 36, 21, 6, 23, 40, 41, 42, 43, 44, 9, 10, 27, /* 144 */
681 48, 49, 26, 51, 52, 53, 54, 8, 56, 57, 58, 59, 4, 20, 62,255, /* 160 */
682 -1, -1, 74, -1, -1, -1,106, -1, -1, -1, -1, -1, 95, -1, -1, -1, /* 176 */
683 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */
684 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 208 */
685 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224 */
686 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 240 */
687 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 256 */
691 static int iso_8859_1_to_ibm1047_table
[] = {
692 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, /* 16 */
693 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31, /* 32 */
694 64, 90,127,123, 91,108, 80,125, 77, 93, 92, 78,107, 96, 75, 97, /* 48 */
695 240,241,242,243,244,245,246,247,248,249,122, 94, 76,126,110,111, /* 64 */
696 124,193,194,195,196,197,198,199,200,201,209,210,211,212,213,214, /* 80 */
697 215,216,217,226,227,228,229,230,231,232,233,173,224,189, 95,109, /* 96 */
698 121,129,130,131,132,133,134,135,136,137,145,146,147,148,149,150, /* 112 */
699 151,152,153,162,163,164,165,166,167,168,169,192, 79,208,161, 7, /* 128 */
700 32, 33, 34, 35, 36, 21, 6, 23, 40, 41, 42, 43, 44, 9, 10, 27, /* 144 */
701 48, 49, 26, 51, 52, 53, 54, 8, 56, 57, 58, 59, 4, 20, 62,255, /* 160 */
702 65,170, 74,177,159,178,106,181,187,180,154,138,176,202,175,188, /* 176 */
703 144,143,234,250,190,160,182,179,157,218,155,139,183,184,185,171, /* 192 */
704 100,101, 98,102, 99,103,158,104,116,113,114,115,120,117,118,119, /* 208 */
705 172,105,237,238,235,239,236,191,128,253,254,251,252,186,174, 89, /* 224 */
706 68, 69, 66, 70, 67, 71,156, 72, 84, 81, 82, 83, 88, 85, 86, 87, /* 240 */
707 140, 73,205,206,203,207,204,225,112,221,222,219,220,141,142,223 /* 256 */
711 static int ebcdic_us_to_ascii_table
[] = {
712 0, 1, 2, 3, -1, 9, -1,127, -1, -1, -1, 11, 12, 13, 14, 15, /* 16 */
713 16, 17, 18, 19, -1, -1, 8, -1, 24, 25, -1, -1, 28, 29, 30, 31, /* 32 */
714 -1, -1, -1, -1, -1, 10, 23, 27, -1, -1, -1, -1, -1, 5, 6, 7, /* 48 */
715 -1, -1, 22, -1, -1, -1, -1, 4, -1, -1, -1, -1, 20, 21, -1, 26, /* 64 */
716 32, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46, 60, 40, 43,124, /* 80 */
717 38, -1, -1, -1, -1, -1, -1, -1, -1, -1, 33, 36, 42, 41, 59, -1, /* 96 */
718 45, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, 44, 37, 95, 62, 63, /* 112 */
719 -1, -1, -1, -1, -1, -1, -1, -1, -1, 96, 58, 35, 64, 39, 61, 34, /* 128 */
720 -1, 97, 98, 99,100,101,102,103,104,105, -1, -1, -1, -1, -1, -1, /* 144 */
721 -1,106,107,108,109,110,111,112,113,114, -1, -1, -1, -1, -1, -1, /* 160 */
722 -1,126,115,116,117,118,119,120,121,122, -1, -1, -1, -1, -1, -1, /* 176 */
723 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */
724 123, 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, -1, -1, -1, -1, -1, /* 208 */
725 125, 74, 75, 76, 77, 78, 79, 80, 81, 82, -1, -1, -1, -1, -1, -1, /* 224 */
726 92, -1, 83, 84, 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, -1, -1, /* 240 */
727 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, -1, -1, -1, -1, -1 /* 256 */
731 static int ebcdic_us_to_iso_8859_1_table
[] = {
732 0, 1, 2, 3,156, 9,134,127,151,141,142, 11, 12, 13, 14, 15, /* 16 */
733 16, 17, 18, 19,157,133, 8,135, 24, 25,146,143, 28, 29, 30, 31, /* 32 */
734 128,129,130,131,132, 10, 23, 27,136,137,138,139,140, 5, 6, 7, /* 48 */
735 144,145, 22,147,148,149,150, 4,152,153,154,155, 20, 21,158, 26, /* 64 */
736 32, -1, -1, -1, -1, -1, -1, -1, -1, -1,162, 46, 60, 40, 43,124, /* 80 */
737 38, -1, -1, -1, -1, -1, -1, -1, -1, -1, 33, 36, 42, 41, 59,172, /* 96 */
738 45, 47, -1, -1, -1, -1, -1, -1, -1, -1,166, 44, 37, 95, 62, 63, /* 112 */
739 -1, -1, -1, -1, -1, -1, -1, -1, -1, 96, 58, 35, 64, 39, 61, 34, /* 128 */
740 -1, 97, 98, 99,100,101,102,103,104,105, -1, -1, -1, -1, -1, -1, /* 144 */
741 -1,106,107,108,109,110,111,112,113,114, -1, -1, -1, -1, -1, -1, /* 160 */
742 -1,126,115,116,117,118,119,120,121,122, -1, -1, -1, -1, -1, -1, /* 176 */
743 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */
744 123, 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, -1, -1, -1, -1, -1, /* 208 */
745 125, 74, 75, 76, 77, 78, 79, 80, 81, 82, -1, -1, -1, -1, -1, -1, /* 224 */
746 92, -1, 83, 84, 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, -1, -1, /* 240 */
747 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, -1, -1, -1, -1,159 /* 256 */
751 static int ebcdic_us_to_ibm1047_table
[] = {
752 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 16 */
753 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 32 */
754 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 48 */
755 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 64 */
756 64, -1, -1, -1, -1, -1, -1, -1, -1, -1, 74, 75, 76, 77, 78, 79, /* 80 */
757 80, -1, -1, -1, -1, -1, -1, -1, -1, -1, 90, 91, 92, 93, 94,176, /* 96 */
758 96, 97, -1, -1, -1, -1, -1, -1, -1, -1,106,107,108,109,110,111, /* 112 */
759 -1, -1, -1, -1, -1, -1, -1, -1, -1,121,122,123,124,125,126,127, /* 128 */
760 -1,129,130,131,132,133,134,135,136,137, -1, -1, -1, -1, -1, -1, /* 144 */
761 -1,145,146,147,148,149,150,151,152,153, -1, -1, -1, -1, -1, -1, /* 160 */
762 -1,161,162,163,164,165,166,167,168,169, -1, -1, -1, -1, -1, -1, /* 176 */
763 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */
764 192,193,194,195,196,197,198,199,200,201, -1, -1, -1, -1, -1, -1, /* 208 */
765 208,209,210,211,212,213,214,215,216,217, -1, -1, -1, -1, -1, -1, /* 224 */
766 224, -1,226,227,228,229,230,231,232,233, -1, -1, -1, -1, -1, -1, /* 240 */
767 240,241,242,243,244,245,246,247,248,249, -1, -1, -1, -1, -1,255 /* 256 */
771 static int ibm1047_to_ascii_table
[] = {
772 0, 1, 2, 3, -1, 9, -1,127, -1, -1, -1, 11, 12, 13, 14, 15, /* 16 */
773 16, 17, 18, 19, -1, -1, 8, -1, 24, 25, -1, -1, 28, 29, 30, 31, /* 32 */
774 -1, -1, -1, -1, -1, 10, 23, 27, -1, -1, -1, -1, -1, 5, 6, 7, /* 48 */
775 -1, -1, 22, -1, -1, -1, -1, 4, -1, -1, -1, -1, 20, 21, -1, 26, /* 64 */
776 32, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46, 60, 40, 43,124, /* 80 */
777 38, -1, -1, -1, -1, -1, -1, -1, -1, -1, 33, 36, 42, 41, 59, 94, /* 96 */
778 45, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, 44, 37, 95, 62, 63, /* 112 */
779 -1, -1, -1, -1, -1, -1, -1, -1, -1, 96, 58, 35, 64, 39, 61, 34, /* 128 */
780 -1, 97, 98, 99,100,101,102,103,104,105, -1, -1, -1, -1, -1, -1, /* 144 */
781 -1,106,107,108,109,110,111,112,113,114, -1, -1, -1, -1, -1, -1, /* 160 */
782 -1,126,115,116,117,118,119,120,121,122, -1, -1, -1, 91, -1, -1, /* 176 */
783 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 93, -1, -1, /* 192 */
784 123, 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, -1, -1, -1, -1, -1, /* 208 */
785 125, 74, 75, 76, 77, 78, 79, 80, 81, 82, -1, -1, -1, -1, -1, -1, /* 224 */
786 92, -1, 83, 84, 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, -1, -1, /* 240 */
787 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, -1, -1, -1, -1, -1 /* 256 */
791 static int ibm1047_to_iso_8859_1_table
[] = {
792 0, 1, 2, 3,156, 9,134,127,151,141,142, 11, 12, 13, 14, 15, /* 16 */
793 16, 17, 18, 19,157,133, 8,135, 24, 25,146,143, 28, 29, 30, 31, /* 32 */
794 128,129,130,131,132, 10, 23, 27,136,137,138,139,140, 5, 6, 7, /* 48 */
795 144,145, 22,147,148,149,150, 4,152,153,154,155, 20, 21,158, 26, /* 64 */
796 32,160,226,228,224,225,227,229,231,241,162, 46, 60, 40, 43,124, /* 80 */
797 38,233,234,235,232,237,238,239,236,223, 33, 36, 42, 41, 59, 94, /* 96 */
798 45, 47,194,196,192,193,195,197,199,209,166, 44, 37, 95, 62, 63, /* 112 */
799 248,201,202,203,200,205,206,207,204, 96, 58, 35, 64, 39, 61, 34, /* 128 */
800 216, 97, 98, 99,100,101,102,103,104,105,171,187,240,253,254,177, /* 144 */
801 176,106,107,108,109,110,111,112,113,114,170,186,230,184,198,164, /* 160 */
802 181,126,115,116,117,118,119,120,121,122,161,191,208, 91,222,174, /* 176 */
803 172,163,165,183,169,167,182,188,189,190,221,168,175, 93,180,215, /* 192 */
804 123, 65, 66, 67, 68, 69, 70, 71, 72, 73,173,244,246,242,243,245, /* 208 */
805 125, 74, 75, 76, 77, 78, 79, 80, 81, 82,185,251,252,249,250,255, /* 224 */
806 92,247, 83, 84, 85, 86, 87, 88, 89, 90,178,212,214,210,211,213, /* 240 */
807 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,179,219,220,217,218,159 /* 256 */
811 static int ibm1047_to_ebcdic_us_table
[] = {
812 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 16 */
813 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 32 */
814 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 48 */
815 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 64 */
816 64, -1, -1, -1, -1, -1, -1, -1, -1, -1, 74, 75, 76, 77, 78, 79, /* 80 */
817 80, -1, -1, -1, -1, -1, -1, -1, -1, -1, 90, 91, 92, 93, 94, -1, /* 96 */
818 96, 97, -1, -1, -1, -1, -1, -1, -1, -1,106,107,108,109,110,111, /* 112 */
819 -1, -1, -1, -1, -1, -1, -1, -1, -1,121,122,123,124,125,126,127, /* 128 */
820 -1,129,130,131,132,133,134,135,136,137, -1, -1, -1, -1, -1, -1, /* 144 */
821 -1,145,146,147,148,149,150,151,152,153, -1, -1, -1, -1, -1, -1, /* 160 */
822 -1,161,162,163,164,165,166,167,168,169, -1, -1, -1, -1, -1, -1, /* 176 */
823 95, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */
824 192,193,194,195,196,197,198,199,200,201, -1, -1, -1, -1, -1, -1, /* 208 */
825 208,209,210,211,212,213,214,215,216,217, -1, -1, -1, -1, -1, -1, /* 224 */
826 224, -1,226,227,228,229,230,231,232,233, -1, -1, -1, -1, -1, -1, /* 240 */
827 240,241,242,243,244,245,246,247,248,249, -1, -1, -1, -1, -1,255 /* 256 */
832 table_convert_char (void *baton
, int from
, int *to
)
834 int *table
= (int *) baton
;
836 if (0 <= from
&& from
<= 255
837 && table
[from
] != -1)
847 static struct translation
*
848 table_translation (const char *from
, const char *to
, int *table
,
849 const char *(*c_target_char_has_backslash_escape
)
850 (void *baton
, int target_char
),
851 void *c_target_char_has_backslash_escape_baton
,
852 int (*c_parse_backslash
) (void *baton
,
855 void *c_parse_backslash_baton
)
857 struct translation
*t
= xmalloc (sizeof (*t
));
859 memset (t
, 0, sizeof (*t
));
862 t
->c_target_char_has_backslash_escape
= c_target_char_has_backslash_escape
;
863 t
->c_target_char_has_backslash_escape_baton
864 = c_target_char_has_backslash_escape_baton
;
865 t
->c_parse_backslash
= c_parse_backslash
;
866 t
->c_parse_backslash_baton
= c_parse_backslash_baton
;
867 t
->convert_char
= table_convert_char
;
868 t
->convert_char_baton
= (void *) table
;
874 static struct translation
*
875 simple_table_translation (const char *from
, const char *to
, int *table
)
877 return table_translation (from
, to
, table
, 0, 0, 0, 0);
882 /* Setting and retrieving the host and target charsets. */
885 /* The current host and target character sets. */
886 static struct charset
*current_host_charset
, *current_target_charset
;
888 /* The current functions and batons we should use for the functions in
891 static const char *(*c_target_char_has_backslash_escape_func
)
892 (void *baton
, int target_char
);
893 static void *c_target_char_has_backslash_escape_baton
;
895 static int (*c_parse_backslash_func
) (void *baton
,
898 static void *c_parse_backslash_baton
;
900 static int (*host_char_to_target_func
) (void *baton
,
903 static void *host_char_to_target_baton
;
905 static int (*target_char_to_host_func
) (void *baton
,
908 static void *target_char_to_host_baton
;
911 /* Cached iconv conversions, that might be useful to fallback
913 static struct cached_iconv cached_iconv_host_to_target
;
914 static struct cached_iconv cached_iconv_target_to_host
;
917 /* Charset structures manipulation functions. */
919 static struct charset
*
920 lookup_charset_or_error (const char *name
)
922 struct charset
*cs
= lookup_charset (name
);
925 error ("GDB doesn't know of any character set named `%s'.", name
);
931 check_valid_host_charset (struct charset
*cs
)
933 if (! cs
->valid_host_charset
)
934 error ("GDB can't use `%s' as its host character set.", cs
->name
);
937 /* Set the host and target character sets to HOST and TARGET. */
939 set_host_and_target_charsets (struct charset
*host
, struct charset
*target
)
941 struct translation
*h2t
, *t2h
;
943 /* If they're not both initialized yet, then just do nothing for
944 now. As soon as we're done running our initialize function,
945 everything will be initialized. */
946 if (! host
|| ! target
)
948 current_host_charset
= host
;
949 current_target_charset
= target
;
953 h2t
= lookup_translation (host
->name
, target
->name
);
954 t2h
= lookup_translation (target
->name
, host
->name
);
956 /* If the translations don't provide conversion functions, make sure
957 iconv can back them up. Do this *before* modifying any state. */
960 if (! h2t
|| ! h2t
->convert_char
)
962 if (check_iconv_cache (&cached_iconv_host_to_target
, host
, target
)
964 error ("GDB can't convert from the `%s' character set to `%s'.",
965 host
->name
, target
->name
);
967 if (! t2h
|| ! t2h
->convert_char
)
969 if (check_iconv_cache (&cached_iconv_target_to_host
, target
, host
)
971 error ("GDB can't convert from the `%s' character set to `%s'.",
972 target
->name
, host
->name
);
976 if (t2h
&& t2h
->c_target_char_has_backslash_escape
)
978 c_target_char_has_backslash_escape_func
979 = t2h
->c_target_char_has_backslash_escape
;
980 c_target_char_has_backslash_escape_baton
981 = t2h
->c_target_char_has_backslash_escape_baton
;
984 c_target_char_has_backslash_escape_func
985 = default_c_target_char_has_backslash_escape
;
987 if (h2t
&& h2t
->c_parse_backslash
)
989 c_parse_backslash_func
= h2t
->c_parse_backslash
;
990 c_parse_backslash_baton
= h2t
->c_parse_backslash_baton
;
993 c_parse_backslash_func
= default_c_parse_backslash
;
995 if (h2t
&& h2t
->convert_char
)
997 host_char_to_target_func
= h2t
->convert_char
;
998 host_char_to_target_baton
= h2t
->convert_char_baton
;
1000 else if (host
== target
)
1001 host_char_to_target_func
= identity_either_char_to_other
;
1004 host_char_to_target_func
= iconv_convert
;
1005 host_char_to_target_baton
= &cached_iconv_host_to_target
;
1008 if (t2h
&& t2h
->convert_char
)
1010 target_char_to_host_func
= t2h
->convert_char
;
1011 target_char_to_host_baton
= t2h
->convert_char_baton
;
1013 else if (host
== target
)
1014 target_char_to_host_func
= identity_either_char_to_other
;
1017 target_char_to_host_func
= iconv_convert
;
1018 target_char_to_host_baton
= &cached_iconv_target_to_host
;
1021 current_host_charset
= host
;
1022 current_target_charset
= target
;
1025 /* Do the real work of setting the host charset. */
1027 set_host_charset (const char *charset
)
1029 struct charset
*cs
= lookup_charset_or_error (charset
);
1030 check_valid_host_charset (cs
);
1031 set_host_and_target_charsets (cs
, current_target_charset
);
1034 /* Do the real work of setting the target charset. */
1036 set_target_charset (const char *charset
)
1038 struct charset
*cs
= lookup_charset_or_error (charset
);
1040 set_host_and_target_charsets (current_host_charset
, cs
);
1044 /* 'Set charset', 'set host-charset', 'set target-charset', 'show
1045 charset' sfunc's. */
1047 /* This is the sfunc for the 'set charset' command. */
1049 set_charset_sfunc (char *charset
, int from_tty
, struct cmd_list_element
*c
)
1051 struct charset
*cs
= lookup_charset_or_error (host_charset_name
);
1052 check_valid_host_charset (cs
);
1053 /* CAREFUL: set the target charset here as well. */
1054 target_charset_name
= host_charset_name
;
1055 set_host_and_target_charsets (cs
, cs
);
1058 /* 'set host-charset' command sfunc. We need a wrapper here because
1059 the function needs to have a specific signature. */
1061 set_host_charset_sfunc (char *charset
, int from_tty
,
1062 struct cmd_list_element
*c
)
1064 set_host_charset (host_charset_name
);
1067 /* Wrapper for the 'set target-charset' command. */
1069 set_target_charset_sfunc (char *charset
, int from_tty
,
1070 struct cmd_list_element
*c
)
1072 set_target_charset (target_charset_name
);
1075 /* sfunc for the 'show charset' command. */
1077 show_charset (char *arg
, int from_tty
)
1079 if (current_host_charset
== current_target_charset
)
1081 printf_filtered ("The current host and target character set is `%s'.\n",
1086 printf_filtered ("The current host character set is `%s'.\n",
1088 printf_filtered ("The current target character set is `%s'.\n",
1094 /* Accessor functions. */
1099 return current_host_charset
->name
;
1103 target_charset (void)
1105 return current_target_charset
->name
;
1110 /* Public character management functions. */
1114 c_target_char_has_backslash_escape (int target_char
)
1116 return ((*c_target_char_has_backslash_escape_func
)
1117 (c_target_char_has_backslash_escape_baton
, target_char
));
1122 c_parse_backslash (int host_char
, int *target_char
)
1124 return (*c_parse_backslash_func
) (c_parse_backslash_baton
,
1125 host_char
, target_char
);
1130 host_char_print_literally (int host_char
)
1132 return ((*current_host_charset
->host_char_print_literally
)
1133 (current_host_charset
->host_char_print_literally_baton
,
1139 target_char_to_control_char (int target_char
, int *target_ctrl_char
)
1141 return ((*current_target_charset
->target_char_to_control_char
)
1142 (current_target_charset
->target_char_to_control_char_baton
,
1143 target_char
, target_ctrl_char
));
1148 host_char_to_target (int host_char
, int *target_char
)
1150 return ((*host_char_to_target_func
)
1151 (host_char_to_target_baton
, host_char
, target_char
));
1156 target_char_to_host (int target_char
, int *host_char
)
1158 return ((*target_char_to_host_func
)
1159 (target_char_to_host_baton
, target_char
, host_char
));
1164 /* The charset.c module initialization function. */
1166 extern initialize_file_ftype _initialize_charset
; /* -Wmissing-prototype */
1169 _initialize_charset (void)
1171 struct cmd_list_element
*new_cmd
;
1173 /* Register all the character set GDB knows about.
1175 You should use the same names that iconv does, where possible, to
1176 take advantage of the iconv-based default behaviors.
1178 CAUTION: if you register a character set, you must also register
1179 as many translations as are necessary to make that character set
1180 interoperate correctly with all the other character sets. We do
1181 provide default behaviors when no translation is available, or
1182 when a translation's function pointer for a particular operation
1183 is zero. Hopefully, these defaults will be correct often enough
1184 that we won't need to provide too many translations. */
1185 register_charset (simple_charset ("ASCII", 1,
1186 ascii_print_literally
, 0,
1187 ascii_to_control
, 0));
1188 register_charset (iso_8859_family_charset ("ISO-8859-1"));
1189 register_charset (ebcdic_family_charset ("EBCDIC-US"));
1190 register_charset (ebcdic_family_charset ("IBM1047"));
1191 register_iconv_charsets ();
1194 struct { char *from
; char *to
; int *table
; } tlist
[] = {
1195 { "ASCII", "ISO-8859-1", ascii_to_iso_8859_1_table
},
1196 { "ASCII", "EBCDIC-US", ascii_to_ebcdic_us_table
},
1197 { "ASCII", "IBM1047", ascii_to_ibm1047_table
},
1198 { "ISO-8859-1", "ASCII", iso_8859_1_to_ascii_table
},
1199 { "ISO-8859-1", "EBCDIC-US", iso_8859_1_to_ebcdic_us_table
},
1200 { "ISO-8859-1", "IBM1047", iso_8859_1_to_ibm1047_table
},
1201 { "EBCDIC-US", "ASCII", ebcdic_us_to_ascii_table
},
1202 { "EBCDIC-US", "ISO-8859-1", ebcdic_us_to_iso_8859_1_table
},
1203 { "EBCDIC-US", "IBM1047", ebcdic_us_to_ibm1047_table
},
1204 { "IBM1047", "ASCII", ibm1047_to_ascii_table
},
1205 { "IBM1047", "ISO-8859-1", ibm1047_to_iso_8859_1_table
},
1206 { "IBM1047", "EBCDIC-US", ibm1047_to_ebcdic_us_table
}
1211 for (i
= 0; i
< (sizeof (tlist
) / sizeof (tlist
[0])); i
++)
1212 register_translation (simple_table_translation (tlist
[i
].from
,
1217 set_host_charset (host_charset_name
);
1218 set_target_charset (target_charset_name
);
1220 new_cmd
= add_set_enum_cmd ("charset",
1224 "Set the host and target character sets.\n"
1225 "The `host character set' is the one used by the system GDB is running on.\n"
1226 "The `target character set' is the one used by the program being debugged.\n"
1227 "You may only use supersets of ASCII for your host character set; GDB does\n"
1228 "not support any others.\n"
1229 "To see a list of the character sets GDB supports, type `set charset <TAB>'.",
1232 /* Note that the sfunc below needs to set target_charset_name, because
1233 the 'set charset' command sets two variables. */
1234 set_cmd_sfunc (new_cmd
, set_charset_sfunc
);
1235 /* Don't use set_from_show - need to print some extra info. */
1236 add_cmd ("charset", class_support
, show_charset
,
1237 "Show the host and target character sets.\n"
1238 "The `host character set' is the one used by the system GDB is running on.\n"
1239 "The `target character set' is the one used by the program being debugged.\n"
1240 "You may only use supersets of ASCII for your host character set; GDB does\n"
1241 "not support any others.\n"
1242 "To see a list of the character sets GDB supports, type `set charset <TAB>'.",
1246 new_cmd
= add_set_enum_cmd ("host-charset",
1250 "Set the host character set.\n"
1251 "The `host character set' is the one used by the system GDB is running on.\n"
1252 "You may only use supersets of ASCII for your host character set; GDB does\n"
1253 "not support any others.\n"
1254 "To see a list of the character sets GDB supports, type `set host-charset <TAB>'.",
1257 set_cmd_sfunc (new_cmd
, set_host_charset_sfunc
);
1259 add_show_from_set (new_cmd
, &showlist
);
1263 new_cmd
= add_set_enum_cmd ("target-charset",
1265 target_charset_enum
,
1266 &target_charset_name
,
1267 "Set the target character set.\n"
1268 "The `target character set' is the one used by the program being debugged.\n"
1269 "GDB translates characters and strings between the host and target\n"
1270 "character sets as needed.\n"
1271 "To see a list of the character sets GDB supports, type `set target-charset'<TAB>",
1274 set_cmd_sfunc (new_cmd
, set_target_charset_sfunc
);
1275 add_show_from_set (new_cmd
, &showlist
);