public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [review] Normalize Ada ptype to use a single "?"
@ 2019-12-04 22:19 Tom Tromey (Code Review)
  2019-12-08  0:40 ` Joel Brobecker (Code Review)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tom Tromey (Code Review) @ 2019-12-04 22:19 UTC (permalink / raw)
  To: gdb-patches

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/740
......................................................................

Normalize Ada ptype to use a single "?"

Sometimes -- notably with unchecked unions -- the Ada "ptype" code
will print a "?" or "??" to indicate something unknown.  The choice of
what was printed was somewhat arbitrary, and in one case, Ada would
print an empty string rather than "?".

This patch normalizes the Ada code to use "?" rather than an empty
string or "??".  My reasoning here is that a single question mark is
enough to convey unknown-ness.

gdb/ChangeLog
2019-12-04  Tom Tromey  <tromey@adacore.com>

	* ada-typeprint.c (print_choices): Use a single "?".
	(print_variant_part): Print "?" if the discriminant name
	is not known.

gdb/testsuite/ChangeLog
2019-12-04  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/unchecked_union.exp: New file.
	* gdb.ada/unchecked_union/pck.adb: New file.
	* gdb.ada/unchecked_union/pck.ads: New file.
	* gdb.ada/unchecked_union/unchecked_union.adb: New file.
	* gdb-utils.exp (string_to_regexp): Also quote "?".

Change-Id: I3403040780a155ffa2c44c8e6a04ba86bc810e29
---
M gdb/ChangeLog
M gdb/ada-typeprint.c
M gdb/testsuite/ChangeLog
A gdb/testsuite/gdb.ada/unchecked_union.exp
A gdb/testsuite/gdb.ada/unchecked_union/pck.adb
A gdb/testsuite/gdb.ada/unchecked_union/pck.ads
A gdb/testsuite/gdb.ada/unchecked_union/unchecked_union.adb
M gdb/testsuite/lib/gdb-utils.exp
8 files changed, 171 insertions(+), 5 deletions(-)



diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f06f739..55bf790 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2019-12-04  Tom Tromey  <tromey@adacore.com>
 
+	* ada-typeprint.c (print_choices): Use a single "?".
+	(print_variant_part): Print "?" if the discriminant name
+	is not known.
+
+2019-12-04  Tom Tromey  <tromey@adacore.com>
+
 	* gdbtypes.c (create_range_type): Inherit endianity
 	from base type.
 
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index f89dd23..70fad1c 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -526,7 +526,7 @@
     }
 
 Huh:
-  fprintf_filtered (stream, "?? =>");
+  fprintf_filtered (stream, "? =>");
   return 0;
 }
 
@@ -592,9 +592,12 @@
 		    struct ui_file *stream, int show, int level,
 		    const struct type_print_options *flags)
 {
-  fprintf_filtered (stream, "\n%*scase %s is", level + 4, "",
-		    ada_variant_discrim_name
-		    (TYPE_FIELD_TYPE (type, field_num)));
+  const char *variant
+    = ada_variant_discrim_name (TYPE_FIELD_TYPE (type, field_num));
+  if (*variant == '\0')
+    variant = "?";
+
+  fprintf_filtered (stream, "\n%*scase %s is", level + 4, "", variant);
   print_variant_clauses (type, field_num, outer_type, stream, show,
 			 level + 4, flags);
   fprintf_filtered (stream, "\n%*send case;", level + 4, "");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 2d45592..c2481a6 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,13 @@
 2019-12-04  Tom Tromey  <tromey@adacore.com>
 
+	* gdb.ada/unchecked_union.exp: New file.
+	* gdb.ada/unchecked_union/pck.adb: New file.
+	* gdb.ada/unchecked_union/pck.ads: New file.
+	* gdb.ada/unchecked_union/unchecked_union.adb: New file.
+	* gdb-utils.exp (string_to_regexp): Also quote "?".
+
+2019-12-04  Tom Tromey  <tromey@adacore.com>
+
 	* gdb.base/endianity.c (struct other) <x>: New field.
 	(main): Initialize it.
 	* gdb.base/endianity.exp: Update.
diff --git a/gdb/testsuite/gdb.ada/unchecked_union.exp b/gdb/testsuite/gdb.ada/unchecked_union.exp
new file mode 100644
index 0000000..e522238
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/unchecked_union.exp
@@ -0,0 +1,58 @@
+# Copyright 2019 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# 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 ptype of an unchecked union.
+
+load_lib "ada.exp"
+
+standard_ada_testfile unchecked_union
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} {
+  return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "BREAK" ${testdir}/unchecked_union.adb]
+runto "unchecked_union.adb:$bp_location"
+
+proc multi_line_string {str} {
+    set result {}
+    foreach line [split $str \n] {
+	lappend result [string_to_regexp $line]
+    }
+    return [eval multi_line $result]
+}
+
+set inner_string {    case ? is
+        when ? =>
+            small: range 0 .. 255;
+        when ? =>
+            large: range 255 .. 510;
+    end case;
+}
+set inner_full "type = record (?) is\n${inner_string}end record"
+
+set pair_string {    case ? is
+        when ? =>
+            field_one: range 0 .. 255;
+        when ? =>
+            field_two: range 255 .. 510;
+    end case;
+}
+set pair_full "type = record\n${inner_string}${pair_string}end record"
+
+gdb_test "ptype Pair" [multi_line_string $pair_full]
+gdb_test "ptype Inner" [multi_line_string $inner_full]
diff --git a/gdb/testsuite/gdb.ada/unchecked_union/pck.adb b/gdb/testsuite/gdb.ada/unchecked_union/pck.adb
new file mode 100644
index 0000000..6535991
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/unchecked_union/pck.adb
@@ -0,0 +1,21 @@
+--  Copyright 2019 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package body Pck is
+   procedure Do_Nothing (A : System.Address) is
+   begin
+      null;
+   end Do_Nothing;
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/unchecked_union/pck.ads b/gdb/testsuite/gdb.ada/unchecked_union/pck.ads
new file mode 100644
index 0000000..b8d0010
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/unchecked_union/pck.ads
@@ -0,0 +1,19 @@
+--  Copyright 2019 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+with System;
+package Pck is
+   procedure Do_Nothing (A : System.Address);
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/unchecked_union/unchecked_union.adb b/gdb/testsuite/gdb.ada/unchecked_union/unchecked_union.adb
new file mode 100644
index 0000000..d6de66d
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/unchecked_union/unchecked_union.adb
@@ -0,0 +1,51 @@
+--  Copyright 2019 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+with System;
+with Pck; use Pck;
+
+procedure Foo is
+   type Key is (Alpha, Omega);
+
+   type Inner(Disc : Key := Omega) is record
+      case Disc is
+         when Alpha =>
+            Small : Integer range 0..255;
+         when others =>
+            Large : Integer range 255..510;
+      end case;
+   end record;
+   pragma Unchecked_Union (Inner);
+
+   type Outer(Disc : Key := Alpha) is record
+      case Disc is
+         when Alpha =>
+            Field_One : Integer range 0..255;
+         when others =>
+            Field_Two : Integer range 255..510;
+      end case;
+   end record;
+   pragma Unchecked_Union (Outer);
+
+   type Pair is record
+      Pone : Inner;
+      Ptwo : Outer;
+   end record;
+
+   Value : Pair;
+
+begin
+   Do_Nothing (Value'Address);          -- BREAK
+end Foo;
diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
index 95ca348..17c1adf 100644
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -34,7 +34,7 @@
 
 proc string_to_regexp {str} {
     set result $str
-    regsub -all {[]*+.|(){}^$\[\\]} $str {\\&} result
+    regsub -all {[]?*+.|(){}^$\[\\]} $str {\\&} result
     return $result
 }
 

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I3403040780a155ffa2c44c8e6a04ba86bc810e29
Gerrit-Change-Number: 740
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: newchange

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

* [review] Normalize Ada ptype to use a single "?"
  2019-12-04 22:19 [review] Normalize Ada ptype to use a single "?" Tom Tromey (Code Review)
@ 2019-12-08  0:40 ` Joel Brobecker (Code Review)
  2019-12-10 15:59 ` [pushed] " Sourceware to Gerrit sync (Code Review)
  2019-12-10 15:59 ` Sourceware to Gerrit sync (Code Review)
  2 siblings, 0 replies; 4+ messages in thread
From: Joel Brobecker (Code Review) @ 2019-12-08  0:40 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

Joel Brobecker has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/740
......................................................................


Patch Set 1: Code-Review+2


-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I3403040780a155ffa2c44c8e6a04ba86bc810e29
Gerrit-Change-Number: 740
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Joel Brobecker <brobecker@adacore.com>
Gerrit-Comment-Date: Sun, 08 Dec 2019 00:40:07 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

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

* [pushed] Normalize Ada ptype to use a single "?"
  2019-12-04 22:19 [review] Normalize Ada ptype to use a single "?" Tom Tromey (Code Review)
  2019-12-08  0:40 ` Joel Brobecker (Code Review)
  2019-12-10 15:59 ` [pushed] " Sourceware to Gerrit sync (Code Review)
@ 2019-12-10 15:59 ` Sourceware to Gerrit sync (Code Review)
  2 siblings, 0 replies; 4+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-12-10 15:59 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches; +Cc: Joel Brobecker

Sourceware to Gerrit sync has submitted this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/740
......................................................................

Normalize Ada ptype to use a single "?"

Sometimes -- notably with unchecked unions -- the Ada "ptype" code
will print a "?" or "??" to indicate something unknown.  The choice of
what was printed was somewhat arbitrary, and in one case, Ada would
print an empty string rather than "?".

This patch normalizes the Ada code to use "?" rather than an empty
string or "??".  My reasoning here is that a single question mark is
enough to convey unknown-ness.

gdb/ChangeLog
2019-12-10  Tom Tromey  <tromey@adacore.com>

	* ada-typeprint.c (print_choices): Use a single "?".
	(print_variant_part): Print "?" if the discriminant name
	is not known.

gdb/testsuite/ChangeLog
2019-12-10  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/unchecked_union.exp: New file.
	* gdb.ada/unchecked_union/pck.adb: New file.
	* gdb.ada/unchecked_union/pck.ads: New file.
	* gdb.ada/unchecked_union/unchecked_union.adb: New file.
	* gdb-utils.exp (string_to_regexp): Also quote "?".

Change-Id: I3403040780a155ffa2c44c8e6a04ba86bc810e29
---
M gdb/ChangeLog
M gdb/ada-typeprint.c
M gdb/testsuite/ChangeLog
A gdb/testsuite/gdb.ada/unchecked_union.exp
A gdb/testsuite/gdb.ada/unchecked_union/pck.adb
A gdb/testsuite/gdb.ada/unchecked_union/pck.ads
A gdb/testsuite/gdb.ada/unchecked_union/unchecked_union.adb
M gdb/testsuite/lib/gdb-utils.exp
8 files changed, 171 insertions(+), 5 deletions(-)


diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 98a6285..ac58517 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-10  Tom Tromey  <tromey@adacore.com>
+
+	* ada-typeprint.c (print_choices): Use a single "?".
+	(print_variant_part): Print "?" if the discriminant name
+	is not known.
+
 2019-12-10  George Barrett  <bob@bob131.so>
 
 	Fix scripted probe breakpoints.
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index f89dd23..70fad1c 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -526,7 +526,7 @@
     }
 
 Huh:
-  fprintf_filtered (stream, "?? =>");
+  fprintf_filtered (stream, "? =>");
   return 0;
 }
 
@@ -592,9 +592,12 @@
 		    struct ui_file *stream, int show, int level,
 		    const struct type_print_options *flags)
 {
-  fprintf_filtered (stream, "\n%*scase %s is", level + 4, "",
-		    ada_variant_discrim_name
-		    (TYPE_FIELD_TYPE (type, field_num)));
+  const char *variant
+    = ada_variant_discrim_name (TYPE_FIELD_TYPE (type, field_num));
+  if (*variant == '\0')
+    variant = "?";
+
+  fprintf_filtered (stream, "\n%*scase %s is", level + 4, "", variant);
   print_variant_clauses (type, field_num, outer_type, stream, show,
 			 level + 4, flags);
   fprintf_filtered (stream, "\n%*send case;", level + 4, "");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index c14c341..52edbc1 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2019-12-10  Tom Tromey  <tromey@adacore.com>
+
+	* gdb.ada/unchecked_union.exp: New file.
+	* gdb.ada/unchecked_union/pck.adb: New file.
+	* gdb.ada/unchecked_union/pck.ads: New file.
+	* gdb.ada/unchecked_union/unchecked_union.adb: New file.
+	* gdb-utils.exp (string_to_regexp): Also quote "?".
+
 2019-12-10  George Barrett  <bob@bob131.so>
 
 	Test scripted probe breakpoints.
diff --git a/gdb/testsuite/gdb.ada/unchecked_union.exp b/gdb/testsuite/gdb.ada/unchecked_union.exp
new file mode 100644
index 0000000..e522238
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/unchecked_union.exp
@@ -0,0 +1,58 @@
+# Copyright 2019 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# 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 ptype of an unchecked union.
+
+load_lib "ada.exp"
+
+standard_ada_testfile unchecked_union
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} {
+  return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "BREAK" ${testdir}/unchecked_union.adb]
+runto "unchecked_union.adb:$bp_location"
+
+proc multi_line_string {str} {
+    set result {}
+    foreach line [split $str \n] {
+	lappend result [string_to_regexp $line]
+    }
+    return [eval multi_line $result]
+}
+
+set inner_string {    case ? is
+        when ? =>
+            small: range 0 .. 255;
+        when ? =>
+            large: range 255 .. 510;
+    end case;
+}
+set inner_full "type = record (?) is\n${inner_string}end record"
+
+set pair_string {    case ? is
+        when ? =>
+            field_one: range 0 .. 255;
+        when ? =>
+            field_two: range 255 .. 510;
+    end case;
+}
+set pair_full "type = record\n${inner_string}${pair_string}end record"
+
+gdb_test "ptype Pair" [multi_line_string $pair_full]
+gdb_test "ptype Inner" [multi_line_string $inner_full]
diff --git a/gdb/testsuite/gdb.ada/unchecked_union/pck.adb b/gdb/testsuite/gdb.ada/unchecked_union/pck.adb
new file mode 100644
index 0000000..6535991
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/unchecked_union/pck.adb
@@ -0,0 +1,21 @@
+--  Copyright 2019 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package body Pck is
+   procedure Do_Nothing (A : System.Address) is
+   begin
+      null;
+   end Do_Nothing;
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/unchecked_union/pck.ads b/gdb/testsuite/gdb.ada/unchecked_union/pck.ads
new file mode 100644
index 0000000..b8d0010
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/unchecked_union/pck.ads
@@ -0,0 +1,19 @@
+--  Copyright 2019 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+with System;
+package Pck is
+   procedure Do_Nothing (A : System.Address);
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/unchecked_union/unchecked_union.adb b/gdb/testsuite/gdb.ada/unchecked_union/unchecked_union.adb
new file mode 100644
index 0000000..d6de66d
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/unchecked_union/unchecked_union.adb
@@ -0,0 +1,51 @@
+--  Copyright 2019 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+with System;
+with Pck; use Pck;
+
+procedure Foo is
+   type Key is (Alpha, Omega);
+
+   type Inner(Disc : Key := Omega) is record
+      case Disc is
+         when Alpha =>
+            Small : Integer range 0..255;
+         when others =>
+            Large : Integer range 255..510;
+      end case;
+   end record;
+   pragma Unchecked_Union (Inner);
+
+   type Outer(Disc : Key := Alpha) is record
+      case Disc is
+         when Alpha =>
+            Field_One : Integer range 0..255;
+         when others =>
+            Field_Two : Integer range 255..510;
+      end case;
+   end record;
+   pragma Unchecked_Union (Outer);
+
+   type Pair is record
+      Pone : Inner;
+      Ptwo : Outer;
+   end record;
+
+   Value : Pair;
+
+begin
+   Do_Nothing (Value'Address);          -- BREAK
+end Foo;
diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
index 95ca348..17c1adf 100644
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -34,7 +34,7 @@
 
 proc string_to_regexp {str} {
     set result $str
-    regsub -all {[]*+.|(){}^$\[\\]} $str {\\&} result
+    regsub -all {[]?*+.|(){}^$\[\\]} $str {\\&} result
     return $result
 }
 

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I3403040780a155ffa2c44c8e6a04ba86bc810e29
Gerrit-Change-Number: 740
Gerrit-PatchSet: 2
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Joel Brobecker <brobecker@adacore.com>
Gerrit-MessageType: merged

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

* [pushed] Normalize Ada ptype to use a single "?"
  2019-12-04 22:19 [review] Normalize Ada ptype to use a single "?" Tom Tromey (Code Review)
  2019-12-08  0:40 ` Joel Brobecker (Code Review)
@ 2019-12-10 15:59 ` Sourceware to Gerrit sync (Code Review)
  2019-12-10 15:59 ` Sourceware to Gerrit sync (Code Review)
  2 siblings, 0 replies; 4+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-12-10 15:59 UTC (permalink / raw)
  To: Tom Tromey, Joel Brobecker, gdb-patches

The original change was created by Tom Tromey.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/740
......................................................................

Normalize Ada ptype to use a single "?"

Sometimes -- notably with unchecked unions -- the Ada "ptype" code
will print a "?" or "??" to indicate something unknown.  The choice of
what was printed was somewhat arbitrary, and in one case, Ada would
print an empty string rather than "?".

This patch normalizes the Ada code to use "?" rather than an empty
string or "??".  My reasoning here is that a single question mark is
enough to convey unknown-ness.

gdb/ChangeLog
2019-12-10  Tom Tromey  <tromey@adacore.com>

	* ada-typeprint.c (print_choices): Use a single "?".
	(print_variant_part): Print "?" if the discriminant name
	is not known.

gdb/testsuite/ChangeLog
2019-12-10  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/unchecked_union.exp: New file.
	* gdb.ada/unchecked_union/pck.adb: New file.
	* gdb.ada/unchecked_union/pck.ads: New file.
	* gdb.ada/unchecked_union/unchecked_union.adb: New file.
	* gdb-utils.exp (string_to_regexp): Also quote "?".

