public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Fix print of cv qualifiers
@ 2021-11-16  9:58 Christina Schimpe
  2021-11-16  9:58 ` [PATCH v2 1/2] gdb: Print cv qualifiers if class attributes are substituted Christina Schimpe
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christina Schimpe @ 2021-11-16  9:58 UTC (permalink / raw)
  To: gdb-patches

Hi all, 

here is an updated version of the patch based on the feedback of Andrew.
V1 of this patch can be found here:
https://sourceware.org/pipermail/gdb-patches/2021-November/183081.html

Changes since V1:
- New commit for changes in gdb.cp/ptype-cv-cp.*.
- Supplemented ptype and whatis tests in gdb.cp/ptype-cv-cp.*.
- Formatted test comments.
- Removed hard-coded line number in gdb.cp/templates.exp.

Thanks,
Christina

Christina Schimpe (2):
  gdb: Print cv qualifiers if class attributes are substituted
  gdb/testsuite: Extend tests for print of cv qualifiers

 gdb/c-typeprint.c                    |  1 +
 gdb/testsuite/gdb.cp/ptype-cv-cp.cc  |  4 ++++
 gdb/testsuite/gdb.cp/ptype-cv-cp.exp | 12 ++++++++++
 gdb/testsuite/gdb.cp/templates.cc    | 14 +++++++++++
 gdb/testsuite/gdb.cp/templates.exp   | 36 ++++++++++++++++++++++++++++
 5 files changed, 67 insertions(+)

-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] gdb: Print cv qualifiers if class attributes are substituted
  2021-11-16  9:58 [PATCH v2 0/2] Fix print of cv qualifiers Christina Schimpe
@ 2021-11-16  9:58 ` Christina Schimpe
  2021-11-16  9:58 ` [PATCH v2 2/2] gdb/testsuite: Extend tests for print of cv qualifiers Christina Schimpe
  2021-11-19 11:33 ` [PATCH v2 0/2] Fix " Andrew Burgess
  2 siblings, 0 replies; 4+ messages in thread
From: Christina Schimpe @ 2021-11-16  9:58 UTC (permalink / raw)
  To: gdb-patches

Make ptype print const/volatile qualifiers when template or typedef
attributes are substituted.

For a programm like
~~~
template<typename DataT>
class Cfoo
{
  typedef float myfloat;
public:
  DataT me0;
  const DataT me1=1;
  const myfloat me2=2.0;
};

