1130803Smarcel/* Character set conversion support for GDB. 2130803Smarcel 3130803Smarcel Copyright 2001, 2003 Free Software Foundation, Inc. 4130803Smarcel 5130803Smarcel This file is part of GDB. 6130803Smarcel 7130803Smarcel This program is free software; you can redistribute it and/or modify 8130803Smarcel it under the terms of the GNU General Public License as published by 9130803Smarcel the Free Software Foundation; either version 2 of the License, or 10130803Smarcel (at your option) any later version. 11130803Smarcel 12130803Smarcel This program is distributed in the hope that it will be useful, 13130803Smarcel but WITHOUT ANY WARRANTY; without even the implied warranty of 14130803Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15130803Smarcel GNU General Public License for more details. 16130803Smarcel 17130803Smarcel You should have received a copy of the GNU General Public License 18130803Smarcel along with this program; if not, write to the Free Software 19130803Smarcel Foundation, Inc., 59 Temple Place - Suite 330, 20130803Smarcel Boston, MA 02111-1307, USA. */ 21130803Smarcel 22130803Smarcel#include "defs.h" 23130803Smarcel#include "charset.h" 24130803Smarcel#include "gdbcmd.h" 25130803Smarcel#include "gdb_assert.h" 26130803Smarcel 27130803Smarcel#include <stddef.h> 28130803Smarcel#include "gdb_string.h" 29130803Smarcel#include <ctype.h> 30130803Smarcel 31130803Smarcel#ifdef HAVE_ICONV 32130803Smarcel#include <iconv.h> 33130803Smarcel#endif 34130803Smarcel 35130803Smarcel 36130803Smarcel/* How GDB's character set support works 37130803Smarcel 38130803Smarcel GDB has two global settings: 39130803Smarcel 40130803Smarcel - The `current host character set' is the character set GDB should 41130803Smarcel use in talking to the user, and which (hopefully) the user's 42130803Smarcel terminal knows how to display properly. 43130803Smarcel 44130803Smarcel - The `current target character set' is the character set the 45130803Smarcel program being debugged uses. 46130803Smarcel 47130803Smarcel There are commands to set each of these, and mechanisms for 48130803Smarcel choosing reasonable default values. GDB has a global list of 49130803Smarcel character sets that it can use as its host or target character 50130803Smarcel sets. 51130803Smarcel 52130803Smarcel The header file `charset.h' declares various functions that 53130803Smarcel different pieces of GDB need to perform tasks like: 54130803Smarcel 55130803Smarcel - printing target strings and characters to the user's terminal 56130803Smarcel (mostly target->host conversions), 57130803Smarcel 58130803Smarcel - building target-appropriate representations of strings and 59130803Smarcel characters the user enters in expressions (mostly host->target 60130803Smarcel conversions), 61130803Smarcel 62130803Smarcel and so on. 63130803Smarcel 64130803Smarcel Now, many of these operations are specific to a particular 65130803Smarcel host/target character set pair. If GDB supports N character sets, 66130803Smarcel there are N^2 possible pairs. This means that, the larger GDB's 67130803Smarcel repertoire of character sets gets, the more expensive it gets to add 68130803Smarcel new character sets. 69130803Smarcel 70130803Smarcel To make sure that GDB can do the right thing for every possible 71130803Smarcel pairing of host and target character set, while still allowing 72130803Smarcel GDB's repertoire to scale, we use a two-tiered approach: 73130803Smarcel 74130803Smarcel - We maintain a global table of "translations" --- groups of 75130803Smarcel functions specific to a particular pair of character sets. 76130803Smarcel 77130803Smarcel - However, a translation can be incomplete: some functions can be 78130803Smarcel omitted. Where there is not a translation to specify exactly 79130803Smarcel what function to use, we provide reasonable defaults. The 80130803Smarcel default behaviors try to use the "iconv" library functions, which 81130803Smarcel support a wide range of character sets. However, even if iconv 82130803Smarcel is not available, there are fallbacks to support trivial 83130803Smarcel translations: when the host and target character sets are the 84130803Smarcel same. */ 85130803Smarcel 86130803Smarcel 87130803Smarcel/* The character set and translation structures. */ 88130803Smarcel 89130803Smarcel 90130803Smarcel/* A character set GDB knows about. GDB only supports character sets 91130803Smarcel with stateless encodings, in which every character is one byte 92130803Smarcel long. */ 93130803Smarcelstruct charset { 94130803Smarcel 95130803Smarcel /* A singly-linked list of all known charsets. */ 96130803Smarcel struct charset *next; 97130803Smarcel 98130803Smarcel /* The name of the character set. Comparisons on character set 99130803Smarcel names are case-sensitive. */ 100130803Smarcel const char *name; 101130803Smarcel 102130803Smarcel /* Non-zero iff this character set can be used as a host character 103130803Smarcel set. At present, GDB basically assumes that the host character 104130803Smarcel set is a superset of ASCII. */ 105130803Smarcel int valid_host_charset; 106130803Smarcel 107130803Smarcel /* Pointers to charset-specific functions that depend only on a 108130803Smarcel single character set, and data pointers to pass to them. */ 109130803Smarcel int (*host_char_print_literally) (void *baton, 110130803Smarcel int host_char); 111130803Smarcel void *host_char_print_literally_baton; 112130803Smarcel 113130803Smarcel int (*target_char_to_control_char) (void *baton, 114130803Smarcel int target_char, 115130803Smarcel int *target_ctrl_char); 116130803Smarcel void *target_char_to_control_char_baton; 117130803Smarcel}; 118130803Smarcel 119130803Smarcel 120130803Smarcel/* A translation from one character set to another. */ 121130803Smarcelstruct translation { 122130803Smarcel 123130803Smarcel /* A singly-linked list of all known translations. */ 124130803Smarcel struct translation *next; 125130803Smarcel 126130803Smarcel /* This structure describes functions going from the FROM character 127130803Smarcel set to the TO character set. Comparisons on character set names 128130803Smarcel are case-sensitive. */ 129130803Smarcel const char *from, *to; 130130803Smarcel 131130803Smarcel /* Pointers to translation-specific functions, and data pointers to 132130803Smarcel pass to them. These pointers can be zero, indicating that GDB 133130803Smarcel should fall back on the default behavior. We hope the default 134130803Smarcel behavior will be correct for many from/to pairs, reducing the 135130803Smarcel number of translations that need to be registered explicitly. */ 136130803Smarcel 137130803Smarcel /* TARGET_CHAR is in the `from' charset. 138130803Smarcel Returns a string in the `to' charset. */ 139130803Smarcel const char *(*c_target_char_has_backslash_escape) (void *baton, 140130803Smarcel int target_char); 141130803Smarcel void *c_target_char_has_backslash_escape_baton; 142130803Smarcel 143130803Smarcel /* HOST_CHAR is in the `from' charset. 144130803Smarcel TARGET_CHAR points to a char in the `to' charset. */ 145130803Smarcel int (*c_parse_backslash) (void *baton, int host_char, int *target_char); 146130803Smarcel void *c_parse_backslash_baton; 147130803Smarcel 148130803Smarcel /* This is used for the host_char_to_target and target_char_to_host 149130803Smarcel functions. */ 150130803Smarcel int (*convert_char) (void *baton, int from, int *to); 151130803Smarcel void *convert_char_baton; 152130803Smarcel}; 153130803Smarcel 154130803Smarcel 155130803Smarcel 156130803Smarcel/* The global lists of character sets and translations. */ 157130803Smarcel 158130803Smarcel 159130803Smarcel#ifndef GDB_DEFAULT_HOST_CHARSET 160130803Smarcel#define GDB_DEFAULT_HOST_CHARSET "ISO-8859-1" 161130803Smarcel#endif 162130803Smarcel 163130803Smarcel#ifndef GDB_DEFAULT_TARGET_CHARSET 164130803Smarcel#define GDB_DEFAULT_TARGET_CHARSET "ISO-8859-1" 165130803Smarcel#endif 166130803Smarcel 167130803Smarcelstatic const char *host_charset_name = GDB_DEFAULT_HOST_CHARSET; 168130803Smarcelstatic const char *target_charset_name = GDB_DEFAULT_TARGET_CHARSET; 169130803Smarcel 170130803Smarcelstatic const char *host_charset_enum[] = 171130803Smarcel{ 172130803Smarcel "ASCII", 173130803Smarcel "ISO-8859-1", 174130803Smarcel 0 175130803Smarcel}; 176130803Smarcel 177130803Smarcelstatic const char *target_charset_enum[] = 178130803Smarcel{ 179130803Smarcel "ASCII", 180130803Smarcel "ISO-8859-1", 181130803Smarcel "EBCDIC-US", 182130803Smarcel "IBM1047", 183130803Smarcel 0 184130803Smarcel}; 185130803Smarcel 186130803Smarcel/* The global list of all the charsets GDB knows about. */ 187130803Smarcelstatic struct charset *all_charsets; 188130803Smarcel 189130803Smarcel 190130803Smarcelstatic void 191130803Smarcelregister_charset (struct charset *cs) 192130803Smarcel{ 193130803Smarcel struct charset **ptr; 194130803Smarcel 195130803Smarcel /* Put the new charset on the end, so that the list ends up in the 196130803Smarcel same order as the registrations in the _initialize function. */ 197130803Smarcel for (ptr = &all_charsets; *ptr; ptr = &(*ptr)->next) 198130803Smarcel ; 199130803Smarcel 200130803Smarcel cs->next = 0; 201130803Smarcel *ptr = cs; 202130803Smarcel} 203130803Smarcel 204130803Smarcel 205130803Smarcelstatic struct charset * 206130803Smarcellookup_charset (const char *name) 207130803Smarcel{ 208130803Smarcel struct charset *cs; 209130803Smarcel 210130803Smarcel for (cs = all_charsets; cs; cs = cs->next) 211130803Smarcel if (! strcmp (name, cs->name)) 212130803Smarcel return cs; 213130803Smarcel 214130803Smarcel return NULL; 215130803Smarcel} 216130803Smarcel 217130803Smarcel 218130803Smarcel/* The global list of translations. */ 219130803Smarcelstatic struct translation *all_translations; 220130803Smarcel 221130803Smarcel 222130803Smarcelstatic void 223130803Smarcelregister_translation (struct translation *t) 224130803Smarcel{ 225130803Smarcel t->next = all_translations; 226130803Smarcel all_translations = t; 227130803Smarcel} 228130803Smarcel 229130803Smarcel 230130803Smarcelstatic struct translation * 231130803Smarcellookup_translation (const char *from, const char *to) 232130803Smarcel{ 233130803Smarcel struct translation *t; 234130803Smarcel 235130803Smarcel for (t = all_translations; t; t = t->next) 236130803Smarcel if (! strcmp (from, t->from) 237130803Smarcel && ! strcmp (to, t->to)) 238130803Smarcel return t; 239130803Smarcel 240130803Smarcel return 0; 241130803Smarcel} 242130803Smarcel 243130803Smarcel 244130803Smarcel 245130803Smarcel/* Constructing charsets. */ 246130803Smarcel 247130803Smarcel/* Allocate, initialize and return a straightforward charset. 248130803Smarcel Use this function, rather than creating the structures yourself, 249130803Smarcel so that we can add new fields to the structure in the future without 250130803Smarcel having to tweak all the old charset descriptions. */ 251130803Smarcelstatic struct charset * 252130803Smarcelsimple_charset (const char *name, 253130803Smarcel int valid_host_charset, 254130803Smarcel int (*host_char_print_literally) (void *baton, int host_char), 255130803Smarcel void *host_char_print_literally_baton, 256130803Smarcel int (*target_char_to_control_char) (void *baton, 257130803Smarcel int target_char, 258130803Smarcel int *target_ctrl_char), 259130803Smarcel void *target_char_to_control_char_baton) 260130803Smarcel{ 261130803Smarcel struct charset *cs = xmalloc (sizeof (*cs)); 262130803Smarcel 263130803Smarcel memset (cs, 0, sizeof (*cs)); 264130803Smarcel cs->name = name; 265130803Smarcel cs->valid_host_charset = valid_host_charset; 266130803Smarcel cs->host_char_print_literally = host_char_print_literally; 267130803Smarcel cs->host_char_print_literally_baton = host_char_print_literally_baton; 268130803Smarcel cs->target_char_to_control_char = target_char_to_control_char; 269130803Smarcel cs->target_char_to_control_char_baton = target_char_to_control_char_baton; 270130803Smarcel 271130803Smarcel return cs; 272130803Smarcel} 273130803Smarcel 274130803Smarcel 275130803Smarcel 276130803Smarcel/* ASCII functions. */ 277130803Smarcel 278130803Smarcelstatic int 279130803Smarcelascii_print_literally (void *baton, int c) 280130803Smarcel{ 281130803Smarcel c &= 0xff; 282130803Smarcel 283130803Smarcel return (0x20 <= c && c <= 0x7e); 284130803Smarcel} 285130803Smarcel 286130803Smarcel 287130803Smarcelstatic int 288130803Smarcelascii_to_control (void *baton, int c, int *ctrl_char) 289130803Smarcel{ 290130803Smarcel *ctrl_char = (c & 037); 291130803Smarcel return 1; 292130803Smarcel} 293130803Smarcel 294130803Smarcel 295130803Smarcel/* ISO-8859 family functions. */ 296130803Smarcel 297130803Smarcel 298130803Smarcelstatic int 299130803Smarceliso_8859_print_literally (void *baton, int c) 300130803Smarcel{ 301130803Smarcel c &= 0xff; 302130803Smarcel 303130803Smarcel return ((0x20 <= c && c <= 0x7e) /* ascii printables */ 304130803Smarcel || (! sevenbit_strings && 0xA0 <= c)); /* iso 8859 printables */ 305130803Smarcel} 306130803Smarcel 307130803Smarcel 308130803Smarcelstatic int 309130803Smarceliso_8859_to_control (void *baton, int c, int *ctrl_char) 310130803Smarcel{ 311130803Smarcel *ctrl_char = (c & 0200) | (c & 037); 312130803Smarcel return 1; 313130803Smarcel} 314130803Smarcel 315130803Smarcel 316130803Smarcel/* Construct an ISO-8859-like character set. */ 317130803Smarcelstatic struct charset * 318130803Smarceliso_8859_family_charset (const char *name) 319130803Smarcel{ 320130803Smarcel return simple_charset (name, 1, 321130803Smarcel iso_8859_print_literally, 0, 322130803Smarcel iso_8859_to_control, 0); 323130803Smarcel} 324130803Smarcel 325130803Smarcel 326130803Smarcel 327130803Smarcel/* EBCDIC family functions. */ 328130803Smarcel 329130803Smarcel 330130803Smarcelstatic int 331130803Smarcelebcdic_print_literally (void *baton, int c) 332130803Smarcel{ 333130803Smarcel c &= 0xff; 334130803Smarcel 335130803Smarcel return (64 <= c && c <= 254); 336130803Smarcel} 337130803Smarcel 338130803Smarcel 339130803Smarcelstatic int 340130803Smarcelebcdic_to_control (void *baton, int c, int *ctrl_char) 341130803Smarcel{ 342130803Smarcel /* There are no control character equivalents in EBCDIC. Use 343130803Smarcel numeric escapes. */ 344130803Smarcel return 0; 345130803Smarcel} 346130803Smarcel 347130803Smarcel 348130803Smarcel/* Construct an EBCDIC-like character set. */ 349130803Smarcelstatic struct charset * 350130803Smarcelebcdic_family_charset (const char *name) 351130803Smarcel{ 352130803Smarcel return simple_charset (name, 0, 353130803Smarcel ebcdic_print_literally, 0, 354130803Smarcel ebcdic_to_control, 0); 355130803Smarcel} 356130803Smarcel 357130803Smarcel 358130803Smarcel 359130803Smarcel 360130803Smarcel 361130803Smarcel/* Fallback functions using iconv. */ 362130803Smarcel 363130803Smarcel#if defined(HAVE_ICONV) 364130803Smarcel 365130803Smarcelstruct cached_iconv { 366130803Smarcel struct charset *from, *to; 367130803Smarcel iconv_t i; 368130803Smarcel}; 369130803Smarcel 370130803Smarcel 371130803Smarcel/* Make sure the iconv cache *CI contains an iconv descriptor 372130803Smarcel translating from FROM to TO. If it already does, fine; otherwise, 373130803Smarcel close any existing descriptor, and open up a new one. On success, 374130803Smarcel return zero; on failure, return -1 and set errno. */ 375130803Smarcelstatic int 376130803Smarcelcheck_iconv_cache (struct cached_iconv *ci, 377130803Smarcel struct charset *from, 378130803Smarcel struct charset *to) 379130803Smarcel{ 380130803Smarcel iconv_t i; 381130803Smarcel 382130803Smarcel /* Does the cached iconv descriptor match the conversion we're trying 383130803Smarcel to do now? */ 384130803Smarcel if (ci->from == from 385130803Smarcel && ci->to == to 386130803Smarcel && ci->i != (iconv_t) 0) 387130803Smarcel return 0; 388130803Smarcel 389130803Smarcel /* It doesn't. If we actually had any iconv descriptor open at 390130803Smarcel all, close it now. */ 391130803Smarcel if (ci->i != (iconv_t) 0) 392130803Smarcel { 393130803Smarcel i = ci->i; 394130803Smarcel ci->i = (iconv_t) 0; 395130803Smarcel 396130803Smarcel if (iconv_close (i) == -1) 397130803Smarcel error ("Error closing `iconv' descriptor for " 398130803Smarcel "`%s'-to-`%s' character conversion: %s", 399130803Smarcel ci->from->name, ci->to->name, safe_strerror (errno)); 400130803Smarcel } 401130803Smarcel 402130803Smarcel /* Open a new iconv descriptor for the required conversion. */ 403130803Smarcel i = iconv_open (to->name, from->name); 404130803Smarcel if (i == (iconv_t) -1) 405130803Smarcel return -1; 406130803Smarcel 407130803Smarcel ci->i = i; 408130803Smarcel ci->from = from; 409130803Smarcel ci->to = to; 410130803Smarcel 411130803Smarcel return 0; 412130803Smarcel} 413130803Smarcel 414130803Smarcel 415130803Smarcel/* Convert FROM_CHAR using the cached iconv conversion *CI. Return 416130803Smarcel non-zero if the conversion was successful, zero otherwise. */ 417130803Smarcelstatic int 418130803Smarcelcached_iconv_convert (struct cached_iconv *ci, int from_char, int *to_char) 419130803Smarcel{ 420130803Smarcel char from; 421130803Smarcel ICONV_CONST char *from_ptr = &from; 422130803Smarcel char to, *to_ptr = &to; 423130803Smarcel size_t from_left = sizeof (from), to_left = sizeof (to); 424130803Smarcel 425130803Smarcel gdb_assert (ci->i != (iconv_t) 0); 426130803Smarcel 427130803Smarcel from = from_char; 428130803Smarcel if (iconv (ci->i, &from_ptr, &from_left, &to_ptr, &to_left) 429130803Smarcel == (size_t) -1) 430130803Smarcel { 431130803Smarcel /* These all suggest that the input or output character sets 432130803Smarcel have multi-byte encodings of some characters, which means 433130803Smarcel it's unsuitable for use as a GDB character set. We should 434130803Smarcel never have selected it. */ 435130803Smarcel gdb_assert (errno != E2BIG && errno != EINVAL); 436130803Smarcel 437130803Smarcel /* This suggests a bug in the code managing *CI. */ 438130803Smarcel gdb_assert (errno != EBADF); 439130803Smarcel 440130803Smarcel /* This seems to mean that there is no equivalent character in 441130803Smarcel the `to' character set. */ 442130803Smarcel if (errno == EILSEQ) 443130803Smarcel return 0; 444130803Smarcel 445130803Smarcel /* Anything else is mysterious. */ 446130803Smarcel internal_error (__FILE__, __LINE__, 447130803Smarcel "Error converting character `%d' from `%s' to `%s' " 448130803Smarcel "character set: %s", 449130803Smarcel from_char, ci->from->name, ci->to->name, 450130803Smarcel safe_strerror (errno)); 451130803Smarcel } 452130803Smarcel 453130803Smarcel /* If the pointers weren't advanced across the input, that also 454130803Smarcel suggests something was wrong. */ 455130803Smarcel gdb_assert (from_left == 0 && to_left == 0); 456130803Smarcel 457130803Smarcel *to_char = (unsigned char) to; 458130803Smarcel return 1; 459130803Smarcel} 460130803Smarcel 461130803Smarcel 462130803Smarcelstatic void 463130803Smarcelregister_iconv_charsets (void) 464130803Smarcel{ 465130803Smarcel /* Here we should check whether various character sets were 466130803Smarcel recognized by the local iconv implementation. 467130803Smarcel 468130803Smarcel The first implementation registered a bunch of character sets 469130803Smarcel recognized by iconv, but then we discovered that iconv on Solaris 470130803Smarcel and iconv on GNU/Linux had no character sets in common. So we 471130803Smarcel replaced them with the hard-coded tables that appear later in the 472130803Smarcel file. */ 473130803Smarcel} 474130803Smarcel 475130803Smarcel#endif /* defined (HAVE_ICONV) */ 476130803Smarcel 477130803Smarcel 478130803Smarcel/* Fallback routines for systems without iconv. */ 479130803Smarcel 480130803Smarcel#if ! defined (HAVE_ICONV) 481130803Smarcelstruct cached_iconv { char nothing; }; 482130803Smarcel 483130803Smarcelstatic int 484130803Smarcelcheck_iconv_cache (struct cached_iconv *ci, 485130803Smarcel struct charset *from, 486130803Smarcel struct charset *to) 487130803Smarcel{ 488130803Smarcel errno = EINVAL; 489130803Smarcel return -1; 490130803Smarcel} 491130803Smarcel 492130803Smarcelstatic int 493130803Smarcelcached_iconv_convert (struct cached_iconv *ci, int from_char, int *to_char) 494130803Smarcel{ 495130803Smarcel /* This function should never be called. */ 496130803Smarcel gdb_assert (0); 497130803Smarcel} 498130803Smarcel 499130803Smarcelstatic void 500130803Smarcelregister_iconv_charsets (void) 501130803Smarcel{ 502130803Smarcel} 503130803Smarcel 504130803Smarcel#endif /* ! defined(HAVE_ICONV) */ 505130803Smarcel 506130803Smarcel 507130803Smarcel/* Default trivial conversion functions. */ 508130803Smarcel 509130803Smarcelstatic int 510130803Smarcelidentity_either_char_to_other (void *baton, int either_char, int *other_char) 511130803Smarcel{ 512130803Smarcel *other_char = either_char; 513130803Smarcel return 1; 514130803Smarcel} 515130803Smarcel 516130803Smarcel 517130803Smarcel 518130803Smarcel/* Default non-trivial conversion functions. */ 519130803Smarcel 520130803Smarcel 521130803Smarcelstatic char backslashable[] = "abfnrtv"; 522130803Smarcelstatic char *backslashed[] = {"a", "b", "f", "n", "r", "t", "v", "0"}; 523130803Smarcelstatic char represented[] = "\a\b\f\n\r\t\v"; 524130803Smarcel 525130803Smarcel 526130803Smarcel/* Translate TARGET_CHAR into the host character set, and see if it 527130803Smarcel matches any of our standard escape sequences. */ 528130803Smarcelstatic const char * 529130803Smarceldefault_c_target_char_has_backslash_escape (void *baton, int target_char) 530130803Smarcel{ 531130803Smarcel int host_char; 532130803Smarcel const char *ix; 533130803Smarcel 534130803Smarcel /* If target_char has no equivalent in the host character set, 535130803Smarcel assume it doesn't have a backslashed form. */ 536130803Smarcel if (! target_char_to_host (target_char, &host_char)) 537130803Smarcel return NULL; 538130803Smarcel 539130803Smarcel ix = strchr (represented, host_char); 540130803Smarcel if (ix) 541130803Smarcel return backslashed[ix - represented]; 542130803Smarcel else 543130803Smarcel return NULL; 544130803Smarcel} 545130803Smarcel 546130803Smarcel 547130803Smarcel/* Translate the backslash the way we would in the host character set, 548130803Smarcel and then try to translate that into the target character set. */ 549130803Smarcelstatic int 550130803Smarceldefault_c_parse_backslash (void *baton, int host_char, int *target_char) 551130803Smarcel{ 552130803Smarcel const char *ix; 553130803Smarcel 554130803Smarcel ix = strchr (backslashable, host_char); 555130803Smarcel 556130803Smarcel if (! ix) 557130803Smarcel return 0; 558130803Smarcel else 559130803Smarcel return host_char_to_target (represented[ix - backslashable], 560130803Smarcel target_char); 561130803Smarcel} 562130803Smarcel 563130803Smarcel 564130803Smarcel/* Convert using a cached iconv descriptor. */ 565130803Smarcelstatic int 566130803Smarceliconv_convert (void *baton, int from_char, int *to_char) 567130803Smarcel{ 568130803Smarcel struct cached_iconv *ci = baton; 569130803Smarcel return cached_iconv_convert (ci, from_char, to_char); 570130803Smarcel} 571130803Smarcel 572130803Smarcel 573130803Smarcel 574130803Smarcel/* Conversion tables. */ 575130803Smarcel 576130803Smarcel 577130803Smarcel/* I'd much rather fall back on iconv whenever possible. But the 578130803Smarcel character set names you use with iconv aren't standardized at all, 579130803Smarcel a lot of platforms have really meager character set coverage, etc. 580130803Smarcel I wanted to have at least something we could use to exercise the 581130803Smarcel test suite on all platforms. 582130803Smarcel 583130803Smarcel In the long run, we should have a configure-time process explore 584130803Smarcel somehow which character sets the host platform supports, and some 585130803Smarcel arrangement that allows GDB users to use platform-indepedent names 586130803Smarcel for character sets. */ 587130803Smarcel 588130803Smarcel 589130803Smarcel/* We generated these tables using iconv on a GNU/Linux machine. */ 590130803Smarcel 591130803Smarcel 592130803Smarcelstatic int ascii_to_iso_8859_1_table[] = { 593130803Smarcel 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 16 */ 594130803Smarcel 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 32 */ 595130803Smarcel 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 48 */ 596130803Smarcel 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 64 */ 597130803Smarcel 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 80 */ 598130803Smarcel 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* 96 */ 599130803Smarcel 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, /* 112 */ 600130803Smarcel 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, /* 128 */ 601130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 144 */ 602130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 160 */ 603130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 176 */ 604130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */ 605130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 208 */ 606130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224 */ 607130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 240 */ 608130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 256 */ 609130803Smarcel}; 610130803Smarcel 611130803Smarcel 612130803Smarcelstatic int ascii_to_ebcdic_us_table[] = { 613130803Smarcel 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, /* 16 */ 614130803Smarcel 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31, /* 32 */ 615130803Smarcel 64, 90,127,123, 91,108, 80,125, 77, 93, 92, 78,107, 96, 75, 97, /* 48 */ 616130803Smarcel 240,241,242,243,244,245,246,247,248,249,122, 94, 76,126,110,111, /* 64 */ 617130803Smarcel 124,193,194,195,196,197,198,199,200,201,209,210,211,212,213,214, /* 80 */ 618130803Smarcel 215,216,217,226,227,228,229,230,231,232,233, -1,224, -1, -1,109, /* 96 */ 619130803Smarcel 121,129,130,131,132,133,134,135,136,137,145,146,147,148,149,150, /* 112 */ 620130803Smarcel 151,152,153,162,163,164,165,166,167,168,169,192, 79,208,161, 7, /* 128 */ 621130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 144 */ 622130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 160 */ 623130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 176 */ 624130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */ 625130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 208 */ 626130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224 */ 627130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 240 */ 628130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 256 */ 629130803Smarcel}; 630130803Smarcel 631130803Smarcel 632130803Smarcelstatic int ascii_to_ibm1047_table[] = { 633130803Smarcel 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, /* 16 */ 634130803Smarcel 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31, /* 32 */ 635130803Smarcel 64, 90,127,123, 91,108, 80,125, 77, 93, 92, 78,107, 96, 75, 97, /* 48 */ 636130803Smarcel 240,241,242,243,244,245,246,247,248,249,122, 94, 76,126,110,111, /* 64 */ 637130803Smarcel 124,193,194,195,196,197,198,199,200,201,209,210,211,212,213,214, /* 80 */ 638130803Smarcel 215,216,217,226,227,228,229,230,231,232,233,173,224,189, 95,109, /* 96 */ 639130803Smarcel 121,129,130,131,132,133,134,135,136,137,145,146,147,148,149,150, /* 112 */ 640130803Smarcel 151,152,153,162,163,164,165,166,167,168,169,192, 79,208,161, 7, /* 128 */ 641130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 144 */ 642130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 160 */ 643130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 176 */ 644130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */ 645130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 208 */ 646130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224 */ 647130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 240 */ 648130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 256 */ 649130803Smarcel}; 650130803Smarcel 651130803Smarcel 652130803Smarcelstatic int iso_8859_1_to_ascii_table[] = { 653130803Smarcel 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 16 */ 654130803Smarcel 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 32 */ 655130803Smarcel 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 48 */ 656130803Smarcel 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 64 */ 657130803Smarcel 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 80 */ 658130803Smarcel 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* 96 */ 659130803Smarcel 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, /* 112 */ 660130803Smarcel 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, /* 128 */ 661130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 144 */ 662130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 160 */ 663130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 176 */ 664130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */ 665130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 208 */ 666130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224 */ 667130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 240 */ 668130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 256 */ 669130803Smarcel}; 670130803Smarcel 671130803Smarcel 672130803Smarcelstatic int iso_8859_1_to_ebcdic_us_table[] = { 673130803Smarcel 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, /* 16 */ 674130803Smarcel 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31, /* 32 */ 675130803Smarcel 64, 90,127,123, 91,108, 80,125, 77, 93, 92, 78,107, 96, 75, 97, /* 48 */ 676130803Smarcel 240,241,242,243,244,245,246,247,248,249,122, 94, 76,126,110,111, /* 64 */ 677130803Smarcel 124,193,194,195,196,197,198,199,200,201,209,210,211,212,213,214, /* 80 */ 678130803Smarcel 215,216,217,226,227,228,229,230,231,232,233, -1,224, -1, -1,109, /* 96 */ 679130803Smarcel 121,129,130,131,132,133,134,135,136,137,145,146,147,148,149,150, /* 112 */ 680130803Smarcel 151,152,153,162,163,164,165,166,167,168,169,192, 79,208,161, 7, /* 128 */ 681130803Smarcel 32, 33, 34, 35, 36, 21, 6, 23, 40, 41, 42, 43, 44, 9, 10, 27, /* 144 */ 682130803Smarcel 48, 49, 26, 51, 52, 53, 54, 8, 56, 57, 58, 59, 4, 20, 62,255, /* 160 */ 683130803Smarcel -1, -1, 74, -1, -1, -1,106, -1, -1, -1, -1, -1, 95, -1, -1, -1, /* 176 */ 684130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */ 685130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 208 */ 686130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224 */ 687130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 240 */ 688130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /* 256 */ 689130803Smarcel}; 690130803Smarcel 691130803Smarcel 692130803Smarcelstatic int iso_8859_1_to_ibm1047_table[] = { 693130803Smarcel 0, 1, 2, 3, 55, 45, 46, 47, 22, 5, 37, 11, 12, 13, 14, 15, /* 16 */ 694130803Smarcel 16, 17, 18, 19, 60, 61, 50, 38, 24, 25, 63, 39, 28, 29, 30, 31, /* 32 */ 695130803Smarcel 64, 90,127,123, 91,108, 80,125, 77, 93, 92, 78,107, 96, 75, 97, /* 48 */ 696130803Smarcel 240,241,242,243,244,245,246,247,248,249,122, 94, 76,126,110,111, /* 64 */ 697130803Smarcel 124,193,194,195,196,197,198,199,200,201,209,210,211,212,213,214, /* 80 */ 698130803Smarcel 215,216,217,226,227,228,229,230,231,232,233,173,224,189, 95,109, /* 96 */ 699130803Smarcel 121,129,130,131,132,133,134,135,136,137,145,146,147,148,149,150, /* 112 */ 700130803Smarcel 151,152,153,162,163,164,165,166,167,168,169,192, 79,208,161, 7, /* 128 */ 701130803Smarcel 32, 33, 34, 35, 36, 21, 6, 23, 40, 41, 42, 43, 44, 9, 10, 27, /* 144 */ 702130803Smarcel 48, 49, 26, 51, 52, 53, 54, 8, 56, 57, 58, 59, 4, 20, 62,255, /* 160 */ 703130803Smarcel 65,170, 74,177,159,178,106,181,187,180,154,138,176,202,175,188, /* 176 */ 704130803Smarcel 144,143,234,250,190,160,182,179,157,218,155,139,183,184,185,171, /* 192 */ 705130803Smarcel 100,101, 98,102, 99,103,158,104,116,113,114,115,120,117,118,119, /* 208 */ 706130803Smarcel 172,105,237,238,235,239,236,191,128,253,254,251,252,186,174, 89, /* 224 */ 707130803Smarcel 68, 69, 66, 70, 67, 71,156, 72, 84, 81, 82, 83, 88, 85, 86, 87, /* 240 */ 708130803Smarcel 140, 73,205,206,203,207,204,225,112,221,222,219,220,141,142,223 /* 256 */ 709130803Smarcel}; 710130803Smarcel 711130803Smarcel 712130803Smarcelstatic int ebcdic_us_to_ascii_table[] = { 713130803Smarcel 0, 1, 2, 3, -1, 9, -1,127, -1, -1, -1, 11, 12, 13, 14, 15, /* 16 */ 714130803Smarcel 16, 17, 18, 19, -1, -1, 8, -1, 24, 25, -1, -1, 28, 29, 30, 31, /* 32 */ 715130803Smarcel -1, -1, -1, -1, -1, 10, 23, 27, -1, -1, -1, -1, -1, 5, 6, 7, /* 48 */ 716130803Smarcel -1, -1, 22, -1, -1, -1, -1, 4, -1, -1, -1, -1, 20, 21, -1, 26, /* 64 */ 717130803Smarcel 32, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46, 60, 40, 43,124, /* 80 */ 718130803Smarcel 38, -1, -1, -1, -1, -1, -1, -1, -1, -1, 33, 36, 42, 41, 59, -1, /* 96 */ 719130803Smarcel 45, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, 44, 37, 95, 62, 63, /* 112 */ 720130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, 96, 58, 35, 64, 39, 61, 34, /* 128 */ 721130803Smarcel -1, 97, 98, 99,100,101,102,103,104,105, -1, -1, -1, -1, -1, -1, /* 144 */ 722130803Smarcel -1,106,107,108,109,110,111,112,113,114, -1, -1, -1, -1, -1, -1, /* 160 */ 723130803Smarcel -1,126,115,116,117,118,119,120,121,122, -1, -1, -1, -1, -1, -1, /* 176 */ 724130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */ 725130803Smarcel 123, 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, -1, -1, -1, -1, -1, /* 208 */ 726130803Smarcel 125, 74, 75, 76, 77, 78, 79, 80, 81, 82, -1, -1, -1, -1, -1, -1, /* 224 */ 727130803Smarcel 92, -1, 83, 84, 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, -1, -1, /* 240 */ 728130803Smarcel 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, -1, -1, -1, -1, -1 /* 256 */ 729130803Smarcel}; 730130803Smarcel 731130803Smarcel 732130803Smarcelstatic int ebcdic_us_to_iso_8859_1_table[] = { 733130803Smarcel 0, 1, 2, 3,156, 9,134,127,151,141,142, 11, 12, 13, 14, 15, /* 16 */ 734130803Smarcel 16, 17, 18, 19,157,133, 8,135, 24, 25,146,143, 28, 29, 30, 31, /* 32 */ 735130803Smarcel 128,129,130,131,132, 10, 23, 27,136,137,138,139,140, 5, 6, 7, /* 48 */ 736130803Smarcel 144,145, 22,147,148,149,150, 4,152,153,154,155, 20, 21,158, 26, /* 64 */ 737130803Smarcel 32, -1, -1, -1, -1, -1, -1, -1, -1, -1,162, 46, 60, 40, 43,124, /* 80 */ 738130803Smarcel 38, -1, -1, -1, -1, -1, -1, -1, -1, -1, 33, 36, 42, 41, 59,172, /* 96 */ 739130803Smarcel 45, 47, -1, -1, -1, -1, -1, -1, -1, -1,166, 44, 37, 95, 62, 63, /* 112 */ 740130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, 96, 58, 35, 64, 39, 61, 34, /* 128 */ 741130803Smarcel -1, 97, 98, 99,100,101,102,103,104,105, -1, -1, -1, -1, -1, -1, /* 144 */ 742130803Smarcel -1,106,107,108,109,110,111,112,113,114, -1, -1, -1, -1, -1, -1, /* 160 */ 743130803Smarcel -1,126,115,116,117,118,119,120,121,122, -1, -1, -1, -1, -1, -1, /* 176 */ 744130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */ 745130803Smarcel 123, 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, -1, -1, -1, -1, -1, /* 208 */ 746130803Smarcel 125, 74, 75, 76, 77, 78, 79, 80, 81, 82, -1, -1, -1, -1, -1, -1, /* 224 */ 747130803Smarcel 92, -1, 83, 84, 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, -1, -1, /* 240 */ 748130803Smarcel 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, -1, -1, -1, -1,159 /* 256 */ 749130803Smarcel}; 750130803Smarcel 751130803Smarcel 752130803Smarcelstatic int ebcdic_us_to_ibm1047_table[] = { 753130803Smarcel 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 16 */ 754130803Smarcel 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 32 */ 755130803Smarcel 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 48 */ 756130803Smarcel 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 64 */ 757130803Smarcel 64, -1, -1, -1, -1, -1, -1, -1, -1, -1, 74, 75, 76, 77, 78, 79, /* 80 */ 758130803Smarcel 80, -1, -1, -1, -1, -1, -1, -1, -1, -1, 90, 91, 92, 93, 94,176, /* 96 */ 759130803Smarcel 96, 97, -1, -1, -1, -1, -1, -1, -1, -1,106,107,108,109,110,111, /* 112 */ 760130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1,121,122,123,124,125,126,127, /* 128 */ 761130803Smarcel -1,129,130,131,132,133,134,135,136,137, -1, -1, -1, -1, -1, -1, /* 144 */ 762130803Smarcel -1,145,146,147,148,149,150,151,152,153, -1, -1, -1, -1, -1, -1, /* 160 */ 763130803Smarcel -1,161,162,163,164,165,166,167,168,169, -1, -1, -1, -1, -1, -1, /* 176 */ 764130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */ 765130803Smarcel 192,193,194,195,196,197,198,199,200,201, -1, -1, -1, -1, -1, -1, /* 208 */ 766130803Smarcel 208,209,210,211,212,213,214,215,216,217, -1, -1, -1, -1, -1, -1, /* 224 */ 767130803Smarcel 224, -1,226,227,228,229,230,231,232,233, -1, -1, -1, -1, -1, -1, /* 240 */ 768130803Smarcel 240,241,242,243,244,245,246,247,248,249, -1, -1, -1, -1, -1,255 /* 256 */ 769130803Smarcel}; 770130803Smarcel 771130803Smarcel 772130803Smarcelstatic int ibm1047_to_ascii_table[] = { 773130803Smarcel 0, 1, 2, 3, -1, 9, -1,127, -1, -1, -1, 11, 12, 13, 14, 15, /* 16 */ 774130803Smarcel 16, 17, 18, 19, -1, -1, 8, -1, 24, 25, -1, -1, 28, 29, 30, 31, /* 32 */ 775130803Smarcel -1, -1, -1, -1, -1, 10, 23, 27, -1, -1, -1, -1, -1, 5, 6, 7, /* 48 */ 776130803Smarcel -1, -1, 22, -1, -1, -1, -1, 4, -1, -1, -1, -1, 20, 21, -1, 26, /* 64 */ 777130803Smarcel 32, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46, 60, 40, 43,124, /* 80 */ 778130803Smarcel 38, -1, -1, -1, -1, -1, -1, -1, -1, -1, 33, 36, 42, 41, 59, 94, /* 96 */ 779130803Smarcel 45, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, 44, 37, 95, 62, 63, /* 112 */ 780130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, 96, 58, 35, 64, 39, 61, 34, /* 128 */ 781130803Smarcel -1, 97, 98, 99,100,101,102,103,104,105, -1, -1, -1, -1, -1, -1, /* 144 */ 782130803Smarcel -1,106,107,108,109,110,111,112,113,114, -1, -1, -1, -1, -1, -1, /* 160 */ 783130803Smarcel -1,126,115,116,117,118,119,120,121,122, -1, -1, -1, 91, -1, -1, /* 176 */ 784130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 93, -1, -1, /* 192 */ 785130803Smarcel 123, 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, -1, -1, -1, -1, -1, /* 208 */ 786130803Smarcel 125, 74, 75, 76, 77, 78, 79, 80, 81, 82, -1, -1, -1, -1, -1, -1, /* 224 */ 787130803Smarcel 92, -1, 83, 84, 85, 86, 87, 88, 89, 90, -1, -1, -1, -1, -1, -1, /* 240 */ 788130803Smarcel 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, -1, -1, -1, -1, -1 /* 256 */ 789130803Smarcel}; 790130803Smarcel 791130803Smarcel 792130803Smarcelstatic int ibm1047_to_iso_8859_1_table[] = { 793130803Smarcel 0, 1, 2, 3,156, 9,134,127,151,141,142, 11, 12, 13, 14, 15, /* 16 */ 794130803Smarcel 16, 17, 18, 19,157,133, 8,135, 24, 25,146,143, 28, 29, 30, 31, /* 32 */ 795130803Smarcel 128,129,130,131,132, 10, 23, 27,136,137,138,139,140, 5, 6, 7, /* 48 */ 796130803Smarcel 144,145, 22,147,148,149,150, 4,152,153,154,155, 20, 21,158, 26, /* 64 */ 797130803Smarcel 32,160,226,228,224,225,227,229,231,241,162, 46, 60, 40, 43,124, /* 80 */ 798130803Smarcel 38,233,234,235,232,237,238,239,236,223, 33, 36, 42, 41, 59, 94, /* 96 */ 799130803Smarcel 45, 47,194,196,192,193,195,197,199,209,166, 44, 37, 95, 62, 63, /* 112 */ 800130803Smarcel 248,201,202,203,200,205,206,207,204, 96, 58, 35, 64, 39, 61, 34, /* 128 */ 801130803Smarcel 216, 97, 98, 99,100,101,102,103,104,105,171,187,240,253,254,177, /* 144 */ 802130803Smarcel 176,106,107,108,109,110,111,112,113,114,170,186,230,184,198,164, /* 160 */ 803130803Smarcel 181,126,115,116,117,118,119,120,121,122,161,191,208, 91,222,174, /* 176 */ 804130803Smarcel 172,163,165,183,169,167,182,188,189,190,221,168,175, 93,180,215, /* 192 */ 805130803Smarcel 123, 65, 66, 67, 68, 69, 70, 71, 72, 73,173,244,246,242,243,245, /* 208 */ 806130803Smarcel 125, 74, 75, 76, 77, 78, 79, 80, 81, 82,185,251,252,249,250,255, /* 224 */ 807130803Smarcel 92,247, 83, 84, 85, 86, 87, 88, 89, 90,178,212,214,210,211,213, /* 240 */ 808130803Smarcel 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,179,219,220,217,218,159 /* 256 */ 809130803Smarcel}; 810130803Smarcel 811130803Smarcel 812130803Smarcelstatic int ibm1047_to_ebcdic_us_table[] = { 813130803Smarcel 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 16 */ 814130803Smarcel 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 32 */ 815130803Smarcel 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 48 */ 816130803Smarcel 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 64 */ 817130803Smarcel 64, -1, -1, -1, -1, -1, -1, -1, -1, -1, 74, 75, 76, 77, 78, 79, /* 80 */ 818130803Smarcel 80, -1, -1, -1, -1, -1, -1, -1, -1, -1, 90, 91, 92, 93, 94, -1, /* 96 */ 819130803Smarcel 96, 97, -1, -1, -1, -1, -1, -1, -1, -1,106,107,108,109,110,111, /* 112 */ 820130803Smarcel -1, -1, -1, -1, -1, -1, -1, -1, -1,121,122,123,124,125,126,127, /* 128 */ 821130803Smarcel -1,129,130,131,132,133,134,135,136,137, -1, -1, -1, -1, -1, -1, /* 144 */ 822130803Smarcel -1,145,146,147,148,149,150,151,152,153, -1, -1, -1, -1, -1, -1, /* 160 */ 823130803Smarcel -1,161,162,163,164,165,166,167,168,169, -1, -1, -1, -1, -1, -1, /* 176 */ 824130803Smarcel 95, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192 */ 825130803Smarcel 192,193,194,195,196,197,198,199,200,201, -1, -1, -1, -1, -1, -1, /* 208 */ 826130803Smarcel 208,209,210,211,212,213,214,215,216,217, -1, -1, -1, -1, -1, -1, /* 224 */ 827130803Smarcel 224, -1,226,227,228,229,230,231,232,233, -1, -1, -1, -1, -1, -1, /* 240 */ 828130803Smarcel 240,241,242,243,244,245,246,247,248,249, -1, -1, -1, -1, -1,255 /* 256 */ 829130803Smarcel}; 830130803Smarcel 831130803Smarcel 832130803Smarcelstatic int 833130803Smarceltable_convert_char (void *baton, int from, int *to) 834130803Smarcel{ 835130803Smarcel int *table = (int *) baton; 836130803Smarcel 837130803Smarcel if (0 <= from && from <= 255 838130803Smarcel && table[from] != -1) 839130803Smarcel { 840130803Smarcel *to = table[from]; 841130803Smarcel return 1; 842130803Smarcel } 843130803Smarcel else 844130803Smarcel return 0; 845130803Smarcel} 846130803Smarcel 847130803Smarcel 848130803Smarcelstatic struct translation * 849130803Smarceltable_translation (const char *from, const char *to, int *table, 850130803Smarcel const char *(*c_target_char_has_backslash_escape) 851130803Smarcel (void *baton, int target_char), 852130803Smarcel void *c_target_char_has_backslash_escape_baton, 853130803Smarcel int (*c_parse_backslash) (void *baton, 854130803Smarcel int host_char, 855130803Smarcel int *target_char), 856130803Smarcel void *c_parse_backslash_baton) 857130803Smarcel{ 858130803Smarcel struct translation *t = xmalloc (sizeof (*t)); 859130803Smarcel 860130803Smarcel memset (t, 0, sizeof (*t)); 861130803Smarcel t->from = from; 862130803Smarcel t->to = to; 863130803Smarcel t->c_target_char_has_backslash_escape = c_target_char_has_backslash_escape; 864130803Smarcel t->c_target_char_has_backslash_escape_baton 865130803Smarcel = c_target_char_has_backslash_escape_baton; 866130803Smarcel t->c_parse_backslash = c_parse_backslash; 867130803Smarcel t->c_parse_backslash_baton = c_parse_backslash_baton; 868130803Smarcel t->convert_char = table_convert_char; 869130803Smarcel t->convert_char_baton = (void *) table; 870130803Smarcel 871130803Smarcel return t; 872130803Smarcel} 873130803Smarcel 874130803Smarcel 875130803Smarcelstatic struct translation * 876130803Smarcelsimple_table_translation (const char *from, const char *to, int *table) 877130803Smarcel{ 878130803Smarcel return table_translation (from, to, table, 0, 0, 0, 0); 879130803Smarcel} 880130803Smarcel 881130803Smarcel 882130803Smarcel 883130803Smarcel/* Setting and retrieving the host and target charsets. */ 884130803Smarcel 885130803Smarcel 886130803Smarcel/* The current host and target character sets. */ 887130803Smarcelstatic struct charset *current_host_charset, *current_target_charset; 888130803Smarcel 889130803Smarcel/* The current functions and batons we should use for the functions in 890130803Smarcel charset.h. */ 891130803Smarcel 892130803Smarcelstatic const char *(*c_target_char_has_backslash_escape_func) 893130803Smarcel (void *baton, int target_char); 894130803Smarcelstatic void *c_target_char_has_backslash_escape_baton; 895130803Smarcel 896130803Smarcelstatic int (*c_parse_backslash_func) (void *baton, 897130803Smarcel int host_char, 898130803Smarcel int *target_char); 899130803Smarcelstatic void *c_parse_backslash_baton; 900130803Smarcel 901130803Smarcelstatic int (*host_char_to_target_func) (void *baton, 902130803Smarcel int host_char, 903130803Smarcel int *target_char); 904130803Smarcelstatic void *host_char_to_target_baton; 905130803Smarcel 906130803Smarcelstatic int (*target_char_to_host_func) (void *baton, 907130803Smarcel int target_char, 908130803Smarcel int *host_char); 909130803Smarcelstatic void *target_char_to_host_baton; 910130803Smarcel 911130803Smarcel 912130803Smarcel/* Cached iconv conversions, that might be useful to fallback 913130803Smarcel routines. */ 914130803Smarcelstatic struct cached_iconv cached_iconv_host_to_target; 915130803Smarcelstatic struct cached_iconv cached_iconv_target_to_host; 916130803Smarcel 917130803Smarcel 918130803Smarcel/* Charset structures manipulation functions. */ 919130803Smarcel 920130803Smarcelstatic struct charset * 921130803Smarcellookup_charset_or_error (const char *name) 922130803Smarcel{ 923130803Smarcel struct charset *cs = lookup_charset (name); 924130803Smarcel 925130803Smarcel if (! cs) 926130803Smarcel error ("GDB doesn't know of any character set named `%s'.", name); 927130803Smarcel 928130803Smarcel return cs; 929130803Smarcel} 930130803Smarcel 931130803Smarcelstatic void 932130803Smarcelcheck_valid_host_charset (struct charset *cs) 933130803Smarcel{ 934130803Smarcel if (! cs->valid_host_charset) 935130803Smarcel error ("GDB can't use `%s' as its host character set.", cs->name); 936130803Smarcel} 937130803Smarcel 938130803Smarcel/* Set the host and target character sets to HOST and TARGET. */ 939130803Smarcelstatic void 940130803Smarcelset_host_and_target_charsets (struct charset *host, struct charset *target) 941130803Smarcel{ 942130803Smarcel struct translation *h2t, *t2h; 943130803Smarcel 944130803Smarcel /* If they're not both initialized yet, then just do nothing for 945130803Smarcel now. As soon as we're done running our initialize function, 946130803Smarcel everything will be initialized. */ 947130803Smarcel if (! host || ! target) 948130803Smarcel { 949130803Smarcel current_host_charset = host; 950130803Smarcel current_target_charset = target; 951130803Smarcel return; 952130803Smarcel } 953130803Smarcel 954130803Smarcel h2t = lookup_translation (host->name, target->name); 955130803Smarcel t2h = lookup_translation (target->name, host->name); 956130803Smarcel 957130803Smarcel /* If the translations don't provide conversion functions, make sure 958130803Smarcel iconv can back them up. Do this *before* modifying any state. */ 959130803Smarcel if (host != target) 960130803Smarcel { 961130803Smarcel if (! h2t || ! h2t->convert_char) 962130803Smarcel { 963130803Smarcel if (check_iconv_cache (&cached_iconv_host_to_target, host, target) 964130803Smarcel < 0) 965130803Smarcel error ("GDB can't convert from the `%s' character set to `%s'.", 966130803Smarcel host->name, target->name); 967130803Smarcel } 968130803Smarcel if (! t2h || ! t2h->convert_char) 969130803Smarcel { 970130803Smarcel if (check_iconv_cache (&cached_iconv_target_to_host, target, host) 971130803Smarcel < 0) 972130803Smarcel error ("GDB can't convert from the `%s' character set to `%s'.", 973130803Smarcel target->name, host->name); 974130803Smarcel } 975130803Smarcel } 976130803Smarcel 977130803Smarcel if (t2h && t2h->c_target_char_has_backslash_escape) 978130803Smarcel { 979130803Smarcel c_target_char_has_backslash_escape_func 980130803Smarcel = t2h->c_target_char_has_backslash_escape; 981130803Smarcel c_target_char_has_backslash_escape_baton 982130803Smarcel = t2h->c_target_char_has_backslash_escape_baton; 983130803Smarcel } 984130803Smarcel else 985130803Smarcel c_target_char_has_backslash_escape_func 986130803Smarcel = default_c_target_char_has_backslash_escape; 987130803Smarcel 988130803Smarcel if (h2t && h2t->c_parse_backslash) 989130803Smarcel { 990130803Smarcel c_parse_backslash_func = h2t->c_parse_backslash; 991130803Smarcel c_parse_backslash_baton = h2t->c_parse_backslash_baton; 992130803Smarcel } 993130803Smarcel else 994130803Smarcel c_parse_backslash_func = default_c_parse_backslash; 995130803Smarcel 996130803Smarcel if (h2t && h2t->convert_char) 997130803Smarcel { 998130803Smarcel host_char_to_target_func = h2t->convert_char; 999130803Smarcel host_char_to_target_baton = h2t->convert_char_baton; 1000130803Smarcel } 1001130803Smarcel else if (host == target) 1002130803Smarcel host_char_to_target_func = identity_either_char_to_other; 1003130803Smarcel else 1004130803Smarcel { 1005130803Smarcel host_char_to_target_func = iconv_convert; 1006130803Smarcel host_char_to_target_baton = &cached_iconv_host_to_target; 1007130803Smarcel } 1008130803Smarcel 1009130803Smarcel if (t2h && t2h->convert_char) 1010130803Smarcel { 1011130803Smarcel target_char_to_host_func = t2h->convert_char; 1012130803Smarcel target_char_to_host_baton = t2h->convert_char_baton; 1013130803Smarcel } 1014130803Smarcel else if (host == target) 1015130803Smarcel target_char_to_host_func = identity_either_char_to_other; 1016130803Smarcel else 1017130803Smarcel { 1018130803Smarcel target_char_to_host_func = iconv_convert; 1019130803Smarcel target_char_to_host_baton = &cached_iconv_target_to_host; 1020130803Smarcel } 1021130803Smarcel 1022130803Smarcel current_host_charset = host; 1023130803Smarcel current_target_charset = target; 1024130803Smarcel} 1025130803Smarcel 1026130803Smarcel/* Do the real work of setting the host charset. */ 1027130803Smarcelstatic void 1028130803Smarcelset_host_charset (const char *charset) 1029130803Smarcel{ 1030130803Smarcel struct charset *cs = lookup_charset_or_error (charset); 1031130803Smarcel check_valid_host_charset (cs); 1032130803Smarcel set_host_and_target_charsets (cs, current_target_charset); 1033130803Smarcel} 1034130803Smarcel 1035130803Smarcel/* Do the real work of setting the target charset. */ 1036130803Smarcelstatic void 1037130803Smarcelset_target_charset (const char *charset) 1038130803Smarcel{ 1039130803Smarcel struct charset *cs = lookup_charset_or_error (charset); 1040130803Smarcel 1041130803Smarcel set_host_and_target_charsets (current_host_charset, cs); 1042130803Smarcel} 1043130803Smarcel 1044130803Smarcel 1045130803Smarcel/* 'Set charset', 'set host-charset', 'set target-charset', 'show 1046130803Smarcel charset' sfunc's. */ 1047130803Smarcel 1048130803Smarcel/* This is the sfunc for the 'set charset' command. */ 1049130803Smarcelstatic void 1050130803Smarcelset_charset_sfunc (char *charset, int from_tty, struct cmd_list_element *c) 1051130803Smarcel{ 1052130803Smarcel struct charset *cs = lookup_charset_or_error (host_charset_name); 1053130803Smarcel check_valid_host_charset (cs); 1054130803Smarcel /* CAREFUL: set the target charset here as well. */ 1055130803Smarcel target_charset_name = host_charset_name; 1056130803Smarcel set_host_and_target_charsets (cs, cs); 1057130803Smarcel} 1058130803Smarcel 1059130803Smarcel/* 'set host-charset' command sfunc. We need a wrapper here because 1060130803Smarcel the function needs to have a specific signature. */ 1061130803Smarcelstatic void 1062130803Smarcelset_host_charset_sfunc (char *charset, int from_tty, 1063130803Smarcel struct cmd_list_element *c) 1064130803Smarcel{ 1065130803Smarcel set_host_charset (host_charset_name); 1066130803Smarcel} 1067130803Smarcel 1068130803Smarcel/* Wrapper for the 'set target-charset' command. */ 1069130803Smarcelstatic void 1070130803Smarcelset_target_charset_sfunc (char *charset, int from_tty, 1071130803Smarcel struct cmd_list_element *c) 1072130803Smarcel{ 1073130803Smarcel set_target_charset (target_charset_name); 1074130803Smarcel} 1075130803Smarcel 1076130803Smarcel/* sfunc for the 'show charset' command. */ 1077130803Smarcelstatic void 1078130803Smarcelshow_charset (char *arg, int from_tty) 1079130803Smarcel{ 1080130803Smarcel if (current_host_charset == current_target_charset) 1081130803Smarcel { 1082130803Smarcel printf_filtered ("The current host and target character set is `%s'.\n", 1083130803Smarcel host_charset ()); 1084130803Smarcel } 1085130803Smarcel else 1086130803Smarcel { 1087130803Smarcel printf_filtered ("The current host character set is `%s'.\n", 1088130803Smarcel host_charset ()); 1089130803Smarcel printf_filtered ("The current target character set is `%s'.\n", 1090130803Smarcel target_charset ()); 1091130803Smarcel } 1092130803Smarcel} 1093130803Smarcel 1094130803Smarcel 1095130803Smarcel/* Accessor functions. */ 1096130803Smarcel 1097130803Smarcelconst char * 1098130803Smarcelhost_charset (void) 1099130803Smarcel{ 1100130803Smarcel return current_host_charset->name; 1101130803Smarcel} 1102130803Smarcel 1103130803Smarcelconst char * 1104130803Smarceltarget_charset (void) 1105130803Smarcel{ 1106130803Smarcel return current_target_charset->name; 1107130803Smarcel} 1108130803Smarcel 1109130803Smarcel 1110130803Smarcel 1111130803Smarcel/* Public character management functions. */ 1112130803Smarcel 1113130803Smarcel 1114130803Smarcelconst char * 1115130803Smarcelc_target_char_has_backslash_escape (int target_char) 1116130803Smarcel{ 1117130803Smarcel return ((*c_target_char_has_backslash_escape_func) 1118130803Smarcel (c_target_char_has_backslash_escape_baton, target_char)); 1119130803Smarcel} 1120130803Smarcel 1121130803Smarcel 1122130803Smarcelint 1123130803Smarcelc_parse_backslash (int host_char, int *target_char) 1124130803Smarcel{ 1125130803Smarcel return (*c_parse_backslash_func) (c_parse_backslash_baton, 1126130803Smarcel host_char, target_char); 1127130803Smarcel} 1128130803Smarcel 1129130803Smarcel 1130130803Smarcelint 1131130803Smarcelhost_char_print_literally (int host_char) 1132130803Smarcel{ 1133130803Smarcel return ((*current_host_charset->host_char_print_literally) 1134130803Smarcel (current_host_charset->host_char_print_literally_baton, 1135130803Smarcel host_char)); 1136130803Smarcel} 1137130803Smarcel 1138130803Smarcel 1139130803Smarcelint 1140130803Smarceltarget_char_to_control_char (int target_char, int *target_ctrl_char) 1141130803Smarcel{ 1142130803Smarcel return ((*current_target_charset->target_char_to_control_char) 1143130803Smarcel (current_target_charset->target_char_to_control_char_baton, 1144130803Smarcel target_char, target_ctrl_char)); 1145130803Smarcel} 1146130803Smarcel 1147130803Smarcel 1148130803Smarcelint 1149130803Smarcelhost_char_to_target (int host_char, int *target_char) 1150130803Smarcel{ 1151130803Smarcel return ((*host_char_to_target_func) 1152130803Smarcel (host_char_to_target_baton, host_char, target_char)); 1153130803Smarcel} 1154130803Smarcel 1155130803Smarcel 1156130803Smarcelint 1157130803Smarceltarget_char_to_host (int target_char, int *host_char) 1158130803Smarcel{ 1159130803Smarcel return ((*target_char_to_host_func) 1160130803Smarcel (target_char_to_host_baton, target_char, host_char)); 1161130803Smarcel} 1162130803Smarcel 1163130803Smarcel 1164130803Smarcel 1165130803Smarcel/* The charset.c module initialization function. */ 1166130803Smarcel 1167130803Smarcelextern initialize_file_ftype _initialize_charset; /* -Wmissing-prototype */ 1168130803Smarcel 1169130803Smarcelvoid 1170130803Smarcel_initialize_charset (void) 1171130803Smarcel{ 1172130803Smarcel struct cmd_list_element *new_cmd; 1173130803Smarcel 1174130803Smarcel /* Register all the character set GDB knows about. 1175130803Smarcel 1176130803Smarcel You should use the same names that iconv does, where possible, to 1177130803Smarcel take advantage of the iconv-based default behaviors. 1178130803Smarcel 1179130803Smarcel CAUTION: if you register a character set, you must also register 1180130803Smarcel as many translations as are necessary to make that character set 1181130803Smarcel interoperate correctly with all the other character sets. We do 1182130803Smarcel provide default behaviors when no translation is available, or 1183130803Smarcel when a translation's function pointer for a particular operation 1184130803Smarcel is zero. Hopefully, these defaults will be correct often enough 1185130803Smarcel that we won't need to provide too many translations. */ 1186130803Smarcel register_charset (simple_charset ("ASCII", 1, 1187130803Smarcel ascii_print_literally, 0, 1188130803Smarcel ascii_to_control, 0)); 1189130803Smarcel register_charset (iso_8859_family_charset ("ISO-8859-1")); 1190130803Smarcel register_charset (ebcdic_family_charset ("EBCDIC-US")); 1191130803Smarcel register_charset (ebcdic_family_charset ("IBM1047")); 1192130803Smarcel register_iconv_charsets (); 1193130803Smarcel 1194130803Smarcel { 1195130803Smarcel struct { char *from; char *to; int *table; } tlist[] = { 1196130803Smarcel { "ASCII", "ISO-8859-1", ascii_to_iso_8859_1_table }, 1197130803Smarcel { "ASCII", "EBCDIC-US", ascii_to_ebcdic_us_table }, 1198130803Smarcel { "ASCII", "IBM1047", ascii_to_ibm1047_table }, 1199130803Smarcel { "ISO-8859-1", "ASCII", iso_8859_1_to_ascii_table }, 1200130803Smarcel { "ISO-8859-1", "EBCDIC-US", iso_8859_1_to_ebcdic_us_table }, 1201130803Smarcel { "ISO-8859-1", "IBM1047", iso_8859_1_to_ibm1047_table }, 1202130803Smarcel { "EBCDIC-US", "ASCII", ebcdic_us_to_ascii_table }, 1203130803Smarcel { "EBCDIC-US", "ISO-8859-1", ebcdic_us_to_iso_8859_1_table }, 1204130803Smarcel { "EBCDIC-US", "IBM1047", ebcdic_us_to_ibm1047_table }, 1205130803Smarcel { "IBM1047", "ASCII", ibm1047_to_ascii_table }, 1206130803Smarcel { "IBM1047", "ISO-8859-1", ibm1047_to_iso_8859_1_table }, 1207130803Smarcel { "IBM1047", "EBCDIC-US", ibm1047_to_ebcdic_us_table } 1208130803Smarcel }; 1209130803Smarcel 1210130803Smarcel int i; 1211130803Smarcel 1212130803Smarcel for (i = 0; i < (sizeof (tlist) / sizeof (tlist[0])); i++) 1213130803Smarcel register_translation (simple_table_translation (tlist[i].from, 1214130803Smarcel tlist[i].to, 1215130803Smarcel tlist[i].table)); 1216130803Smarcel } 1217130803Smarcel 1218130803Smarcel set_host_charset (host_charset_name); 1219130803Smarcel set_target_charset (target_charset_name); 1220130803Smarcel 1221130803Smarcel new_cmd = add_set_enum_cmd ("charset", 1222130803Smarcel class_support, 1223130803Smarcel host_charset_enum, 1224130803Smarcel &host_charset_name, 1225130803Smarcel "Set the host and target character sets.\n" 1226130803Smarcel "The `host character set' is the one used by the system GDB is running on.\n" 1227130803Smarcel "The `target character set' is the one used by the program being debugged.\n" 1228130803Smarcel "You may only use supersets of ASCII for your host character set; GDB does\n" 1229130803Smarcel "not support any others.\n" 1230130803Smarcel "To see a list of the character sets GDB supports, type `set charset <TAB>'.", 1231130803Smarcel &setlist); 1232130803Smarcel 1233130803Smarcel /* Note that the sfunc below needs to set target_charset_name, because 1234130803Smarcel the 'set charset' command sets two variables. */ 1235130803Smarcel set_cmd_sfunc (new_cmd, set_charset_sfunc); 1236130803Smarcel /* Don't use set_from_show - need to print some extra info. */ 1237130803Smarcel add_cmd ("charset", class_support, show_charset, 1238130803Smarcel "Show the host and target character sets.\n" 1239130803Smarcel "The `host character set' is the one used by the system GDB is running on.\n" 1240130803Smarcel "The `target character set' is the one used by the program being debugged.\n" 1241130803Smarcel "You may only use supersets of ASCII for your host character set; GDB does\n" 1242130803Smarcel "not support any others.\n" 1243130803Smarcel "To see a list of the character sets GDB supports, type `set charset <TAB>'.", 1244130803Smarcel &showlist); 1245130803Smarcel 1246130803Smarcel 1247130803Smarcel new_cmd = add_set_enum_cmd ("host-charset", 1248130803Smarcel class_support, 1249130803Smarcel host_charset_enum, 1250130803Smarcel &host_charset_name, 1251130803Smarcel "Set the host character set.\n" 1252130803Smarcel "The `host character set' is the one used by the system GDB is running on.\n" 1253130803Smarcel "You may only use supersets of ASCII for your host character set; GDB does\n" 1254130803Smarcel "not support any others.\n" 1255130803Smarcel "To see a list of the character sets GDB supports, type `set host-charset <TAB>'.", 1256130803Smarcel &setlist); 1257130803Smarcel 1258130803Smarcel set_cmd_sfunc (new_cmd, set_host_charset_sfunc); 1259130803Smarcel 1260130803Smarcel add_show_from_set (new_cmd, &showlist); 1261130803Smarcel 1262130803Smarcel 1263130803Smarcel 1264130803Smarcel new_cmd = add_set_enum_cmd ("target-charset", 1265130803Smarcel class_support, 1266130803Smarcel target_charset_enum, 1267130803Smarcel &target_charset_name, 1268130803Smarcel "Set the target character set.\n" 1269130803Smarcel "The `target character set' is the one used by the program being debugged.\n" 1270130803Smarcel "GDB translates characters and strings between the host and target\n" 1271130803Smarcel "character sets as needed.\n" 1272130803Smarcel "To see a list of the character sets GDB supports, type `set target-charset'<TAB>", 1273130803Smarcel &setlist); 1274130803Smarcel 1275130803Smarcel set_cmd_sfunc (new_cmd, set_target_charset_sfunc); 1276130803Smarcel add_show_from_set (new_cmd, &showlist); 1277130803Smarcel} 1278