aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2020-04-06 12:59:57 -0600
committerTom Tromey <tromey@adacore.com>2020-04-06 12:59:57 -0600
commit6ee448cc2d0b9337713ecb6bb2e6305b4f504cbc (patch)
treebc6c280d5cb3ad650f3c93b7a5c2455cf66583c7
parentdea34e8cc336a80546dac21463583a76e3e5d473 (diff)
downloadfsf-binutils-gdb-6ee448cc2d0b9337713ecb6bb2e6305b4f504cbc.zip
fsf-binutils-gdb-6ee448cc2d0b9337713ecb6bb2e6305b4f504cbc.tar.gz
fsf-binutils-gdb-6ee448cc2d0b9337713ecb6bb2e6305b4f504cbc.tar.bz2
Select variant field when printing variant
When I updated the Ada variant-printing code to be value-based, I neglected a couple of issues. First, print_variant_part must first extract the variant field before finding the active component; second, print_field_values should pass in the field value as the outer value when recursing. This patch fixes both of these issues. gdb/ChangeLog 2020-04-06 Tom Tromey <tromey@adacore.com> * ada-valprint.c (print_variant_part): Extract the variant field. (print_field_values): Use the field as the outer value when recursing. gdb/testsuite/ChangeLog 2020-04-06 Tom Tromey <tromey@adacore.com> * gdb.ada/variant-record/proc.adb: New file. * gdb.ada/variant-record/value.adb: New file. * gdb.ada/variant-record/value.s: New file. * gdb.ada/variant-record.exp: New file.
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/ada-valprint.c6
-rw-r--r--gdb/testsuite/ChangeLog7
-rw-r--r--gdb/testsuite/gdb.ada/variant-record.exp30
-rw-r--r--gdb/testsuite/gdb.ada/variant-record/proc.adb21
-rw-r--r--gdb/testsuite/gdb.ada/variant-record/value.adb30
-rw-r--r--gdb/testsuite/gdb.ada/variant-record/value.ads48
7 files changed, 146 insertions, 2 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f742c1f..94fbdbd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2020-04-06 Tom Tromey <tromey@adacore.com>
+ * ada-valprint.c (print_variant_part): Extract the variant field.
+ (print_field_values): Use the field as the outer value when
+ recursing.
+
+2020-04-06 Tom Tromey <tromey@adacore.com>
+
* sh-nbsd-tdep.c: Include nbsd-tdep.h.
* ppc-nbsd-tdep.c: Include nbsd-tdep.h.
* mips-nbsd-tdep.c (mipsnbsd_init_abi): Add missing ";".
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 2f2375a..2768829 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -565,7 +565,8 @@ print_variant_part (struct value *value, int field_num,
if (which < 0)
return 0;
- struct value *active_component = value_field (value, which);
+ struct value *variant_field = value_field (value, field_num);
+ struct value *active_component = value_field (variant_field, which);
return print_field_values (active_component, outer_value, stream, recurse,
options, comma_needed, language);
}
@@ -603,8 +604,9 @@ print_field_values (struct value *value, struct value *outer_value,
if (ada_is_wrapper_field (type, i))
{
+ struct value *field_val = value_field (value, i);
comma_needed =
- print_field_values (value_field (value, i), outer_value,
+ print_field_values (field_val, field_val,
stream, recurse, options,
comma_needed, language);
continue;
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 226a070..8701593 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2020-04-06 Tom Tromey <tromey@adacore.com>
+
+ * gdb.ada/variant-record/proc.adb: New file.
+ * gdb.ada/variant-record/value.adb: New file.
+ * gdb.ada/variant-record/value.s: New file.
+ * gdb.ada/variant-record.exp: New file.
+
2020-04-03 Hannes Domani <ssbssa@yahoo.de>
PR gdb/25325
diff --git a/gdb/testsuite/gdb.ada/variant-record.exp b/gdb/testsuite/gdb.ada/variant-record.exp
new file mode 100644
index 0000000..82b73c6
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/variant-record.exp
@@ -0,0 +1,30 @@
+# Copyright 2020 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/>.
+
+load_lib "ada.exp"
+
+standard_ada_testfile proc
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable debug] != ""} {
+ return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "STOP" ${testdir}/proc.adb]
+runto "proc.adb:$bp_location"
+
+gdb_test "print Value.Name(My_Value)" \
+ "= \\(well => yes, name => \"abcdefgh\"\\)"
diff --git a/gdb/testsuite/gdb.ada/variant-record/proc.adb b/gdb/testsuite/gdb.ada/variant-record/proc.adb
new file mode 100644
index 0000000..4becfb3
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/variant-record/proc.adb
@@ -0,0 +1,21 @@
+-- Copyright 2020 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 Value;
+procedure Proc is
+ My_Value : Value.T := Value.Create;
+begin
+ null; -- STOP
+end;
diff --git a/gdb/testsuite/gdb.ada/variant-record/value.adb b/gdb/testsuite/gdb.ada/variant-record/value.adb
new file mode 100644
index 0000000..993483d
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/variant-record/value.adb
@@ -0,0 +1,30 @@
+-- Copyright 2020 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 Value is
+ function Create return T is
+ begin
+ return (One => (Well => Value_Name.No,
+ Unique_Name => (X1 => 1, X2 => 2)),
+ Two => (Well => Value_Name.Yes,
+ Name => "abcdefgh"));
+ end Create;
+
+ function Name (Of_Value : T) return Value_Name.T is
+ begin
+ return Of_Value.Two;
+ end Name;
+
+end Value;
diff --git a/gdb/testsuite/gdb.ada/variant-record/value.ads b/gdb/testsuite/gdb.ada/variant-record/value.ads
new file mode 100644
index 0000000..f2af7d0
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/variant-record/value.ads
@@ -0,0 +1,48 @@
+-- Copyright 2020 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 Value is
+ package Value_Name is
+ Length : constant Positive := 8;
+ subtype Name_T is String (1 .. Length);
+
+ type A_Record_T is
+ record
+ X1 : Natural;
+ X2 : Natural;
+ end record;
+
+ type Yes_No_T is (Yes, No);
+ type T (Well : Yes_No_T := Yes) is
+ record
+ case Well is
+ when Yes =>
+ Name : Name_T;
+ when No =>
+ Unique_Name : A_Record_T;
+ end case;
+ end record;
+ end;
+
+ type T is private;
+ function Create return T;
+ function Name (Of_Value : T) return Value_Name.T;
+private
+ type T is
+ record
+ One : Value_Name.T (Well => Value_Name.No);
+ Two : Value_Name.T (Well => Value_Name.Yes);
+ end record;
+end;