gdb/gdb_wchar.h - gdb

Data types defined

Macros defined

Source code

  1. /* Wide characters for gdb
  2.    Copyright (C) 2009-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 GDB_WCHAR_H
  15. #define GDB_WCHAR_H

  16. /* We handle three different modes here.

  17.    Capable systems have the full suite: wchar_t support and iconv
  18.    (perhaps via GNU libiconv).  On these machines, full functionality
  19.    is available.  Note that full functionality is dependent on us
  20.    being able to convert from an arbitrary encoding to wchar_t.  In
  21.    practice this means we look for __STDC_ISO_10646__ (where we know
  22.    the name of the wchar_t encoding) or GNU libiconv, where we can use
  23.    "wchar_t".

  24.    DJGPP is known to have libiconv but not wchar_t support.  On
  25.    systems like this, we use the narrow character functions.  The full
  26.    functionality is available to the user, but many characters (those
  27.    outside the narrow range) will be displayed as escapes.

  28.    Finally, some systems do not have iconv, or are really broken
  29.    (e.g., Solaris, which almost has all of this working, but where
  30.    just enough is broken to make it too hard to use).  Here we provide
  31.    a phony iconv which only handles a single character set, and we
  32.    provide wrappers for the wchar_t functionality we use.  */


  33. #if defined (HAVE_ICONV)
  34. #include <iconv.h>
  35. #else
  36. /* This define is used elsewhere so we don't need to duplicate the
  37.    same checking logic in multiple places.  */
  38. #define PHONY_ICONV
  39. #endif

  40. #include <wchar.h>
  41. #include <wctype.h>

  42. /* We use "btowc" as a sentinel to detect functioning wchar_t support.
  43.    We check for either __STDC_ISO_10646__ or a new-enough libiconv in
  44.    order to ensure we can convert to and from wchar_t.  We choose
  45.    libiconv version 0x108 because it is the first version with
  46.    iconvlist.  */
  47. #if defined (HAVE_ICONV) && defined (HAVE_BTOWC) \
  48.   && (defined (__STDC_ISO_10646__) \
  49.       || (defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108))

  50. typedef wchar_t gdb_wchar_t;
  51. typedef wint_t gdb_wint_t;

  52. #define gdb_wcslen wcslen
  53. #define gdb_iswprint iswprint
  54. #define gdb_iswdigit iswdigit
  55. #define gdb_btowc btowc
  56. #define gdb_WEOF WEOF

  57. #define LCST(X) L ## X

  58. /* If __STDC_ISO_10646__ is defined, then the host wchar_t is UCS-4.
  59.    We exploit this fact in the hope that there are hosts that define
  60.    this but which do not support "wchar_t" as an encoding argument to
  61.    iconv_open.  We put the endianness into the encoding name to avoid
  62.    hosts that emit a BOM when the unadorned name is used.  */
  63. #if defined (__STDC_ISO_10646__)
  64. #define USE_INTERMEDIATE_ENCODING_FUNCTION
  65. #define INTERMEDIATE_ENCODING intermediate_encoding ()
  66. const char *intermediate_encoding (void);

  67. #elif defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108
  68. #define INTERMEDIATE_ENCODING "wchar_t"
  69. #else
  70. /* This shouldn't happen, because the earlier #if should have filtered
  71.    out this case.  */
  72. #error "Neither __STDC_ISO_10646__ nor _LIBICONV_VERSION defined"
  73. #endif

  74. #else

  75. /* If we got here and have wchar_t support, we might be on a system
  76.    with some problem.  So, we just disable everything.  */
  77. #if defined (HAVE_BTOWC)
  78. #define PHONY_ICONV
  79. #endif

  80. typedef char gdb_wchar_t;
  81. typedef int gdb_wint_t;

  82. #define gdb_wcslen strlen
  83. #define gdb_iswprint isprint
  84. #define gdb_iswdigit isdigit
  85. #define gdb_btowc /* empty */
  86. #define gdb_WEOF EOF

  87. #define LCST(X) X

  88. /* If we are using the narrow character set, we want to use the host
  89.    narrow encoding as our intermediate encoding.  However, if we are
  90.    also providing a phony iconv, we might as well just stick with
  91.    "wchar_t".  */
  92. #ifdef PHONY_ICONV
  93. #define INTERMEDIATE_ENCODING "wchar_t"
  94. #else
  95. #define INTERMEDIATE_ENCODING host_charset ()
  96. #endif

  97. #endif

  98. #endif /* GDB_WCHAR_H */