]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Handle wide characters that cannot be converted
authorTom Tromey <tromey@adacore.com>
Thu, 5 Feb 2026 20:51:07 +0000 (13:51 -0700)
committerTom Tromey <tromey@adacore.com>
Thu, 12 Feb 2026 21:43:24 +0000 (14:43 -0700)
commit5835be9c497e85e0b788cedeff99999dbd37efd1
treec0e26caa202fe029e40223efdf10d2f0dd10b3f3
parentaf67bb32a24bf26287568ce5069d8e12be6579ec
Handle wide characters that cannot be converted

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.
gdb/char-print.c
gdb/char-print.h