From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 5EFDD3858281; Mon, 17 Oct 2022 16:11:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5EFDD3858281 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666023060; bh=lJ7EaEprSU2pO4zc3oDmkjxaU68al67Ib17i6sL8Yr4=; h=From:To:Subject:Date:From; b=DoBQWwjL73Y67mnoJeMhcQsQKgZKOGqZLoB5g5W7SJAlBnrqZEZYD+Dtg27OTeKJB H8Snqexe3bhlUr4cMtedYasxv24YYN7mmFaFrWptrE9snHBgDj7OMtSVSSPs2q2kZ0 95xsThkoprSAjrotTxNFUqjEKfhjAIVPTUW3UDFg= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Improve Ada support in .gdb_index X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: acd121de32c3924347f228d8f27000a09b9c8949 X-Git-Newrev: 5fea97943259a2bd997f92ffa66116b5c0d4eaab Message-Id: <20221017161100.5EFDD3858281@sourceware.org> Date: Mon, 17 Oct 2022 16:11:00 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D5fea97943259= a2bd997f92ffa66116b5c0d4eaab commit 5fea97943259a2bd997f92ffa66116b5c0d4eaab Author: Tom Tromey Date: Thu Sep 22 08:43:47 2022 -0600 Improve Ada support in .gdb_index =20 The cooked index work changed how .gdb_index is constructed, and in the process broke .gdb_index support. This is PR symtab/29179. =20 This patch partially fixes the problem. It arranges for Ada names to be encoded in the form expected by the index code. In particular, linkage names for Ada are emitted, including the "main" name; names are Ada-encoded; and names are no longer case-folded, something that prevented operator names from round-tripping correctly. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29179 Diff: --- gdb/ada-lang.c | 8 +++++--- gdb/ada-lang.h | 2 +- gdb/dwarf2/index-write.c | 44 +++++++++++++++++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 1f26394208a..adacf1dd1c9 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -1146,12 +1146,14 @@ ada_fold_name (gdb::string_view name, bool throw_on= _error =3D false) return fold_storage.c_str (); } =20 -/* The "encoded" form of DECODED, according to GNAT conventions. */ +/* The "encoded" form of DECODED, according to GNAT conventions. If + FOLD is true (the default), case-fold any ordinary symbol. Symbols + with <...> quoting are not folded in any case. */ =20 std::string -ada_encode (const char *decoded) +ada_encode (const char *decoded, bool fold) { - if (decoded[0] !=3D '<') + if (fold && decoded[0] !=3D '<') decoded =3D ada_fold_name (decoded); return ada_encode_1 (decoded, true); } diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h index df648c2297e..84c691b94ee 100644 --- a/gdb/ada-lang.h +++ b/gdb/ada-lang.h @@ -316,7 +316,7 @@ extern struct type *ada_get_base_type (struct type *); =20 extern struct type *ada_check_typedef (struct type *); =20 -extern std::string ada_encode (const char *); +extern std::string ada_encode (const char *, bool fold =3D true); =20 extern const char *ada_enum_name (const char *); =20 diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 4f89dfb65f7..6b4052c3467 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1109,22 +1109,48 @@ write_cooked_index (cooked_index_vector *table, htab_up var_names (htab_create_alloc (10, htab_hash_string, htab_eq_stri= ng, nullptr, xcalloc, xfree)); =20 + const char *main_for_ada =3D main_name (); + for (const cooked_index_entry *entry : table->all_entries ()) { - /* GDB never put C++ linkage names into .gdb_index. The theory - here is that a linkage name will normally be in the minimal - symbols anyway, so including it in the index is usually - redundant -- and the cases where it would not be redundant - are rare and not worth supporting. */ - if (entry->per_cu->lang () =3D=3D language_cplus - && (entry->flags & IS_LINKAGE) !=3D 0) - continue; - const auto it =3D cu_index_htab.find (entry->per_cu); gdb_assert (it !=3D cu_index_htab.cend ()); =20 const char *name =3D entry->full_name (&symtab->m_string_obstack); =20 + if (entry->per_cu->lang () =3D=3D language_ada) + { + /* We want to ensure that the Ada main function's name + appears verbatim in the index. However, this name will + be of the form "_ada_mumble", and will be rewritten by + ada_decode. So, recognize it specially here and add it + to the index by hand. */ + if (entry->tag =3D=3D DW_TAG_subprogram + && strcmp (main_for_ada, name) =3D=3D 0) + { + /* Leave it alone. */ + } + else + { + /* In order for the index to work when read back into + gdb, it has to use the encoded name, with any + suffixes stripped. */ + std::string encoded =3D ada_encode (name, false); + name =3D obstack_strdup (&symtab->m_string_obstack, + encoded.c_str ()); + } + } + else if (entry->per_cu->lang () =3D=3D language_cplus + && (entry->flags & IS_LINKAGE) !=3D 0) + { + /* GDB never put C++ linkage names into .gdb_index. The + theory here is that a linkage name will normally be in + the minimal symbols anyway, so including it in the index + is usually redundant -- and the cases where it would not + be redundant are rare and not worth supporting. */ + continue; + } + gdb_index_symbol_kind kind; if (entry->tag =3D=3D DW_TAG_subprogram) kind =3D GDB_INDEX_SYMBOL_KIND_FUNCTION;