From: Tom Tromey Date: Wed, 11 Feb 2026 22:05:26 +0000 (-0700) Subject: Handle enumerators in name associations in Ada X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af67bb32a24bf26287568ce5069d8e12be6579ec;p=thirdparty%2Fbinutils-gdb.git Handle enumerators in name associations in Ada assoc.exp does this: print pck.value := (Left => 3, Center => 7, Pck.Right => 2) However, the test case is constructed so that "Center" has multiple meanings: it might name the enumerator here: type Posn is (Left, Center, Right); or it might refer to this variable: Center : Pck.Posn := Pck.Right; The correct answer in this case is to pick the enumerator, because that is the array's index type. Originally I didn't fix this problem and instead used a kfail. However, this same problem turned up again (in a slightly different form) when the libgnat debuginfo was installed. This patch fixes the bug by introducing new code in ada_name_association::assign to handle the enumeration case. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33896 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33898 Tested-By: Tom de Vries --- diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index ae594378047..9ffe453b027 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -9643,8 +9643,41 @@ ada_name_association::assign (aggregate_assigner &assigner, if (ada_is_direct_array_type (assigner.lhs->type ())) { - value *tem = m_val->evaluate (nullptr, assigner.exp, EVAL_NORMAL); - index = value_as_long (tem); + std::optional enum_index; + + /* If the array's index type has enumeration type, then simple + names should be looked up as enumerators. */ + if (const char *name = find_name (op); + name != nullptr) + { + type *idx_type + = ada_check_typedef (assigner.lhs->type ())->index_type (); + idx_type = get_base_type (idx_type); + if (idx_type->code () == TYPE_CODE_ENUM) + { + for (const auto &field : idx_type->fields ()) + { + const char *ename = ada_enum_name (field.name ()); + if (streq (name, ename)) + { + enum_index = field.loc_enumval (); + break; + } + } + + /* If we didn't find the name, that is ok -- the user + might have written (VAR => EXPR), naming some + variable somewhere. */ + } + } + + if (enum_index.has_value ()) + index = *enum_index; + else + { + value *tem = m_val->evaluate (nullptr, assigner.exp, EVAL_NORMAL); + index = value_as_long (tem); + } } else { diff --git a/gdb/testsuite/gdb.ada/assoc.exp b/gdb/testsuite/gdb.ada/assoc.exp index 5d073f3a190..0a2b4bd5bda 100644 --- a/gdb/testsuite/gdb.ada/assoc.exp +++ b/gdb/testsuite/gdb.ada/assoc.exp @@ -34,7 +34,6 @@ gdb_test_multiple "print pck.value := (Left => 3, Center => 7, Pck.Right => 2)" pass $gdb_test_name } -wrap -re " = \\(3, 2, 2\\)" { - setup_kfail ada/33898 *-*-* fail $gdb_test_name } }