Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Use UTF-32 as the wide charset for 64-bit
@ 2026-10-15 13:47 Aditya Vidyadhar Kamath
  2026-10-15 14:05 ` Tom Tromey
  2026-10-19 16:04 ` Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Aditya Vidyadhar Kamath @ 2026-10-15 13:47 UTC (permalink / raw)
  To: ulrich.weigand, simon.marchi, tom
  Cc: gdb-patches, Aditya.Kamath1, sangamesh.swamy, Aditya Vidyadhar Kamath

From: Aditya Vidyadhar Kamath <aditya.kamath1@ibm.com>

On AIX, wchar_t is 4 bytes in 64-bit mode and 2 bytes in 32-bit mode,
and rs6000_aix_init_osabi sets wchar_bit accordingly.  The
auto_wide_charset method however always returned "UTF-16", so a 64-bit
inferior's wide strings were decoded as 2-byte units.  This printed
L'\000\000a' for L'a', and GDB crashed with SIGSEGV on the following
print in gdb.base/wchar.exp.

Return "UTF-32" for 64-bit and keep "UTF-16" for 32-bit.  wchar.exp now
passes in 64-bit mode.
---
 gdb/rs6000-aix-tdep.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index d823fea5645..a80caa9dc18 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -1052,14 +1052,22 @@ rs6000_software_single_step (struct regcache *regcache)
   return next_pcs;
 }
 
-/* Implement the "auto_wide_charset" gdbarch method for this platform.  */
+/* Implement the "auto_wide_charset" gdbarch method for this platform.
+   wchar_t is 2 bytes in 32-bit mode and 4 bytes in 64-bit mode, see
+   the set_gdbarch_wchar_bit calls in rs6000_aix_init_osabi.  */
 
 static const char *
-rs6000_aix_auto_wide_charset (void)
+rs6000_aix_auto_wide_charset_32 (void)
 {
   return "UTF-16";
 }
 
+static const char *
+rs6000_aix_auto_wide_charset_64 (void)
+{
+  return "UTF-32";
+}
+
 /* Implement an osabi sniffer for RS6000/AIX.
 
    This function assumes that ABFD's flavour is XCOFF.  In other words,
@@ -1404,11 +1412,18 @@ rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
     set_gdbarch_frame_red_zone_size (gdbarch, 288);
 
   if (tdep->wordsize == 8)
-    set_gdbarch_wchar_bit (gdbarch, 32);
+    {
+      set_gdbarch_wchar_bit (gdbarch, 32);
+      set_gdbarch_auto_wide_charset (gdbarch,
+  		     rs6000_aix_auto_wide_charset_64);
+    }
   else
-    set_gdbarch_wchar_bit (gdbarch, 16);
+    {
+      set_gdbarch_wchar_bit (gdbarch, 16);
+      set_gdbarch_auto_wide_charset (gdbarch,
+  		     rs6000_aix_auto_wide_charset_32);
+    }
   set_gdbarch_wchar_signed (gdbarch, false);
-  set_gdbarch_auto_wide_charset (gdbarch, rs6000_aix_auto_wide_charset);
 
   set_gdbarch_make_solib_ops (gdbarch, make_aix_solib_ops);
   frame_unwind_append_unwinder (gdbarch, &aix_sighandle_frame_unwind);
-- 
2.51.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-10-21  6:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-15 13:47 [PATCH] Use UTF-32 as the wide charset for 64-bit Aditya Vidyadhar Kamath
2026-10-15 14:05 ` Tom Tromey
2026-10-16 12:02   ` Aditya Kamath
2026-10-19 16:04 ` Tom Tromey
2026-10-21  6:32   ` Aditya Kamath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox