* [PATCH] [gdb/ada] Extend type equivalence test in ada_resolve_enum
@ 2023-09-07 14:42 Tom de Vries
2023-09-07 14:42 ` [PATCH] [gdb/symtab] Fix gdb-index writing for .debug_types Tom de Vries
2023-09-07 18:36 ` [PATCH] [gdb/ada] Extend type equivalence test in ada_resolve_enum Tom Tromey
0 siblings, 2 replies; 4+ messages in thread
From: Tom de Vries @ 2023-09-07 14:42 UTC (permalink / raw)
To: gdb-patches
When running test-case gdb.ada/local-enum.exp with target board debug-types, I
run into:
...
(gdb) print v1(three)^M
No name 'three' in enumeration type 'local__e1'^M
(gdb) FAIL: gdb.ada/local-enum.exp: print v1 element
...
The array V1 is of type A1 which is an array with index type E1, containing
"three" as enumerator:
...
type E1 is (one, two, three);
type A1 is array (E1) of Integer;
V1 : A1 := (0, 1, 2);
...
There's also a type E2 that contains three as enumerator:
...
type E2 is (three, four, five);
...
When doing "print v1(three)", it's the job of ada_resolve_enum to resolve
"three" to type E1 rather than type E2.
When using target board debug-types, the enums E1 and E2 are replicated in the
.debug_types section, and consequently in ada_resolve_enum the type
equivalence check using a pointer comparison fails:
...
for (int i = 0; i < syms.size (); ++i)
{
/* We already know the name matches, so we're just looking for
an element of the correct enum type. */
if (ada_check_typedef (syms[i].symbol->type ()) == context_type)
return i;
}
...
Fix this by also trying a structural comparison using
ada_identical_enum_types_p.
Tested on x86_64-linux.
PR ada/29335
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29335
---
gdb/ada-lang.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index c0cc512bfa3..7b61cce9341 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -202,6 +202,7 @@ 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 ada_identical_enum_types_p (struct type *type1, struct type *type2);
\f
/* The character set used for source files. */
@@ -3799,11 +3800,24 @@ ada_resolve_enum (std::vector<struct block_symbol> &syms,
gdb_assert (context_type->code () == TYPE_CODE_ENUM);
context_type = ada_check_typedef (context_type);
+ /* We already know the name matches, so we're just looking for
+ an element of the correct enum type. */
+ struct type *type1 = context_type;
for (int i = 0; i < syms.size (); ++i)
{
- /* We already know the name matches, so we're just looking for
- an element of the correct enum type. */
- if (ada_check_typedef (syms[i].symbol->type ()) == context_type)
+ struct type *type2 = ada_check_typedef (syms[i].symbol->type ());
+ if (type1 == type2)
+ return i;
+ }
+
+ for (int i = 0; i < syms.size (); ++i)
+ {
+ struct type *type2 = ada_check_typedef (syms[i].symbol->type ());
+ if (type1->num_fields () != type2->num_fields ())
+ continue;
+ if (strcmp (type1->name (), type2->name ()) != 0)
+ continue;
+ if (ada_identical_enum_types_p (type1, type2))
return i;
}
base-commit: 4d944db22c351296bad0b54d6a1857ad1fbde575
--
2.35.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] [gdb/symtab] Fix gdb-index writing for .debug_types
2023-09-07 14:42 [PATCH] [gdb/ada] Extend type equivalence test in ada_resolve_enum Tom de Vries
@ 2023-09-07 14:42 ` Tom de Vries
2023-09-07 18:42 ` Tom Tromey
2023-09-07 18:36 ` [PATCH] [gdb/ada] Extend type equivalence test in ada_resolve_enum Tom Tromey
1 sibling, 1 reply; 4+ messages in thread
From: Tom de Vries @ 2023-09-07 14:42 UTC (permalink / raw)
To: gdb-patches
With test-case gdb.ada/same_enum.exp and target board dwarf4-gdb-index we run
into:
...
(gdb) print red^M
No definition of "red" in current context.^M
(gdb) FAIL: gdb.ada/same_enum.exp: print red
...
[ This is a regression since commit 844a72efbce ("Simplify gdb_index writing"),
so this is broken in gdb 12 and 13. ]
The easiest way to see what's going wrong is with readelf. We have in section
.gdb_index:
...
[7194] pck__red:
2 [static, variable]
3 [static, variable]
...
which points to the CUs 2 and 3 in the CU list (shown using "2" and "3"), but
should be pointing to the TUs 2 and 3 in the TU list (shown using "T2" and
"T3").
Fix this by removing the counter / types_counter distinction in
write_gdbindex, such that we get the expected:
...
[7194] pck__red:
T2 [static, variable]
T3 [static, variable]
...
[ While reading write_gdbindex I noticed a few oddities related to dwz
handling, I've filed PR30829 about this. ]
Tested on x86_64-linux.
PR symtab/30827
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30827
---
gdb/dwarf2/index-write.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index e178bb067a9..11f254e263a 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1201,18 +1201,14 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table,
data_buf types_cu_list;
/* The CU list is already sorted, so we don't need to do additional
- work here. Also, the debug_types entries do not appear in
- all_units, but only in their own hash table. */
+ work here. */
int counter = 0;
- int types_counter = 0;
for (int i = 0; i < per_bfd->all_units.size (); ++i)
{
dwarf2_per_cu_data *per_cu = per_bfd->all_units[i].get ();
- int &this_counter = per_cu->is_debug_types ? types_counter : counter;
-
- const auto insertpair = cu_index_htab.emplace (per_cu, this_counter);
+ const auto insertpair = cu_index_htab.emplace (per_cu, counter);
gdb_assert (insertpair.second);
/* The all_units list contains CUs read from the objfile as well as
@@ -1234,7 +1230,7 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table,
else
cu_list.append_uint (8, BFD_ENDIAN_LITTLE, per_cu->length ());
- ++this_counter;
+ ++counter;
}
write_cooked_index (table, cu_index_htab, &symtab);
--
2.35.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] [gdb/ada] Extend type equivalence test in ada_resolve_enum
2023-09-07 14:42 [PATCH] [gdb/ada] Extend type equivalence test in ada_resolve_enum Tom de Vries
2023-09-07 14:42 ` [PATCH] [gdb/symtab] Fix gdb-index writing for .debug_types Tom de Vries
@ 2023-09-07 18:36 ` Tom Tromey
1 sibling, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2023-09-07 18:36 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> When using target board debug-types, the enums E1 and E2 are replicated in the
Tom> .debug_types section, and consequently in ada_resolve_enum the type
Tom> equivalence check using a pointer comparison fails:
Tom> ...
Tom> for (int i = 0; i < syms.size (); ++i)
Tom> {
Tom> /* We already know the name matches, so we're just looking for
Tom> an element of the correct enum type. */
Tom> if (ada_check_typedef (syms[i].symbol->type ()) == context_type)
Tom> return i;
Tom> }
Tom> ...
Tom> Fix this by also trying a structural comparison using
Tom> ada_identical_enum_types_p.
Thank you. I think this is ok.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] [gdb/symtab] Fix gdb-index writing for .debug_types
2023-09-07 14:42 ` [PATCH] [gdb/symtab] Fix gdb-index writing for .debug_types Tom de Vries
@ 2023-09-07 18:42 ` Tom Tromey
0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2023-09-07 18:42 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> Fix this by removing the counter / types_counter distinction in
Tom> write_gdbindex, such that we get the expected:
Tom> ...
Tom> [7194] pck__red:
Tom> T2 [static, variable]
Tom> T3 [static, variable]
Tom> ...
Tom> [ While reading write_gdbindex I noticed a few oddities related to dwz
Tom> handling, I've filed PR30829 about this. ]
Tom> Tested on x86_64-linux.
Ok. Thank you.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-07 19:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-07 14:42 [PATCH] [gdb/ada] Extend type equivalence test in ada_resolve_enum Tom de Vries
2023-09-07 14:42 ` [PATCH] [gdb/symtab] Fix gdb-index writing for .debug_types Tom de Vries
2023-09-07 18:42 ` Tom Tromey
2023-09-07 18:36 ` [PATCH] [gdb/ada] Extend type equivalence test in ada_resolve_enum Tom Tromey
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).