GDB (API)
/home/stan/gdb/src/gdb/charset.h
Go to the documentation of this file.
00001 /* Character set conversion support for GDB.
00002    Copyright (C) 2001-2013 Free Software Foundation, Inc.
00003 
00004    This file is part of GDB.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 3 of the License, or
00009    (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00018 
00019 #ifndef CHARSET_H
00020 #define CHARSET_H
00021 
00022 /* If the target program uses a different character set than the host,
00023    GDB has some support for translating between the two; GDB converts
00024    characters and strings to the host character set before displaying
00025    them, and converts characters and strings appearing in expressions
00026    entered by the user to the target character set.
00027 
00028    GDB's code pretty much assumes that the host character set is some
00029    superset of ASCII; there are plenty if ('0' + n) expressions and
00030    the like.  */
00031 
00032 /* Return the name of the current host/target character set.  The
00033    result is owned by the charset module; the caller should not free
00034    it.  */
00035 const char *host_charset (void);
00036 const char *target_charset (struct gdbarch *gdbarch);
00037 const char *target_wide_charset (struct gdbarch *gdbarch);
00038 
00039 /* These values are used to specify the type of transliteration done
00040    by convert_between_encodings.  */
00041 enum transliterations
00042   {
00043     /* Error on failure to convert.  */
00044     translit_none,
00045     /* Transliterate to host char.  */
00046     translit_char
00047   };
00048 
00049 /* Convert between two encodings.
00050 
00051    FROM is the name of the source encoding.
00052    TO is the name of the target encoding.
00053    BYTES holds the bytes to convert; this is assumed to be characters
00054    in the target encoding.
00055    NUM_BYTES is the number of bytes.
00056    WIDTH is the width of a character from the FROM charset, in bytes.
00057    For a variable width encoding, WIDTH should be the size of a "base
00058    character".
00059    OUTPUT is an obstack where the converted data is written.  The
00060    caller is responsible for initializing the obstack, and for
00061    destroying the obstack should an error occur.
00062    TRANSLIT specifies how invalid conversions should be handled.  */
00063 
00064 void convert_between_encodings (const char *from, const char *to,
00065                                 const gdb_byte *bytes,
00066                                 unsigned int num_bytes,
00067                                 int width, struct obstack *output,
00068                                 enum transliterations translit);
00069 
00070 
00071 /* These values are used by wchar_iterate to report errors.  */
00072 enum wchar_iterate_result
00073   {
00074     /* Ordinary return.  */
00075     wchar_iterate_ok,
00076     /* Invalid input sequence.  */
00077     wchar_iterate_invalid,
00078     /* Incomplete input sequence at the end of the input.  */
00079     wchar_iterate_incomplete,
00080     /* EOF.  */
00081     wchar_iterate_eof
00082   };
00083 
00084 /* Declaration of the opaque wchar iterator type.  */
00085 struct wchar_iterator;
00086 
00087 /* Create a new character iterator which returns wchar_t's.  INPUT is
00088    the input buffer.  BYTES is the number of bytes in the input
00089    buffer.  CHARSET is the name of the character set in which INPUT is
00090    encoded.  WIDTH is the number of bytes in a base character of
00091    CHARSET.
00092    
00093    This function either returns a new character set iterator, or calls
00094    error.  The result can be freed using a cleanup; see
00095    make_cleanup_wchar_iterator.  */
00096 struct wchar_iterator *make_wchar_iterator (const gdb_byte *input,
00097                                             size_t bytes,
00098                                             const char *charset,
00099                                             size_t width);
00100 
00101 /* Return a new cleanup suitable for destroying the wchar iterator
00102    ITER.  */
00103 struct cleanup *make_cleanup_wchar_iterator (struct wchar_iterator *iter);
00104 
00105 /* Perform a single iteration of a wchar_t iterator.
00106    
00107    Returns the number of characters converted.  A negative result
00108    means that EOF has been reached.  A positive result indicates the
00109    number of valid wchar_ts in the result; *OUT_CHARS is updated to
00110    point to the first valid character.
00111 
00112    In all cases aside from EOF, *PTR is set to point to the first
00113    converted target byte.  *LEN is set to the number of bytes
00114    converted.
00115 
00116    A zero result means one of several unusual results.  *OUT_RESULT is
00117    set to indicate the type of un-ordinary return.
00118 
00119    wchar_iterate_invalid means that an invalid input character was
00120    seen.  The iterator is advanced by WIDTH (the argument to
00121    make_wchar_iterator) bytes.
00122 
00123    wchar_iterate_incomplete means that an incomplete character was
00124    seen at the end of the input sequence.
00125    
00126    wchar_iterate_eof means that all bytes were successfully
00127    converted.  The other output arguments are not set.  */
00128 int wchar_iterate (struct wchar_iterator *iter,
00129                    enum wchar_iterate_result *out_result,
00130                    gdb_wchar_t **out_chars,
00131                    const gdb_byte **ptr, size_t *len);
00132 
00133 
00134 
00135 /* GDB needs to know a few details of its execution character set.
00136    This knowledge is isolated here and in charset.c.  */
00137 
00138 /* The escape character.  */
00139 #define HOST_ESCAPE_CHAR 27
00140 
00141 /* Convert a letter, like 'c', to its corresponding control
00142    character.  */
00143 char host_letter_to_control_character (char c);
00144 
00145 /* Convert a hex digit character to its numeric value.  E.g., 'f' is
00146    converted to 15.  This function assumes that C is a valid hex
00147    digit.  Both upper- and lower-case letters are recognized.  */
00148 int host_hex_value (char c);
00149 
00150 #endif /* CHARSET_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines