From 53375380e934928af133bca69c1e1912c35e9c73 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 12 Apr 2017 14:00:49 +0100 Subject: Teach GDB that wchar_t is a built-in type in C++ mode GDB is currently not aware that wchar_t is a built-in type in C++ mode. This is usually not a problem because the debug info describes the type, so when you have a program loaded, you don't notice this. However, if you try expressions involving wchar_t before a program is loaded, gdb errors out: (gdb) p (wchar_t)-1 No symbol table is loaded. Use the "file" command. (gdb) p L"hello" No type named wchar_t. (gdb) ptype L"hello" No type named wchar_t. This commit teaches gdb about the type. After: (gdb) p (wchar_t)-1 $1 = -1 L'\xffffffff' (gdb) p L"hello" $2 = L"hello" (gdb) ptype L"hello" type = wchar_t [6] Unlike char16_t/char32_t, unfortunately, the underlying type of wchar_t is implementation dependent, both size and signness. So this requires adding a couple new gdbarch hooks. I grepped the GCC code base for WCHAR_TYPE and WCHAR_TYPE_SIZE, and it seems to me that the majority of the ABIs have a 4-byte signed wchar_t, so that's what I made the default for GDB too. And then I looked for which ports have a 16-bit and/or unsigned wchar_t, and made GDB follow suit. gdb/ChangeLog: 2017-04-12 Pedro Alves PR gdb/21323 * c-lang.c (cplus_primitive_types) : New enum value. (cplus_language_arch_info): Register cplus_primitive_type_wchar_t. * gdbtypes.h (struct builtin_type) : New field. * gdbtypes.c (gdbtypes_post_init): Create the "wchar_t" type. * gdbarch.sh (wchar_bit, wchar_signed): New per-arch values. * gdbarch.h, gdbarch.c: Regenerate. * aarch64-tdep.c (aarch64_gdbarch_init): Override gdbarch_wchar_bit and gdbarch_wchar_signed. * alpha-tdep.c (alpha_gdbarch_init): Likewise. * arm-tdep.c (arm_gdbarch_init): Likewise. * avr-tdep.c (avr_gdbarch_init): Likewise. * h8300-tdep.c (h8300_gdbarch_init): Likewise. * i386-nto-tdep.c (i386nto_init_abi): Likewise. * i386-tdep.c (i386_go32_init_abi): Likewise. * m32r-tdep.c (m32r_gdbarch_init): Likewise. * moxie-tdep.c (moxie_gdbarch_init): Likewise. * nds32-tdep.c (nds32_gdbarch_init): Likewise. * rs6000-aix-tdep.c (rs6000_aix_init_osabi): Likewise. * sh-tdep.c (sh_gdbarch_init): Likewise. * sparc-tdep.c (sparc32_gdbarch_init): Likewise. * sparc64-tdep.c (sparc64_init_abi): Likewise. * windows-tdep.c (windows_init_abi): Likewise. * xstormy16-tdep.c (xstormy16_gdbarch_init): Likewise. gdb/testsuite/ChangeLog: 2017-04-12 Pedro Alves PR gdb/21323 * gdb.cp/wide_char_types.c: Include . (wchar): New global. * gdb.cp/wide_char_types.exp (wide_char_types_program) (do_test_wide_char, wide_char_types_no_program, top level): Add wchar_t testing. --- gdb/m32r-tdep.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gdb/m32r-tdep.c') diff --git a/gdb/m32r-tdep.c b/gdb/m32r-tdep.c index 4701f7a..0820af9 100644 --- a/gdb/m32r-tdep.c +++ b/gdb/m32r-tdep.c @@ -911,6 +911,9 @@ m32r_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) tdep = XNEW (struct gdbarch_tdep); gdbarch = gdbarch_alloc (&info, tdep); + set_gdbarch_wchar_bit (gdbarch, 16); + set_gdbarch_wchar_signed (gdbarch, 0); + set_gdbarch_read_pc (gdbarch, m32r_read_pc); set_gdbarch_unwind_sp (gdbarch, m32r_unwind_sp); -- cgit v1.1