public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Add another case to Ada expression resolution
@ 2021-01-22 21:10 Tom Tromey
  2021-01-22 21:10 ` [PATCH 1/2] Add test case for symbol menu for local enumerators Tom Tromey
  2021-01-22 21:10 ` [PATCH 2/2] Specially handle array contexts in Ada expression resolution Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Tom Tromey @ 2021-01-22 21:10 UTC (permalink / raw)
  To: gdb-patches

This series adds a new test case to cover an Ada scenario that isn't
currently tested.  Then, it adds a new feature to Ada expression
resolution, updating the new test to account for this.

Tom



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

* [PATCH 1/2] Add test case for symbol menu for local enumerators
  2021-01-22 21:10 [PATCH 0/2] Add another case to Ada expression resolution Tom Tromey
@ 2021-01-22 21:10 ` Tom Tromey
  2021-01-25  7:55   ` Joel Brobecker
  2021-01-22 21:10 ` [PATCH 2/2] Specially handle array contexts in Ada expression resolution Tom Tromey
  1 sibling, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2021-01-22 21:10 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Ada will normally present a menu to the user to allow manual
disambiguation of symbols.  The AdaCore internal GDB had a bug that
prevented this from happening.  Although this bug is not in the FSF
GDB, it seemed worthwhile to write a test case to ensure this.

gdb/testsuite/ChangeLog
2021-01-22  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/local-enum.exp: New file.
	* gdb.ada/local-enum/local.adb: New file.
---
 gdb/testsuite/ChangeLog                    |  5 ++
 gdb/testsuite/gdb.ada/local-enum.exp       | 83 ++++++++++++++++++++++
 gdb/testsuite/gdb.ada/local-enum/local.adb | 28 ++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 gdb/testsuite/gdb.ada/local-enum.exp
 create mode 100644 gdb/testsuite/gdb.ada/local-enum/local.adb

diff --git a/gdb/testsuite/gdb.ada/local-enum.exp b/gdb/testsuite/gdb.ada/local-enum.exp
new file mode 100644
index 00000000000..32daf9a0d96
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/local-enum.exp
@@ -0,0 +1,83 @@
+# Copyright 2021 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"
+
+if { [skip_ada_tests] } { return -1 }
+
+standard_ada_testfile local
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable debug] != ""} {
+  return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "STOP" ${testdir}/local.adb]
+if ![runto "local.adb:$bp_location" ] then {
+  perror "Couldn't run ${testfile}"
+  return
+}
+
+# The test has two constants named 'three', with different values.
+# This prints one of them and checks the value.  WHICH_ENUM is the
+# name of the enum, either "e1" or "e2".
+proc print_three {which_enum value} {
+    # We don't know which in order gdb will print the constants, so
+    # adapt to either.
+    set menu1 [multi_line \
+		   "Multiple matches for three" \
+		   "\\\[0\\\] cancel" \
+		   "\\\[1\\\] local\\.e2'\\(three\\) \\(enumeral\\)" \
+		   "\\\[2\\\] local\\.e1'\\(three\\) \\(enumeral\\)" \
+		   "> $"]
+    set menu2 [multi_line \
+		   "Multiple matches for three" \
+		   "\\\[0\\\] cancel" \
+		   "\\\[1\\\] local\\.e1'\\(three\\) \\(enumeral\\)" \
+		   "\\\[2\\\] local\\.e2'\\(three\\) \\(enumeral\\)" \
+		   "> $"]
+
+    set index -1
+    set test_name "menu for test index $which_enum"
+    gdb_test_multiple "print/d three" $test_name {
+	-re $menu1 {
+	    pass $test_name
+	    if {$which_enum == "e1"} {
+		set index 2
+	    } else {
+		set index 1
+	    }
+	}
+	-re $menu2 {
+	    pass $test_name
+	    if {$which_enum == "e1"} {
+		set index 1
+	    } else {
+		set index 2
+	    }
+	}
+	default {
+	    fail $test_name
+	}
+    }
+
+    if {$index != -1} {
+	gdb_test $index " = $value"
+    }
+}
+
+print_three e2 0
+print_three e1 2
diff --git a/gdb/testsuite/gdb.ada/local-enum/local.adb b/gdb/testsuite/gdb.ada/local-enum/local.adb
new file mode 100644
index 00000000000..9fafbb151fa
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/local-enum/local.adb
@@ -0,0 +1,28 @@
+--  Copyright 2021 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/>.
+
+procedure Local is
+  type E1 is (one, two, three);
+  type E2 is (three, four, five);
+
+  type A1 is array (E1) of Integer;
+  type A2 is array (E2) of Integer;
+
+  V1 : A1 := (0, 1, 2);
+  V2 : A2 := (3, 4, 5);
+
+begin
+  null; -- STOP
+end Local;
-- 
2.26.2


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

* [PATCH 2/2] Specially handle array contexts in Ada expression resolution
  2021-01-22 21:10 [PATCH 0/2] Add another case to Ada expression resolution Tom Tromey
  2021-01-22 21:10 ` [PATCH 1/2] Add test case for symbol menu for local enumerators Tom Tromey
@ 2021-01-22 21:10 ` Tom Tromey
  2021-01-25  7:57   ` Joel Brobecker
  1 sibling, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2021-01-22 21:10 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

A user noticed that the Ada expression code in gdb did not
automatically disambiguate an enumerator in an array context.  That
is, an expression like "print array(enumerator)" is not ambiguous,
even if "enumerator" is declared in multiple enumerations, because the
correct one can be found by examining the array's index type.