int main()
{
  Cfoo<int> 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<int> [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<int> [with DataT = int] {
  public:
    DataT me0;
    const DataT me1;
    const myfloat me2;

  private:
    typedef float myfloat;
}
~~~

gdb/ChangeLog:
2021-11-16  Christina Schimpe  <christina.schimpe@intel.com>

	* gdb/c-typeprint.c: Print cv qualifiers in case of parameter
	  substitution.

gdb/testsuite/ChangeLog:
2021-11-16  Christina Schimpe  <christina.schimpe@intel.com>

	* 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.
---
 gdb/c-typeprint.c                  |  1 +
 gdb/testsuite/gdb.cp/templates.cc  | 14 ++++++++++++
 gdb/testsuite/gdb.cp/templates.exp | 36 ++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)

diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 5f20233c78..a6228248e9 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 d6120e2dd1..d5b24af3a4 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<typename DataT>
+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<double> cfoo;
+
   Garply<int> f;
   Garply<char> fc;
   f.x = 13;
diff --git a/gdb/testsuite/gdb.cp/templates.exp b/gdb/testsuite/gdb.cp/templates.exp
index 8370beb95b..5f0538d8d4 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<double> \\\[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<double> \\{" \
+  "\[ \t\]*public:" \
+    "\[ \t\]*double me0;" \
+    "\[ \t\]*const double me1;" \
+    "\[ \t\]*const Cfoo<double>::myfloat me2;" \
+    "\[ \t\]*const int me3;" \
+    "" \
+  "\[ \t\]*private:" \
+    "\[ \t\]*typedef float myfloat;" \
+"\\}" \
+] "print raw type of cfoo"
+
 # pt Garply<int>
 
 gdb_test_multiple "ptype/r Garply<int>" "ptype Garply<int>" {
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] gdb/testsuite: Extend tests for print of cv qualifiers
  2021-11-16  9:58 [PATCH v2 0/2] Fix print of cv qualifiers Christina Schimpe
  2021-11-16  9:58 ` [PATCH v2 1/2] gdb: Print cv qualifiers if class attributes are substituted Christina Schimpe
@ 2021-11-16  9:58 ` Christina Schimpe
  2021-11-19 11:33 ` [PATCH v2 0/2] Fix " Andrew Burgess
  2 siblings, 0 replies; 4+ messages in thread
From: Christina Schimpe @ 2021-11-16  9:58 UTC (permalink / raw)
  To: gdb-patches

This commit supplements whatis and ptype command tests for print of
const-volatile qualifiers.

gdb/testsuite/ChangeLog:
2021-11-16  Christina Schimpe  <christina.schimpe@intel.com>

	* gdb.cp/ptype-cv-cp.cc: New const and volatile typedef
	  variables.
	* gdb.cp/ptype-cv-cp.exp: Add new tests.
---
 gdb/testsuite/gdb.cp/ptype-cv-cp.cc  |  4 ++++
 gdb/testsuite/gdb.cp/ptype-cv-cp.exp | 12 ++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/gdb/testsuite/gdb.cp/ptype-cv-cp.cc b/gdb/testsuite/gdb.cp/ptype-cv-cp.cc
index 9560dfa80b..27dc2f1b33 100644
--- a/gdb/testsuite/gdb.cp/ptype-cv-cp.cc
+++ b/gdb/testsuite/gdb.cp/ptype-cv-cp.cc
@@ -26,6 +26,10 @@ __attribute__((used)) const_my_int v_const_my_int (1);
 volatile_my_int v_volatile_my_int (2);
 const_volatile_my_int v_const_volatile_my_int (3);
 volatile_const_my_int v_volatile_const_my_int (4);
+__attribute__((used)) const my_int v2_const_my_int (5);
+volatile my_int v2_volatile_my_int (6);
+const volatile my_int v2_const_volatile_my_int (7);
+volatile const my_int v2_volatile_const_my_int (8);
 
 int
 main ()
diff --git a/gdb/testsuite/gdb.cp/ptype-cv-cp.exp b/gdb/testsuite/gdb.cp/ptype-cv-cp.exp
index b3574cbd34..5518a4e30e 100644
--- a/gdb/testsuite/gdb.cp/ptype-cv-cp.exp
+++ b/gdb/testsuite/gdb.cp/ptype-cv-cp.exp
@@ -41,3 +41,15 @@ if {[test_compiler_info {gcc-[0-3]-*}]
     setup_xfail "gcc/45997" "*-*-*"
 }
 gdb_test "ptype v_volatile_const_my_int" "type = const volatile int"
+
+gdb_test "ptype v2_const_my_int" "type = const int"
+gdb_test "whatis v2_const_my_int" "type = const my_int"
+
+gdb_test "ptype v2_volatile_my_int" "type = volatile int"
+gdb_test "whatis v2_volatile_my_int" "type = volatile my_int"
+
+gdb_test "ptype v2_const_volatile_my_int" "type = const volatile int"
+gdb_test "whatis v2_const_volatile_my_int" "type = const volatile my_int"
+
+gdb_test "ptype v2_volatile_const_my_int" "type = const volatile int"
+gdb_test "whatis v2_volatile_const_my_int" "type = const volatile my_int"
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] Fix print of cv qualifiers
  2021-11-16  9:58 [PATCH v2 0/2] Fix print of cv qualifiers Christina Schimpe
  2021-11-16  9:58 ` [PATCH v2 1/2] gdb: Print cv qualifiers if class attributes are substituted Christina Schimpe
  2021-11-16  9:58 ` [PATCH v2 2/2] gdb/testsuite: Extend tests for print of cv qualifiers Christina Schimpe
@ 2021-11-19 11:33 ` Andrew Burgess
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Burgess @ 2021-11-19 11:33 UTC (permalink / raw)
  To: Christina Schimpe; +Cc: gdb-patches

* Christina Schimpe via Gdb-patches <gdb-patches@sourceware.org> [2021-11-16 10:58:09 +0100]:

> Hi all, 
> 
> here is an updated version of the patch based on the feedback of Andrew.
> V1 of this patch can be found here:
> https://sourceware.org/pipermail/gdb-patches/2021-November/183081.html
> 
> Changes since V1:
> - New commit for changes in gdb.cp/ptype-cv-cp.*.
> - Supplemented ptype and whatis tests in gdb.cp/ptype-cv-cp.*.
> - Formatted test comments.
> - Removed hard-coded line number in gdb.cp/templates.exp.

Thanks for making these changes.  I pushed both these patches.

Andrew

> 
> Thanks,
> Christina
> 
> Christina Schimpe (2):
>   gdb: Print cv qualifiers if class attributes are substituted
>   gdb/testsuite: Extend tests for print of cv qualifiers
> 
>  gdb/c-typeprint.c                    |  1 +
>  gdb/testsuite/gdb.cp/ptype-cv-cp.cc  |  4 ++++
>  gdb/testsuite/gdb.cp/ptype-cv-cp.exp | 12 ++++++++++
>  gdb/testsuite/gdb.cp/templates.cc    | 14 +++++++++++
>  gdb/testsuite/gdb.cp/templates.exp   | 36 ++++++++++++++++++++++++++++
>  5 files changed, 67 insertions(+)
> 
> -- 
> 2.25.1
> 
> Intel Deutschland GmbH
> Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
> Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
> Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
> Chairperson of the Supervisory Board: Nicole Lau
> Registered Office: Munich
> Commercial Register: Amtsgericht Muenchen HRB 186928
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-19 11:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16  9:58 [PATCH v2 0/2] Fix print of cv qualifiers Christina Schimpe
2021-11-16  9:58 ` [PATCH v2 1/2] gdb: Print cv qualifiers if class attributes are substituted Christina Schimpe
2021-11-16  9:58 ` [PATCH v2 2/2] gdb/testsuite: Extend tests for print of cv qualifiers Christina Schimpe
2021-11-19 11:33 ` [PATCH v2 0/2] Fix " Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).