gdb/charset.h - gdb

Data types defined

Macros defined

Source code

  1. /* Character set conversion support for GDB.
  2.    Copyright (C) 2001-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #ifndef CHARSET_H
  15. #define CHARSET_H

  16. /* If the target program uses a different character set than the host,
  17.    GDB has some support for translating between the two; GDB converts
  18.    characters and strings to the host character set before displaying
  19.    them, and converts characters and strings appearing in expressions
  20.    entered by the user to the target character set.

  21.    GDB's code pretty much assumes that the host character set is some
  22.    superset of ASCII; there are plenty if ('0' + n) expressions and
  23.    the like.  */

  24. /* Return the name of the current host/target character set.  The
  25.    result is owned by the charset module; the caller should not free
  26.    it.  */
  27. const char *host_charset (void);
  28. const char *target_charset (struct gdbarch *gdbarch);
  29. const char *target_wide_charset (struct gdbarch *gdbarch);

  30. /* These values are used to specify the type of transliteration done
  31.    by convert_between_encodings.  */
  32. enum transliterations
  33.   {
  34.     /* Error on failure to convert.  */
  35.     translit_none,
  36.     /* Transliterate to host char.  */
  37.     translit_char
  38.   };

  39. /* Convert between two encodings.

  40.    FROM is the name of the source encoding.
  41.    TO is the name of the target encoding.
  42.    BYTES holds the bytes to convert; this is assumed to be characters
  43.    in the target encoding.
  44.    NUM_BYTES is the number of bytes.
  45.    WIDTH is the width of a character from the FROM charset, in bytes.
  46.    For a variable width encoding, WIDTH should be the size of a "base
  47.    character".
  48.    OUTPUT is an obstack where the converted data is written.  The
  49.    caller is responsible for initializing the obstack, and for
  50.    destroying the obstack should an error occur.
  51.    TRANSLIT specifies how invalid conversions should be handled.  */

  52. void convert_between_encodings (const char *from, const char *to,
  53.                                 const gdb_byte *bytes,
  54.                                 unsigned int num_bytes,
  55.                                 int width, struct obstack *output,
  56.                                 enum transliterations translit);


  57. /* These values are used by wchar_iterate to report errors.  */
  58. enum wchar_iterate_result
  59.   {
  60.     /* Ordinary return.  */
  61.     wchar_iterate_ok,
  62.     /* Invalid input sequence.  */
  63.     wchar_iterate_invalid,
  64.     /* Incomplete input sequence at the end of the input.  */
  65.     wchar_iterate_incomplete,
  66.     /* EOF.  */
  67.     wchar_iterate_eof
  68.   };

  69. /* Declaration of the opaque wchar iterator type.  */
  70. struct wchar_iterator;

  71. /* Create a new character iterator which returns wchar_t's.  INPUT is
  72.    the input buffer.  BYTES is the number of bytes in the input
  73.    buffer.  CHARSET is the name of the character set in which INPUT is
  74.    encoded.  WIDTH is the number of bytes in a base character of
  75.    CHARSET.

  76.    This function either returns a new character set iterator, or calls
  77.    error.  The result can be freed using a cleanup; see
  78.    make_cleanup_wchar_iterator.  */
  79. struct wchar_iterator *make_wchar_iterator (const gdb_byte *input,
  80.                                             size_t bytes,
  81.                                             const char *charset,
  82.                                             size_t width);

  83. /* Return a new cleanup suitable for destroying the wchar iterator
  84.    ITER.  */
  85. struct cleanup *make_cleanup_wchar_iterator (struct wchar_iterator *iter);

  86. /* Perform a single iteration of a wchar_t iterator.

  87.    Returns the number of characters converted.  A negative result
  88.    means that EOF has been reached.  A positive result indicates the
  89.    number of valid wchar_ts in the result; *OUT_CHARS is updated to
  90.    point to the first valid character.

  91.    In all cases aside from EOF, *PTR is set to point to the first
  92.    converted target byte.  *LEN is set to the number of bytes
  93.    converted.

  94.    A zero result means one of several unusual results.  *OUT_RESULT is
  95.    set to indicate the type of un-ordinary return.

  96.    wchar_iterate_invalid means that an invalid input character was
  97.    seen.  The iterator is advanced by WIDTH (the argument to
  98.    make_wchar_iterator) bytes.

  99.    wchar_iterate_incomplete means that an incomplete character was
  100.    seen at the end of the input sequence.

  101.    wchar_iterate_eof means that all bytes were successfully
  102.    converted.  The other output arguments are not set.  */
  103. int wchar_iterate (struct wchar_iterator *iter,
  104.                    enum wchar_iterate_result *out_result,
  105.                    gdb_wchar_t **out_chars,
  106.                    const gdb_byte **ptr, size_t *len);



  107. /* GDB needs to know a few details of its execution character set.
  108.    This knowledge is isolated here and in charset.c.  */

  109. /* The escape character.  */
  110. #define HOST_ESCAPE_CHAR 27

  111. /* Convert a letter, like 'c', to its corresponding control
  112.    character.  */
  113. char host_letter_to_control_character (char c);

  114. /* Convert a hex digit character to its numeric valueE.g., 'f' is
  115.    converted to 15.  This function assumes that C is a valid hex
  116.    digit.  Both upper- and lower-case letters are recognized.  */
  117. int host_hex_value (char c);

  118. #endif /* CHARSET_H */