diff options
| author | Tom Tromey <tromey@adacore.com> | 2026-02-05 13:51:07 -0700 |
|---|---|---|
| committer | Tom Tromey <tromey@adacore.com> | 2026-02-12 14:43:24 -0700 |
| commit | 5835be9c497e85e0b788cedeff99999dbd37efd1 (patch) | |
| tree | c0e26caa202fe029e40223efdf10d2f0dd10b3f3 /gdb/char-print.h | |
| parent | af67bb32a24bf26287568ce5069d8e12be6579ec (diff) | |
| download | binutils-master.zip binutils-master.tar.gz binutils-master.tar.bz2 | |
The internal AdaCore test suite found a bug with the char-printing
changes: on Windows, it is possible to have a wide character (in our
case, 0xBEEF) that is "printable" (as determined by iswprint) but
which cannot be converted to the current host charset.
This in turn would result in strange output like:
$2 = 48879 '\357\276'
where what we would expect in Ada would be:
$2 = 48879 '["00beef"]'
A similar problem could occur for C on Windows. There, the character
boundaries appeared lost to the user, so rather than '\xbeef' the user
would see '\357\276'.
This patch fixes this problem by checking the convertibility of a wide
character before printing it.
New in v3: Correctly check result of wcrtomb
New in v2: Skip the new check if the host encoding is UTF-8.
Diffstat (limited to 'gdb/char-print.h')
| -rw-r--r-- | gdb/char-print.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gdb/char-print.h b/gdb/char-print.h index 36b09c4..bbadb96 100644 --- a/gdb/char-print.h +++ b/gdb/char-print.h @@ -81,6 +81,7 @@ public: : m_encoding (encoding == nullptr ? get_default_encoding (ch_type) : encoding), + m_host_utf8 (streq (host_charset (), "UTF-8")), m_byte_order (type_byte_order (ch_type)), m_file (&m_wchar_buf), m_quoter (quoter), @@ -169,10 +170,17 @@ protected: private: + /* Check whether C is both printable (deferring to the 'printable' + method), and also whether it is convertible to the host character + set. Returns true if both conditions hold, false otherwise. */ + bool printable_and_convertible (gdb_wchar_t c) const; + /* Intermediate output is stored here. */ auto_obstack m_wchar_buf; /* The encoding. */ const char *m_encoding; + /* True if the host encoding is UTF-8. */ + bool m_host_utf8; protected: |
