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/testsuite | |
parent | 53e710acd249e1861029b19b7a3d8195e7f28929 (diff) | |
download | gdb-53375380e934928af133bca69c1e1912c35e9c73.zip gdb-53375380e934928af133bca69c1e1912c35e9c73.tar.gz gdb-53375380e934928af133bca69c1e1912c35e9c73.tar.bz2 |
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/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 9 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/wide_char_types.c | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/wide_char_types.exp | 66 |
3 files changed, 63 insertions, 14 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index e2555e0..7f858e6 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,14 @@ 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. + +2017-04-12 Pedro Alves <palves@redhat.com> + PR c++/21323 * gdb.cp/wide_char_types.c: New file. * gdb.cp/wide_char_types.exp: New file. diff --git a/gdb/testsuite/gdb.cp/wide_char_types.c b/gdb/testsuite/gdb.cp/wide_char_types.c index 8337cd4..c899b71 100644 --- a/gdb/testsuite/gdb.cp/wide_char_types.c +++ b/gdb/testsuite/gdb.cp/wide_char_types.c @@ -17,9 +17,11 @@ */ #include <uchar.h> +#include <wchar.h> char16_t u16 = -1; char32_t u32 = -1; +wchar_t wchar = -1; int main () diff --git a/gdb/testsuite/gdb.cp/wide_char_types.exp b/gdb/testsuite/gdb.cp/wide_char_types.exp index df5c8a8f..6a91350 100644 --- a/gdb/testsuite/gdb.cp/wide_char_types.exp +++ b/gdb/testsuite/gdb.cp/wide_char_types.exp @@ -15,14 +15,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -# Test GDB's awareness of the char16_t, char32_t (C++11+) built-in -# types. We also run most tests here in C mode, and check whether the -# built-ins are disabled (gdb uses the typedefs in the debug info -# instead.) +# Test GDB's awareness of the wchar_t (C++98+) and char16_t, char32_t +# (C++11+) built-in types. We also run most tests here in C mode, and +# check whether the built-ins are disabled (gdb uses the typedefs in +# the debug info instead.) standard_testfile -# Test char16_t/char32_t in language LANG, against symbols in +# Test char16_t/char32_t/wchar_t in language LANG, against symbols in # a program. Lang can be "c", "c++03" or "c++11". In C++11, # char16_t/char32_t are built-in types, and the debug information # reflects that (see @@ -51,16 +51,16 @@ proc wide_char_types_program {lang} { fail "can't run to main" return 0 } - do_test_wide_char $lang "u16" "u32" + do_test_wide_char $lang "u16" "u32" "wchar" } -# Test char16_t/char32_t in language LANG. Use CHAR16_EXP and -# CHAR32_EXP as expression for each of the corresponding types. -# (E.g., CHAR16_EXP will be u16 when testing against the program, and -# "(char16_t)-1" when testing the built-in types without a program -# loaded.) +# Test char16_t/char32_t/wchar_t in language LANG. Use CHAR16_EXP, +# CHAR32_EXP, and WCHAR_EXP as expression for each of the +# corresponding types. (E.g., CHAR16_EXP will be u16 when testing +# against the program, and "(char16_t)-1" when testing the built-in +# types without a program loaded.) -proc do_test_wide_char {lang char16_exp char32_exp} { +proc do_test_wide_char {lang char16_exp char32_exp wchar_exp} { global gdb_prompt # Check that the fixed-width wide types are distinct built-in @@ -78,26 +78,60 @@ proc do_test_wide_char {lang char16_exp char32_exp} { "char32_t is typedef" } + # wchar_t is a disctinct built-in type in C++03+. + if {$lang != "c"} { + gdb_test "ptype $wchar_exp" "type = wchar_t" \ + "wchar_t is distinct" + } else { + gdb_test "ptype $wchar_exp" "type = (unsigned )?(long|int|short)" \ + "wchar_t is typedef" + } + # Check that the fixed-width wide char types are unsigned. gdb_test "p $char16_exp" " = 65535 u'\\\\xffff'" \ "char16_t is unsigned" gdb_test "p $char32_exp" " = 4294967295 U'\\\\xffffffff'" \ "char32_t is unsigned" + # Whether wchar_t is signed is implementation-dependent. While we + # ignore whether GDB got the ABI size/sign details right here, + # this at least verifies that the value isn't garbage, and that + # GDB correctly outputs the character using the "L" prefix. + set test "wchar_t sign" + gdb_test_multiple "p $wchar_exp" $test { + -re " = 4294967295 L'\\\\xffffffff'\r\n$gdb_prompt $" { + pass "$test (unsigned)" + } + -re " = 65535 L'\\\\xffff'\r\n$gdb_prompt $" { + pass "$test (unsigned)" + } + -re " = -1 L'\\\\xffffffff'\r\n$gdb_prompt $" { + pass "$test (signed)" + } + -re " = -1 L'\\\\xffff'\r\n$gdb_prompt $" { + pass "$test (signed)" + } + } + # Check sizeof. These are fixed-width. gdb_test "p sizeof($char16_exp)" "= 2" \ "sizeof($char16_exp) == 2" gdb_test "p sizeof($char32_exp)" "= 4" \ "sizeof(char16_t) == 4" + # Size of wchar_t depends on ABI. + gdb_test "p sizeof($wchar_exp)" "= (2|4)" \ + "sizeof(wchar_t)" + # Test printing wide literal strings. Note that when testing with # no program started, this relies on GDB's awareness of the # built-in wide char types. gdb_test {p U"hello"} {= U"hello"} gdb_test {p u"hello"} {= u"hello"} + gdb_test {p L"hello"} {= L"hello"} } -# Make sure that the char16_t/char32_t types are recognized as +# Make sure that the char16_t/char32_t/wchar_t types are recognized as # distinct built-in types in C++ mode, even with no program loaded. # Check that in C mode, the types are not recognized. @@ -116,8 +150,12 @@ proc wide_char_types_no_program {} { gdb_test "p (char32_t) -1" "No symbol table is loaded.*" \ "char32_t is not built-in" + gdb_test "p (wchar_t) -1" "No symbol table is loaded.*" \ + "wchar_t is not built-in" + gdb_test {p U"hello"} "No type named char32_t\\\." gdb_test {p u"hello"} "No type named char16_t\\\." + gdb_test {p L"hello"} "No type named wchar_t\\\." } # Note GDB does not distinguish C++ dialects, so the fixed-width @@ -126,7 +164,7 @@ proc wide_char_types_no_program {} { with_test_prefix "c++" { gdb_test "set language c++" - do_test_wide_char "c++11" "(char16_t) -1" "(char32_t) -1" + do_test_wide_char "c++11" "(char16_t) -1" "(char32_t) -1" "(wchar_t) -1" } } |