[Bug c++/21323] GDB thinks char16_t and char32_t are signed in C++

cvs-commit at gcc dot gnu.org sourceware-bugzilla@sourceware.org
Wed Apr 12 13:10:00 GMT 2017


https://sourceware.org/bugzilla/show_bug.cgi?id=21323

--- Comment #8 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Pedro Alves <palves@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=53375380e934928af133bca69c1e1912c35e9c73

commit 53375380e934928af133bca69c1e1912c35e9c73
Author: Pedro Alves <palves@redhat.com>
Date:   Wed Apr 12 14:00:49 2017 +0100

    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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Gdb-prs mailing list