aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCiaran Woodward <ciaranwoodward@xmos.com>2024-06-10 16:52:37 +0100
committerCiaran Woodward <ciaranwoodward@xmos.com>2024-06-12 11:20:36 +0100
commitf41400ee71f8cfa40b4fb784cbba231394b9c698 (patch)
tree48102537f0a5bed615e9bf25d40abfa87e0f8fa1
parent0c7da7665fcb0edbb330c8ac25eaaaac3bb9d06a (diff)
downloadgdb-f41400ee71f8cfa40b4fb784cbba231394b9c698.zip
gdb-f41400ee71f8cfa40b4fb784cbba231394b9c698.tar.gz
gdb-f41400ee71f8cfa40b4fb784cbba231394b9c698.tar.bz2
Fix printing strings on macOS Sonoma
On macOS sonoma, printing a string would only print the first character. For instance, if there was a 'const char *s = "foobar"', then the 'print s' command would print '$1 = "f"' rather than the expected '$1 = "foobar"'. It seems that this is due to Apple silently replacing the version of libiconv they ship with the OS to one which silently fails to handle the 'outbytesleft' parameter correctly when using 'wchar_t' as a target encoding. This specifically causes issues when using iterating through a string as wchar_iterator does. This bug is visible even if you build for an old version of macOS, but then run on Sonoma. Therefore this fix in the code applies generally to macOS, and not specific to building on Sonoma. Building for an older version and expecting forwards compatibility is a common situation on macOS. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31853 Approved-By: Tom Tromey <tom@tromey.com> (cherry picked from commit bb2981798f54e6eb30e46fb11cda2ca49561ffd3)
-rw-r--r--gdb/gdb_wchar.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/gdb/gdb_wchar.h b/gdb/gdb_wchar.h
index 8df00e4..909a0e4 100644
--- a/gdb/gdb_wchar.h
+++ b/gdb/gdb_wchar.h
@@ -76,8 +76,19 @@ typedef wint_t gdb_wint_t;
We exploit this fact in the hope that there are hosts that define
this but which do not support "wchar_t" as an encoding argument to
iconv_open. We put the endianness into the encoding name to avoid
- hosts that emit a BOM when the unadorned name is used. */
-#if defined (__STDC_ISO_10646__)
+ hosts that emit a BOM when the unadorned name is used.
+
+ Also, on version 14 macOS 'Sonoma', the implementation of iconv was
+ changed in such a way that breaks the way that gdb was using it.
+ Specifically, using wchar_t as an intermediate encoding silently
+ breaks when attempting to do character-by-character encoding.
+ By using the intermediate_encoding function to choose a suitable
+ encoding to put in the wchar_t, the iconv implementation behaves as
+ we expect it to. Strictly speaking, this seems to be a bug in
+ Sonoma specifically, but it is desirable for binaries built for
+ older versions of macOS to still work on newer ones such as Sonoma,
+ so there is no version check here for this workaround. */
+#if defined (__STDC_ISO_10646__) || defined (__APPLE__)
#define USE_INTERMEDIATE_ENCODING_FUNCTION
#define INTERMEDIATE_ENCODING intermediate_encoding ()
const char *intermediate_encoding (void);