diff options
author | Pedro Alves <palves@redhat.com> | 2017-04-12 14:00:49 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2017-04-12 14:06:40 +0100 |
commit | 53375380e934928af133bca69c1e1912c35e9c73 (patch) | |
tree | c81e10950592b97cb76c9843c902901a1aafb908 /gdb/moxie-tdep.c | |
parent | Fix PR c++/21323: GDB thinks char16_t and char32_t are signed in C++ (diff) | |
download | binutils-gdb-53375380e934928af133bca69c1e1912c35e9c73.tar.gz binutils-gdb-53375380e934928af133bca69c1e1912c35e9c73.tar.bz2 binutils-gdb-53375380e934928af133bca69c1e1912c35e9c73.zip |
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 <palves@redhat.com>
PR gdb/21323
* c-lang.c (cplus_primitive_types) <cplus_primitive_type_wchar_t>:
New enum value.
(cplus_language_arch_info): Register cplus_primitive_type_wchar_t.
* gdbtypes.h (struct builtin_type) <builtin_wchar>: 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 <palves@redhat.com>
PR gdb/21323
* gdb.cp/wide_char_types.c: Include <wchar.h>.
(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.
Diffstat (limited to 'gdb/moxie-tdep.c')
-rw-r--r-- | gdb/moxie-tdep.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/gdb/moxie-tdep.c b/gdb/moxie-tdep.c index d0f4223d7f0..dd7a6f4bfb1 100644 --- a/gdb/moxie-tdep.c +++ b/gdb/moxie-tdep.c @@ -1112,6 +1112,9 @@ moxie_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, 32); + set_gdbarch_wchar_signed (gdbarch, 0); + set_gdbarch_read_pc (gdbarch, moxie_read_pc); set_gdbarch_write_pc (gdbarch, moxie_write_pc); set_gdbarch_unwind_sp (gdbarch, moxie_unwind_sp); |