diff options
-rw-r--r-- | gdb/cp-support.c | 10 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/break-f-std-string.exp | 13 |
2 files changed, 19 insertions, 4 deletions
diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 71c1463..807c944 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -41,6 +41,7 @@ #include <atomic> #include "event-top.h" #include "run-on-main-thread.h" +#include "typeprint.h" #define d_left(dc) (dc)->u.s_binary.left #define d_right(dc) (dc)->u.s_binary.right @@ -229,7 +230,14 @@ inspect_type (struct demangle_parse_info *info, string_file buf; try { - type_print (type, "", &buf, -1); + /* Avoid using the current language. If the language is + C, and TYPE is a struct/class, the printed type is + prefixed with "struct " or "class ", which we don't + want when we're expanding a C++ typedef. Print using + the type symbol's language to expand a C++ typedef + the C++ way even if the current language is C. */ + const language_defn *lang = language_def (sym->language ()); + lang->print_type (type, "", &buf, -1, 0, &type_print_raw_options); } /* If type_print threw an exception, there is little point in continuing, so just bow out gracefully. */ diff --git a/gdb/testsuite/gdb.cp/break-f-std-string.exp b/gdb/testsuite/gdb.cp/break-f-std-string.exp index 0869912..e222bae 100644 --- a/gdb/testsuite/gdb.cp/break-f-std-string.exp +++ b/gdb/testsuite/gdb.cp/break-f-std-string.exp @@ -93,10 +93,17 @@ proc test {cxx11_abi} { } } - gdb_test "break f($type)" "$srcfile, line $::decimal\\." + # GDB should be able to expand the std::string typedef in the + # function prototype using C++ logic even if the current language + # is C. + foreach_with_prefix lang {"c" "c++"} { + gdb_test_no_output "set language $lang" - if { $realtype != "" } { - gdb_test "break f($realtype)" "$srcfile, line $::decimal\\." + gdb_test "break f($type)" "$srcfile, line $::decimal\\." + + if { $realtype != "" } { + gdb_test "break f($realtype)" "$srcfile, line $::decimal\\." + } } } |