This patch changes the Ada expression resolution code to handle this
case.

gdb/ChangeLog
2021-01-22  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (resolve_subexp): Handle array context.

gdb/testsuite/ChangeLog
2021-01-22  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/local-enum.exp: Add enumerator resolution test.
---
 gdb/ChangeLog                        |  4 ++++
 gdb/ada-lang.c                       | 22 +++++++++++++++++++---
 gdb/testsuite/ChangeLog              |  4 ++++
 gdb/testsuite/gdb.ada/local-enum.exp |  5 +++++
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e2befe1d82e..8d912402462 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -3474,6 +3474,12 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
   struct value **argvec;        /* Vector of operand types (alloca'ed).  */
   int nargs;                    /* Number of operands.  */
   int oplen;
+  /* If we're resolving an expression like ARRAY(ARG...), then we set
+     this to the type of the array, so we can use the index types as
+     the expected types for resolution.  */
+  struct type *array_type = nullptr;
+  /* The arity of ARRAY_TYPE.  */
+  int array_arity = 0;
 
   argvec = NULL;
   nargs = 0;
@@ -3490,7 +3496,12 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
       else
 	{
 	  *pos += 3;
-	  resolve_subexp (expp, pos, 0, NULL, parse_completion, tracker);
+	  struct value *lhs = resolve_subexp (expp, pos, 0, NULL,
+					      parse_completion, tracker);
+	  struct type *lhstype = ada_check_typedef (value_type (lhs));
+	  array_arity = ada_array_arity (lhstype);
+	  if (array_arity > 0)
+	    array_type = lhstype;
 	}
       nargs = longest_to_int (exp->elts[pc + 1].longconst);
       break;
@@ -3627,8 +3638,13 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
 
   argvec = XALLOCAVEC (struct value *, nargs + 1);
   for (i = 0; i < nargs; i += 1)
-    argvec[i] = resolve_subexp (expp, pos, 1, NULL, parse_completion,
-				tracker);
+    {
+      struct type *subtype = nullptr;
+      if (i < array_arity)
+	subtype = ada_index_type (array_type, i + 1, "array type");
+      argvec[i] = resolve_subexp (expp, pos, 1, subtype, parse_completion,
+				  tracker);
+    }
   argvec[i] = NULL;
   exp = expp->get ();
 
diff --git a/gdb/testsuite/gdb.ada/local-enum.exp b/gdb/testsuite/gdb.ada/local-enum.exp
index 32daf9a0d96..fc49bca1308 100644
--- a/gdb/testsuite/gdb.ada/local-enum.exp
+++ b/gdb/testsuite/gdb.ada/local-enum.exp
@@ -81,3 +81,8 @@ proc print_three {which_enum value} {
 
 print_three e2 0
 print_three e1 2
+
+# These will not result in a menu, as expression resolution should
+# disambiguate the meaning of 'three'.
+gdb_test "print v1(three)" " = 2" "print v1 element"
+gdb_test "print v2(three)" " = 3" "print v2 element"
-- 
2.26.2


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

* Re: [PATCH 1/2] Add test case for symbol menu for local enumerators
  2021-01-22 21:10 ` [PATCH 1/2] Add test case for symbol menu for local enumerators Tom Tromey
@ 2021-01-25  7:55   ` Joel Brobecker
  0 siblings, 0 replies; 5+ messages in thread
From: Joel Brobecker @ 2021-01-25  7:55 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Hi Tom,

> Ada will normally present a menu to the user to allow manual
> disambiguation of symbols.  The AdaCore internal GDB had a bug that
> prevented this from happening.  Although this bug is not in the FSF
> GDB, it seemed worthwhile to write a test case to ensure this.
> 
> gdb/testsuite/ChangeLog
> 2021-01-22  Tom Tromey  <tromey@adacore.com>
> 
> 	* gdb.ada/local-enum.exp: New file.
> 	* gdb.ada/local-enum/local.adb: New file.

This patch looks good to me.

Thank you for submitting it :).

-- 
Joel

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

* Re: [PATCH 2/2] Specially handle array contexts in Ada expression resolution
  2021-01-22 21:10 ` [PATCH 2/2] Specially handle array contexts in Ada expression resolution Tom Tromey
@ 2021-01-25  7:57   ` Joel Brobecker
  0 siblings, 0 replies; 5+ messages in thread
From: Joel Brobecker @ 2021-01-25  7:57 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Hi Tom,

> gdb/ChangeLog
> 2021-01-22  Tom Tromey  <tromey@adacore.com>
> 
> 	* ada-lang.c (resolve_subexp): Handle array context.
> 
> gdb/testsuite/ChangeLog
> 2021-01-22  Tom Tromey  <tromey@adacore.com>
> 
> 	* gdb.ada/local-enum.exp: Add enumerator resolution test.

Looks good to me as well. Thank you Tom.

-- 
Joel

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

end of thread, other threads:[~2021-01-25  7:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-22 21:10 [PATCH 0/2] Add another case to Ada expression resolution Tom Tromey
2021-01-22 21:10 ` [PATCH 1/2] Add test case for symbol menu for local enumerators Tom Tromey
2021-01-25  7:55   ` Joel Brobecker
2021-01-22 21:10 ` [PATCH 2/2] Specially handle array contexts in Ada expression resolution Tom Tromey
2021-01-25  7:57   ` Joel Brobecker

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