From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id B04883858D34 for ; Tue, 2 Jun 2020 10:42:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B04883858D34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 34A2AAC5F for ; Tue, 2 Jun 2020 10:42:53 +0000 (UTC) Date: Tue, 2 Jun 2020 12:42:49 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/symtab] Enable ada .gdb_index Message-ID: <20200602104248.GA5683@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-16.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Jun 2020 10:42:53 -0000 Hi, Currently the .gdb_index is not enable for ada executables (PR24713). Fix this by adding the required support in write_psymbols, similar to how that is done for .debug_names in debug_names::insert. Tested on x86_64-linux, with native and target board cc-with-gdb-index. Any comments? Thanks, - Tom [gdb/symtab] Enable ada .gdb_index gdb/ChangeLog: 2020-06-02 Tom de Vries PR ada/24713 * dwarf2/index-write.c (struct mapped_symtab): Add m_string_obstack. (write_psymbols): Enable .gdb_index for ada. * dwarf2/read.c: Remove comment stating .gdb_index is unsupported for ada. gdb/testsuite/ChangeLog: 2020-06-02 Tom de Vries * gdb.ada/ptype_union.exp: Remove PR24713 workaround. --- gdb/dwarf2/index-write.c | 40 +++++++++++++++++++++++++++++++---- gdb/dwarf2/read.c | 3 --- gdb/testsuite/gdb.ada/ptype_union.exp | 5 ----- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index eabb67fd88..97b2310656 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -184,6 +184,9 @@ struct mapped_symtab offset_type n_elements = 0; std::vector data; + + /* Temporary storage for Ada names. */ + auto_obstack m_string_obstack; }; /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to @@ -543,18 +546,47 @@ write_psymbols (struct mapped_symtab *symtab, for (; count-- > 0; ++psymp) { struct partial_symbol *psym = *psymp; + const char *name = psym->ginfo.search_name (); if (psym->ginfo.language () == language_ada) - error (_("Ada is not currently supported by the index; " - "use the DWARF 5 index instead")); + { + /* 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 (strcmp (main_name (), name) == 0) + { + gdb_index_symbol_kind kind = symbol_kind (psym); + + add_index_entry (symtab, name, is_static, kind, cu_index); + } + + /* In order for the index to work when read back into gdb, it + has to supply a funny form of the name: it should be the + encoded name, with any suffixes stripped. Using the + ordinary encoded name will not work properly with the + searching logic in find_name_components_bounds; nor will + using the decoded name. Furthermore, an Ada "verbatim" + name (of the form "") must be entered without the + angle brackets. Note that the current index is unusual, + see PR symtab/24820 for details. */ + std::string decoded = ada_decode (name); + if (decoded[0] == '<') + name = (char *) obstack_copy0 (&symtab->m_string_obstack, + decoded.c_str () + 1, + decoded.length () - 2); + else + name = obstack_strdup (&symtab->m_string_obstack, + ada_encode (decoded.c_str ())); + } /* Only add a given psymbol once. */ if (psyms_seen.insert (psym).second) { gdb_index_symbol_kind kind = symbol_kind (psym); - add_index_entry (symtab, psym->ginfo.search_name (), - is_static, kind, cu_index); + add_index_entry (symtab, name, is_static, kind, cu_index); } } } diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 65b3b9f0a3..4e113779d3 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -3773,9 +3773,6 @@ dw2_map_matching_symbols if (per_objfile->per_bfd->index_table != nullptr) { - /* Ada currently doesn't support .gdb_index (see PR24713). We can get - here though if the current language is Ada for a non-Ada objfile - using GNU index. */ mapped_index &index = *per_objfile->per_bfd->index_table; const char *match_name = name.ada ().lookup_name ().c_str (); diff --git a/gdb/testsuite/gdb.ada/ptype_union.exp b/gdb/testsuite/gdb.ada/ptype_union.exp index 470f9b550c..c85e5f4b4b 100644 --- a/gdb/testsuite/gdb.ada/ptype_union.exp +++ b/gdb/testsuite/gdb.ada/ptype_union.exp @@ -19,11 +19,6 @@ if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { return -1 } -if {[exec_has_index_section $binfile]} { - unsupported "Ada is not currently supported by the index (PR 24713)" - return -1 -} - # The test case is written in C, because it was easy to make the # required type there; but the bug itself only happens in Ada. gdb_test "set lang ada" ""