forked from Imagelibrary/binutils-gdb
[gdb/ada] Extend type equivalence test in ada_resolve_enum
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.
Approved-By: Tom Tromey <tom@tromey.com>
PR ada/29335
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29335
This commit is contained in:
@@ -204,6 +204,8 @@ static symbol_name_matcher_ftype *ada_get_symbol_name_matcher
|
|||||||
|
|
||||||
static int symbols_are_identical_enums
|
static int symbols_are_identical_enums
|
||||||
(const std::vector<struct block_symbol> &syms);
|
(const std::vector<struct block_symbol> &syms);
|
||||||
|
|
||||||
|
static int ada_identical_enum_types_p (struct type *type1, struct type *type2);
|
||||||
|
|
||||||
|
|
||||||
/* The character set used for source files. */
|
/* The character set used for source files. */
|
||||||
@@ -3801,11 +3803,24 @@ ada_resolve_enum (std::vector<struct block_symbol> &syms,
|
|||||||
gdb_assert (context_type->code () == TYPE_CODE_ENUM);
|
gdb_assert (context_type->code () == TYPE_CODE_ENUM);
|
||||||
context_type = ada_check_typedef (context_type);
|
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)
|
for (int i = 0; i < syms.size (); ++i)
|
||||||
{
|
{
|
||||||
/* We already know the name matches, so we're just looking for
|
struct type *type2 = ada_check_typedef (syms[i].symbol->type ());
|
||||||
an element of the correct enum type. */
|
if (type1 == type2)
|
||||||
if (ada_check_typedef (syms[i].symbol->type ()) == context_type)
|
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;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user