aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2021-01-25 07:38:21 -0700
committerTom Tromey <tromey@adacore.com>2021-01-25 07:38:21 -0700
commit191849105b95e5ac3a3173547fd77f7b1fc3b283 (patch)
treeb0bbfb1aff7d6e137db82311e09c63d2114f8947
parentacd6125f01dc9ba76423b7062c26ca16562943cf (diff)
downloadbinutils-191849105b95e5ac3a3173547fd77f7b1fc3b283.zip
binutils-191849105b95e5ac3a3173547fd77f7b1fc3b283.tar.gz
binutils-191849105b95e5ac3a3173547fd77f7b1fc3b283.tar.bz2
Specially handle array contexts in Ada expression resolution
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-25 Tom Tromey <tromey@adacore.com> * ada-lang.c (resolve_subexp): Handle array context. gdb/testsuite/ChangeLog 2021-01-25 Tom Tromey <tromey@adacore.com> * gdb.ada/local-enum.exp: Add enumerator resolution test.
-rw-r--r--gdb/ChangeLog4
-rw-r--r--gdb/ada-lang.c22
-rw-r--r--gdb/testsuite/ChangeLog4
-rw-r--r--gdb/testsuite/gdb.ada/local-enum.exp5
4 files changed, 32 insertions, 3 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9f9681f..3a4844f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2021-01-25 Tom Tromey <tromey@adacore.com>
+
+ * ada-lang.c (resolve_subexp): Handle array context.
+
2021-01-23 Tom Tromey <tom@tromey.com>
PR compile/25575
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e2befe1..8d91240 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/ChangeLog b/gdb/testsuite/ChangeLog
index 5789500..7fa1074 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2021-01-25 Tom Tromey <tromey@adacore.com>
+ * gdb.ada/local-enum.exp: Add enumerator resolution test.
+
+2021-01-25 Tom Tromey <tromey@adacore.com>
+
* gdb.ada/local-enum.exp: New file.
* gdb.ada/local-enum/local.adb: New file.
diff --git a/gdb/testsuite/gdb.ada/local-enum.exp b/gdb/testsuite/gdb.ada/local-enum.exp
index 32daf9a..fc49bca 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"