public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/ada] Move identical enums handling later
@ 2023-09-06 18:01 Tom de Vries
  2023-09-07 14:00 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2023-09-06 18:01 UTC (permalink / raw)
  To: gdb-patches

When running test-case gdb.ada/arr_acc_idx_w_gap.exp with target board
cc-with-dwz, I run into:
...
(gdb) print enum_with_gaps'enum_rep(lit3)^M
'Enum_Rep requires argument to have same type as enum^M
(gdb) FAIL: gdb.ada/arr_acc_idx_w_gap.exp: enum_rep
...

With target_board unix, we have instead:
...
(gdb) print enum_with_gaps'enum_rep(lit3)^M
$16 = 13^M
(gdb) PASS: gdb.ada/arr_acc_idx_w_gap.exp: enum_rep
...

Conversely, when I add this test to the test-case:
...
     gdb_test "print enum_with_gaps'enum_rep(lit3)" " = 13" \
 	"enum_rep"
+    gdb_test "print enum_subrange'enum_rep(lit3)" " = 13" \
+	"other enum_rep"
...
the extra test passes with target board cc-with-dwz, but fails with target
board unix.

The problem is here in remove_extra_symbols:
...
  if (symbols_are_identical_enums (syms))
    syms.resize (1);
...
where one of the two identical enums is picked before the enum_rep handling
can resolve lit3 to one of the two.

Fix this by moving the code to ada_resolve_variable.

Tested on x86_64-linux.

PR ada/30726
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30726
---
 gdb/ada-lang.c                              | 35 ++++++++++++---------
 gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp |  2 ++
 2 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index c0cc512bfa3..2e1b9664fdc 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -202,6 +202,8 @@ static struct type *ada_find_any_type (const char *name);
 static symbol_name_matcher_ftype *ada_get_symbol_name_matcher
   (const lookup_name_info &lookup_name);
 
+static int symbols_are_identical_enums
+  (const std::vector<struct block_symbol> &syms);
 \f
 
 /* The character set used for source files.  */
@@ -3875,6 +3877,24 @@ ada_resolve_variable (struct symbol *sym, const struct block *block,
 	   && context_type->code () == TYPE_CODE_ENUM)
     i = ada_resolve_enum (candidates, sym->linkage_name (), context_type,
 			  parse_completion);
+  else if (context_type == nullptr
+	   && symbols_are_identical_enums (candidates))
+    {
+      /* If all the remaining symbols are identical enumerals, then
+	 just keep the first one and discard the rest.
+
+	 Unlike what we did previously, we do not discard any entry
+	 unless they are ALL identical.  This is because the symbol
+	 comparison is not a strict comparison, but rather a practical
+	 comparison.  If all symbols are considered identical, then
+	 we can just go ahead and use the first one and discard the rest.
+	 But if we cannot reduce the list to a single element, we have
+	 to ask the user to disambiguate anyways.  And if we have to
+	 present a multiple-choice menu, it's less confusing if the list
+	 isn't missing some choices that were identical and yet distinct.  */
+      candidates.resize (1);
+      i = 0;
+    }
   else if (deprocedure_p && !is_nonfunction (candidates))
     {
       i = ada_resolve_function
@@ -5091,21 +5111,6 @@ remove_extra_symbols (std::vector<struct block_symbol> &syms)
       else
 	i += 1;
     }
-
-  /* If all the remaining symbols are identical enumerals, then
-     just keep the first one and discard the rest.
-
-     Unlike what we did previously, we do not discard any entry
-     unless they are ALL identical.  This is because the symbol
-     comparison is not a strict comparison, but rather a practical
-     comparison.  If all symbols are considered identical, then
-     we can just go ahead and use the first one and discard the rest.
-     But if we cannot reduce the list to a single element, we have
-     to ask the user to disambiguate anyways.  And if we have to
-     present a multiple-choice menu, it's less confusing if the list
-     isn't missing some choices that were identical and yet distinct.  */
-  if (symbols_are_identical_enums (syms))
-    syms.resize (1);
 }
 
 /* Given a type that corresponds to a renaming entity, use the type name
diff --git a/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp b/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp
index 4a1482b6d99..a98e9e1e2c3 100644
--- a/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp
+++ b/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp
@@ -69,6 +69,8 @@ foreach_with_prefix scenario {all minimal} {
 
     gdb_test "print enum_with_gaps'enum_rep(lit3)" " = 13" \
 	"enum_rep"
+    gdb_test "print enum_subrange'enum_rep(lit3)" " = 13" \
+	"other enum_rep"
     gdb_test "print enum_with_gaps'enum_val(21)" " = lit4" \
 	"enum_val"
 }

base-commit: 313b2841b8e9046ea658104988e01bedf6148d5f
-- 
2.35.3


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

* Re: [PATCH] [gdb/ada] Move identical enums handling later
  2023-09-06 18:01 [PATCH] [gdb/ada] Move identical enums handling later Tom de Vries
@ 2023-09-07 14:00 ` Tom Tromey
  2023-09-08  5:56   ` Tom de Vries
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2023-09-07 14:00 UTC (permalink / raw)
  To: Tom de Vries via Gdb-patches; +Cc: Tom de Vries

>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> The problem is here in remove_extra_symbols:
Tom> ...
Tom>   if (symbols_are_identical_enums (syms))
Tom>     syms.resize (1);
Tom> ...
Tom> where one of the two identical enums is picked before the enum_rep handling
Tom> can resolve lit3 to one of the two.

Tom> Fix this by moving the code to ada_resolve_variable.

Thank you.  It's hard to reason about this patch (like, maybe there
could be some code path that now misses the de-duplication), but given
that you tested it, I think it's ok.

Approved-By: Tom Tromey <tom@tromey.com>

Tom

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

* Re: [PATCH] [gdb/ada] Move identical enums handling later
  2023-09-07 14:00 ` Tom Tromey
@ 2023-09-08  5:56   ` Tom de Vries
  0 siblings, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2023-09-08  5:56 UTC (permalink / raw)
  To: Tom Tromey, Tom de Vries via Gdb-patches

On 9/7/23 16:00, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Tom> The problem is here in remove_extra_symbols:
> Tom> ...
> Tom>   if (symbols_are_identical_enums (syms))
> Tom>     syms.resize (1);
> Tom> ...
> Tom> where one of the two identical enums is picked before the enum_rep handling
> Tom> can resolve lit3 to one of the two.
> 
> Tom> Fix this by moving the code to ada_resolve_variable.
> 
> Thank you.  It's hard to reason about this patch (like, maybe there
> could be some code path that now misses the de-duplication),

True.

> but given
> that you tested it, I think it's ok.
> 

Thanks for the review, committed.

- Tom

> Approved-By: Tom Tromey <tom@tromey.com>
> 
> Tom


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

end of thread, other threads:[~2023-09-08  5:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-06 18:01 [PATCH] [gdb/ada] Move identical enums handling later Tom de Vries
2023-09-07 14:00 ` Tom Tromey
2023-09-08  5:56   ` Tom de Vries

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