From: Christina Schimpe Date: Tue, 16 Nov 2021 09:58:10 +0000 (+0100) Subject: gdb: Print cv qualifiers if class attributes are substituted X-Git-Tag: binutils-2_38~738 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=999a4952a2f32e60769b2c3baefb274613754e6d;p=thirdparty%2Fbinutils-gdb.git gdb: Print cv qualifiers if class attributes are substituted Make ptype print const/volatile qualifiers when template or typedef attributes are substituted. For a programm like ~~~ template class Cfoo { typedef float myfloat; public: DataT me0; const DataT me1=1; const myfloat me2=2.0; }; int main() { Cfoo cfoo; return 0; } ~~~ gdb outputs the following type for cfoo's attributes: ~~~ (gdb) b 14 Breakpoint 1 at 0x1170: file tmp.cc, line 14. (gdb) run Starting program: /tmp Breakpoint 1, main () at tmp.cc:14 14 return 0; (gdb) ptype cfoo type = class Cfoo [with DataT = int] { public: DataT me0; DataT me1; myfloat me2; private: typedef float myfloat; } ~~~ The cv qualifiers (const in this case) are ignored for me1 and me2. After: ~~~ (gdb) ptype cfoo type = class Cfoo [with DataT = int] { public: DataT me0; const DataT me1; const myfloat me2; private: typedef float myfloat; } ~~~ gdb/ChangeLog: 2021-11-16 Christina Schimpe * gdb/c-typeprint.c: Print cv qualifiers in case of parameter substitution. gdb/testsuite/ChangeLog: 2021-11-16 Christina Schimpe * gdb.cp/templates.cc: New template class Cfoo with const, template, typdef and integer attributes. * gdb.cp/templates.exp: Add new test using ptype and ptype/r commmands for template class CFoo. --- diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 5f20233c78a..a6228248e9e 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -119,6 +119,7 @@ c_print_type_1 (struct type *type, code = type->code (); if (local_name != NULL) { + c_type_print_modifier (type, stream, 0, 1, language); fputs_filtered (local_name, stream); if (varstring != NULL && *varstring != '\0') fputs_filtered (" ", stream); diff --git a/gdb/testsuite/gdb.cp/templates.cc b/gdb/testsuite/gdb.cp/templates.cc index d6120e2dd1c..d5b24af3a4e 100644 --- a/gdb/testsuite/gdb.cp/templates.cc +++ b/gdb/testsuite/gdb.cp/templates.cc @@ -690,6 +690,18 @@ int gf2 (int a) { char string[3]; +// Template class with typedefs and const attributes. +template +class Cfoo +{ + typedef float myfloat; +public: + DataT me0; + const DataT me1=1; + const myfloat me2=2.0; + const int me3=0; +}; + // Template for nested instantiations @@ -778,6 +790,8 @@ int main() sic.spec ('c'); siip.spec (&x); + Cfoo cfoo; + Garply f; Garply fc; f.x = 13; diff --git a/gdb/testsuite/gdb.cp/templates.exp b/gdb/testsuite/gdb.cp/templates.exp index 8370beb95b5..5f0538d8d4b 100644 --- a/gdb/testsuite/gdb.cp/templates.exp +++ b/gdb/testsuite/gdb.cp/templates.exp @@ -547,6 +547,42 @@ gdb_test_multiple "ptype/r siip" "ptype siip" { } } +# Check cv qualifiers and substitute parameters. + +if {[test_compiler_info {clang-*}]} { + setup_kfail "llvm/52262 " "*-*-*" +} +gdb_test "ptype cfoo" [multi_line \ +"type = (class |)Cfoo \\\[with DataT = double\\\] \\{" \ + "\[ \t\]*public:" \ + "\[ \t\]*DataT me0;" \ + "\[ \t\]*const DataT me1;" \ + "\[ \t\]*const myfloat me2;" \ + "\[ \t\]*const int me3;" \ + "" \ + "\[ \t\]*private:" \ + "\[ \t\]*typedef float myfloat;" \ +"\\}" \ +] "print type of cfoo" + +# Check cv qualifiers and do not substitute. + +if {[test_compiler_info {clang-*}]} { + setup_kfail "llvm/52262 " "*-*-*" +} +gdb_test "ptype/r cfoo" [multi_line \ +"type = (class |)Cfoo \\{" \ + "\[ \t\]*public:" \ + "\[ \t\]*double me0;" \ + "\[ \t\]*const double me1;" \ + "\[ \t\]*const Cfoo::myfloat me2;" \ + "\[ \t\]*const int me3;" \ + "" \ + "\[ \t\]*private:" \ + "\[ \t\]*typedef float myfloat;" \ +"\\}" \ +] "print raw type of cfoo" + # pt Garply gdb_test_multiple "ptype/r Garply" "ptype Garply" {