X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fcharset.h;h=dba95beeb406a7566d5a5ca3152f1158954b76eb;hb=refs%2Fheads%2Fconcurrent-displaced-stepping-2020-04-01;hp=bd93d01d7d02f9d48904deaef6c07479fa8a23bc;hpb=f870a310ee7fbfd6ccaea95d632063cbdbd2b9c9;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/charset.h b/gdb/charset.h index bd93d01d7d..dba95beeb4 100644 --- a/gdb/charset.h +++ b/gdb/charset.h @@ -1,5 +1,5 @@ /* Character set conversion support for GDB. - Copyright (C) 2001, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2001-2020 Free Software Foundation, Inc. This file is part of GDB. @@ -19,6 +19,8 @@ #ifndef CHARSET_H #define CHARSET_H +#include "gdbsupport/def-vector.h" + /* If the target program uses a different character set than the host, GDB has some support for translating between the two; GDB converts characters and strings to the host character set before displaying @@ -60,8 +62,10 @@ enum transliterations caller is responsible for initializing the obstack, and for destroying the obstack should an error occur. TRANSLIT specifies how invalid conversions should be handled. */ + void convert_between_encodings (const char *from, const char *to, - const gdb_byte *bytes, unsigned int num_bytes, + const gdb_byte *bytes, + unsigned int num_bytes, int width, struct obstack *output, enum transliterations translit); @@ -79,53 +83,69 @@ enum wchar_iterate_result wchar_iterate_eof }; -/* Declaration of the opaque wchar iterator type. */ -struct wchar_iterator; +/* An iterator that returns host wchar_t's from a target string. */ +class wchar_iterator +{ + public: -/* Create a new character iterator which returns wchar_t's. INPUT is - the input buffer. BYTES is the number of bytes in the input - buffer. CHARSET is the name of the character set in which INPUT is - encoded. WIDTH is the number of bytes in a base character of - CHARSET. - - This function either returns a new character set iterator, or calls - error. The result can be freed using a cleanup; see - make_cleanup_wchar_iterator. */ -struct wchar_iterator *make_wchar_iterator (const gdb_byte *input, size_t bytes, - const char *charset, - size_t width); - -/* Return a new cleanup suitable for destroying the wchar iterator - ITER. */ -struct cleanup *make_cleanup_wchar_iterator (struct wchar_iterator *iter); - -/* Perform a single iteration of a wchar_t iterator. + /* Create a new character iterator which returns wchar_t's. INPUT is + the input buffer. BYTES is the number of bytes in the input + buffer. CHARSET is the name of the character set in which INPUT is + encoded. WIDTH is the number of bytes in a base character of + CHARSET. + + This constructor can throw on error. */ + wchar_iterator (const gdb_byte *input, size_t bytes, const char *charset, + size_t width); + + ~wchar_iterator (); + + /* Perform a single iteration of a wchar_t iterator. - Returns the number of characters converted. A negative result - means that EOF has been reached. A positive result indicates the - number of valid wchar_ts in the result; *OUT_CHARS is updated to - point to the first valid character. + Returns the number of characters converted. A negative result + means that EOF has been reached. A positive result indicates the + number of valid wchar_ts in the result; *OUT_CHARS is updated to + point to the first valid character. - In all cases aside from EOF, *PTR is set to point to the first - converted target byte. *LEN is set to the number of bytes - converted. + In all cases aside from EOF, *PTR is set to point to the first + converted target byte. *LEN is set to the number of bytes + converted. - A zero result means one of several unusual results. *OUT_RESULT is - set to indicate the type of un-ordinary return. + A zero result means one of several unusual results. *OUT_RESULT is + set to indicate the type of un-ordinary return. - wchar_iterate_invalid means that an invalid input character was - seen. The iterator is advanced by WIDTH (the argument to - make_wchar_iterator) bytes. + wchar_iterate_invalid means that an invalid input character was + seen. The iterator is advanced by WIDTH (the argument to + the wchar_iterator constructor) bytes. - wchar_iterate_incomplete means that an incomplete character was - seen at the end of the input sequence. + wchar_iterate_incomplete means that an incomplete character was + seen at the end of the input sequence. - wchar_iterate_eof means that all bytes were successfully - converted. The other output arguments are not set. */ -int wchar_iterate (struct wchar_iterator *iter, - enum wchar_iterate_result *out_result, - gdb_wchar_t **out_chars, - const gdb_byte **ptr, size_t *len); + wchar_iterate_eof means that all bytes were successfully + converted. The other output arguments are not set. */ + int iterate (enum wchar_iterate_result *out_result, gdb_wchar_t **out_chars, + const gdb_byte **ptr, size_t *len); + + private: + + /* The underlying iconv descriptor. */ +#ifdef PHONY_ICONV + int m_desc; +#else + iconv_t m_desc; +#endif + + /* The input string. This is updated as we convert characters. */ + const gdb_byte *m_input; + /* The number of bytes remaining in the input. */ + size_t m_bytes; + + /* The width of an input character. */ + size_t m_width; + + /* The output buffer. */ + gdb::def_vector m_out; +};