Change-Id: I3403040780a155ffa2c44c8e6a04ba86bc810e29
---
M gdb/ChangeLog
M gdb/ada-typeprint.c
M gdb/testsuite/ChangeLog
A gdb/testsuite/gdb.ada/unchecked_union.exp
A gdb/testsuite/gdb.ada/unchecked_union/pck.adb
A gdb/testsuite/gdb.ada/unchecked_union/pck.ads
A gdb/testsuite/gdb.ada/unchecked_union/unchecked_union.adb
M gdb/testsuite/lib/gdb-utils.exp
8 files changed, 171 insertions(+), 5 deletions(-)



diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 98a6285..ac58517 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-10  Tom Tromey  <tromey@adacore.com>
+
+	* ada-typeprint.c (print_choices): Use a single "?".
+	(print_variant_part): Print "?" if the discriminant name
+	is not known.
+
 2019-12-10  George Barrett  <bob@bob131.so>
 
 	Fix scripted probe breakpoints.
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index f89dd23..70fad1c 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -526,7 +526,7 @@
     }
 
 Huh:
-  fprintf_filtered (stream, "?? =>");
+  fprintf_filtered (stream, "? =>");
   return 0;
 }
 
@@ -592,9 +592,12 @@
 		    struct ui_file *stream, int show, int level,
 		    const struct type_print_options *flags)
 {
-  fprintf_filtered (stream, "\n%*scase %s is", level + 4, "",
-		    ada_variant_discrim_name
-		    (TYPE_FIELD_TYPE (type, field_num)));
+  const char *variant
+    = ada_variant_discrim_name (TYPE_FIELD_TYPE (type, field_num));
+  if (*variant == '\0')
+    variant = "?";
+
+  fprintf_filtered (stream, "\n%*scase %s is", level + 4, "", variant);
   print_variant_clauses (type, field_num, outer_type, stream, show,
 			 level + 4, flags);
   fprintf_filtered (stream, "\n%*send case;", level + 4, "");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index c14c341..52edbc1 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2019-12-10  Tom Tromey  <tromey@adacore.com>
+
+	* gdb.ada/unchecked_union.exp: New file.
+	* gdb.ada/unchecked_union/pck.adb: New file.
+	* gdb.ada/unchecked_union/pck.ads: New file.
+	* gdb.ada/unchecked_union/unchecked_union.adb: New file.
+	* gdb-utils.exp (string_to_regexp): Also quote "?".
+
 2019-12-10  George Barrett  <bob@bob131.so>
 
 	Test scripted probe breakpoints.
diff --git a/gdb/testsuite/gdb.ada/unchecked_union.exp b/gdb/testsuite/gdb.ada/unchecked_union.exp
new file mode 100644
index 0000000..e522238
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/unchecked_union.exp
@@ -0,0 +1,58 @@
+# Copyright 2019 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# 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 ptype of an unchecked union.
+
+load_lib "ada.exp"
+
+standard_ada_testfile unchecked_union
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} {
+  return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "BREAK" ${testdir}/unchecked_union.adb]
+runto "unchecked_union.adb:$bp_location"
+
+proc multi_line_string {str} {
+    set result {}
+    foreach line [split $str \n] {
+	lappend result [string_to_regexp $line]
+    }
+    return [eval multi_line $result]
+}
+
+set inner_string {    case ? is
+        when ? =>
+            small: range 0 .. 255;
+        when ? =>
+            large: range 255 .. 510;
+    end case;
+}
+set inner_full "type = record (?) is\n${inner_string}end record"
+
+set pair_string {    case ? is
+        when ? =>
+            field_one: range 0 .. 255;
+        when ? =>
+            field_two: range 255 .. 510;
+    end case;
+}
+set pair_full "type = record\n${inner_string}${pair_string}end record"
+
+gdb_test "ptype Pair" [multi_line_string $pair_full]
+gdb_test "ptype Inner" [multi_line_string $inner_full]
diff --git a/gdb/testsuite/gdb.ada/unchecked_union/pck.adb b/gdb/testsuite/gdb.ada/unchecked_union/pck.adb
new file mode 100644
index 0000000..6535991
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/unchecked_union/pck.adb
@@ -0,0 +1,21 @@
+--  Copyright 2019 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package body Pck is
+   procedure Do_Nothing (A : System.Address) is
+   begin
+      null;
+   end Do_Nothing;
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/unchecked_union/pck.ads b/gdb/testsuite/gdb.ada/unchecked_union/pck.ads
new file mode 100644
index 0000000..b8d0010
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/unchecked_union/pck.ads
@@ -0,0 +1,19 @@
+--  Copyright 2019 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+with System;
+package Pck is
+   procedure Do_Nothing (A : System.Address);
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/unchecked_union/unchecked_union.adb b/gdb/testsuite/gdb.ada/unchecked_union/unchecked_union.adb
new file mode 100644
index 0000000..d6de66d
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/unchecked_union/unchecked_union.adb
@@ -0,0 +1,51 @@
+--  Copyright 2019 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+with System;
+with Pck; use Pck;
+
+procedure Foo is
+   type Key is (Alpha, Omega);
+
+   type Inner(Disc : Key := Omega) is record
+      case Disc is
+         when Alpha =>
+            Small : Integer range 0..255;
+         when others =>
+            Large : Integer range 255..510;
+      end case;
+   end record;
+   pragma Unchecked_Union (Inner);
+
+   type Outer(Disc : Key := Alpha) is record
+      case Disc is
+         when Alpha =>
+            Field_One : Integer range 0..255;
+         when others =>
+            Field_Two : Integer range 255..510;
+      end case;
+   end record;
+   pragma Unchecked_Union (Outer);
+
+   type Pair is record
+      Pone : Inner;
+      Ptwo : Outer;
+   end record;
+
+   Value : Pair;
+
+begin
+   Do_Nothing (Value'Address);          -- BREAK
+end Foo;
diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
index 95ca348..17c1adf 100644
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -34,7 +34,7 @@
 
 proc string_to_regexp {str} {
     set result $str
-    regsub -all {[]*+.|(){}^$\[\\]} $str {\\&} result
+    regsub -all {[]?*+.|(){}^$\[\\]} $str {\\&} result
     return $result
 }
 

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I3403040780a155ffa2c44c8e6a04ba86bc810e29
Gerrit-Change-Number: 740
Gerrit-PatchSet: 2
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Joel Brobecker <brobecker@adacore.com>
Gerrit-MessageType: newpatchset

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

end of thread, other threads:[~2019-12-10 15:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-04 22:19 [review] Normalize Ada ptype to use a single "?" Tom Tromey (Code Review)
2019-12-08  0:40 ` Joel Brobecker (Code Review)
2019-12-10 15:59 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-12-10 15:59 ` Sourceware to Gerrit sync (Code Review)

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).