From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from qproxy1-pub.mail.unifiedlayer.com (qproxy1-pub.mail.unifiedlayer.com [173.254.64.10]) by sourceware.org (Postfix) with ESMTPS id 6F76A385800E for ; Mon, 4 Apr 2022 19:54:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6F76A385800E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from gproxy4-pub.mail.unifiedlayer.com (unknown [69.89.23.142]) by qproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 1C6918026868 for ; Mon, 4 Apr 2022 19:54:18 +0000 (UTC) Received: from cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway6.mail.pro1.eigbox.com (Postfix) with ESMTP id E229610044F67 for ; Mon, 4 Apr 2022 19:53:47 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id bSlnnJMb5Qs3CbSlnnPKQi; Mon, 04 Apr 2022 19:53:47 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=A+Opg4aG c=1 sm=1 tr=0 ts=624b4ccb a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=z0gMJWrwH1QA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=hZiiH4CShsESFq26OtoA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=WPDPqU9rETOkjgvAzk0/ov4xexEpZOhsjFYMUh5vaQQ=; b=ebDYJ5DQKnhrSq8+bWPAMjuTKe v+Y/33PlP2s5aGm7ZWyKs05pw/XY1eujdwmwthAC7gzeCR4PRIGHXT2b+nNDyelWqk2eDUh3P46wX J5LT1hLL9shAkv3aI6/4fNwpd; Received: from 71-211-176-135.hlrn.qwest.net ([71.211.176.135]:34804 helo=prentzel.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nbSln-003uM1-5S; Mon, 04 Apr 2022 13:53:47 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v4 30/34] Adapt .gdb_index writer to new DWARF scanner Date: Mon, 4 Apr 2022 13:53:31 -0600 Message-Id: <20220404195335.2111906-31-tom@tromey.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220404195335.2111906-1-tom@tromey.com> References: <20220404195335.2111906-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.176.135 X-Source-L: No X-Exim-ID: 1nbSln-003uM1-5S X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-176-135.hlrn.qwest.net (prentzel.Home) [71.211.176.135]:34804 X-Source-Auth: tom+tromey.com X-Email-Count: 38 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3029.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Mon, 04 Apr 2022 19:54:29 -0000 This updates the .gdb_index writer to work with the new DWARF scanner. The .debug_names writer is deferred to another patch, to make review simpler. This introduces a small hack to psyms_seen_size, but is inconsequential because this function will be deleted in a subsequent patch. --- gdb/dwarf2/index-write.c | 63 ++++++++++++++++++++++---- gdb/testsuite/gdb.dwarf2/gdb-index.exp | 5 +- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 9fe7724feea..4d9a9a18c95 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -189,7 +189,7 @@ struct mapped_symtab offset_type n_elements = 0; std::vector data; - /* Temporary storage for Ada names. */ + /* Temporary storage for names. */ auto_obstack m_string_obstack; }; @@ -1237,6 +1237,9 @@ check_dwarf64_offsets (dwarf2_per_objfile *per_objfile) static size_t psyms_seen_size (dwarf2_per_objfile *per_objfile) { + if (per_objfile->per_bfd->using_index) + return 0; + size_t psyms_count = 0; for (const auto &per_cu : per_objfile->per_bfd->all_comp_units) { @@ -1312,6 +1315,41 @@ write_gdbindex_1 (FILE *out_file, assert_file_size (out_file, total_len); } +/* Write the contents of the internal "cooked" index. */ + +static void +write_cooked_index (dwarf2_per_objfile *per_objfile, + const cu_index_map &cu_index_htab, + struct mapped_symtab *symtab) +{ + gdb_assert (per_objfile->per_bfd->using_index); + + for (const cooked_index_entry *entry + : per_objfile->per_bfd->cooked_index_table->all_entries ()) + { + const auto it = cu_index_htab.find (entry->per_cu); + gdb_assert (it != cu_index_htab.cend ()); + + const char *name = entry->full_name (&symtab->m_string_obstack); + + gdb_index_symbol_kind kind; + if (entry->tag == DW_TAG_subprogram) + kind = GDB_INDEX_SYMBOL_KIND_FUNCTION; + else if (entry->tag == DW_TAG_variable + || entry->tag == DW_TAG_constant + || entry->tag == DW_TAG_enumerator) + kind = GDB_INDEX_SYMBOL_KIND_VARIABLE; + else if (entry->tag == DW_TAG_module + || entry->tag == DW_TAG_common_block) + kind = GDB_INDEX_SYMBOL_KIND_OTHER; + else + kind = GDB_INDEX_SYMBOL_KIND_TYPE; + + add_index_entry (symtab, name, (entry->flags & IS_STATIC) != 0, + kind, it->second); + } +} + /* Write contents of a .gdb_index section for OBJFILE into OUT_FILE. If OBJFILE has an associated dwz file, write contents of a .gdb_index section for that dwz file into DWZ_OUT_FILE. If OBJFILE does not have an @@ -1348,7 +1386,9 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, FILE *out_file, { dwarf2_per_cu_data *per_cu = per_objfile->per_bfd->all_comp_units[i].get (); - partial_symtab *psymtab = per_cu->v.psymtab; + partial_symtab *psymtab = (per_objfile->per_bfd->using_index + ? nullptr + : per_cu->v.psymtab); int &this_counter = per_cu->is_debug_types ? types_counter : counter; @@ -1357,7 +1397,10 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, FILE *out_file, if (psymtab->user == NULL) recursively_write_psymbols (objfile, psymtab, &symtab, psyms_seen, this_counter); + } + if (psymtab != NULL || per_objfile->per_bfd->using_index) + { const auto insertpair = cu_index_htab.emplace (per_cu, this_counter); gdb_assert (insertpair.second); @@ -1385,6 +1428,9 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, FILE *out_file, ++this_counter; } + if (per_objfile->per_bfd->using_index) + write_cooked_index (per_objfile, cu_index_htab, &symtab); + /* Dump the address map. */ data_buf addr_vec; if (per_objfile->per_bfd->using_index) @@ -1396,8 +1442,7 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, FILE *out_file, } else write_address_map (per_objfile->per_bfd->partial_symtabs->psymtabs_addrmap, - addr_vec, cu_index_htab, - per_objfile->per_bfd->using_index); + addr_vec, cu_index_htab, false); /* Now that we've processed all symbols we can shrink their cu_indices lists. */ @@ -1603,15 +1648,17 @@ write_dwarf_index (dwarf2_per_objfile *per_objfile, const char *dir, dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; struct objfile *objfile = per_objfile->objfile; - if (per_objfile->per_bfd->using_index) + if (per_objfile->per_bfd->using_index + && per_objfile->per_bfd->cooked_index_table == nullptr) error (_("Cannot use an index to create the index")); if (per_objfile->per_bfd->types.size () > 1) error (_("Cannot make an index when the file has multiple .debug_types sections")); - if (per_bfd->partial_symtabs == nullptr - || !per_bfd->partial_symtabs->psymtabs - || !per_bfd->partial_symtabs->psymtabs_addrmap) + if ((per_bfd->partial_symtabs == nullptr + || !per_bfd->partial_symtabs->psymtabs + || !per_bfd->partial_symtabs->psymtabs_addrmap) + && per_bfd->cooked_index_table == nullptr) return; struct stat st; diff --git a/gdb/testsuite/gdb.dwarf2/gdb-index.exp b/gdb/testsuite/gdb.dwarf2/gdb-index.exp index 587b034b28b..5badcaccb1b 100644 --- a/gdb/testsuite/gdb.dwarf2/gdb-index.exp +++ b/gdb/testsuite/gdb.dwarf2/gdb-index.exp @@ -90,12 +90,15 @@ gdb_test_multiple "mt print objfiles ${testfile}" $test { -re "debug_names.*${gdb_prompt} $" { set binfile_with_index $binfile } - -re "Psymtabs.*${gdb_prompt} $" { + -re "(Psymtabs|Cooked).*${gdb_prompt} $" { set binfile_with_index [local_add_gdb_index $binfile] if { ${binfile_with_index} == "" } { return -1 } } + -re ".*${gdb_prompt} $" { + fail "unrecognized symbol reader" + } } # Ok, we have a copy of $binfile with an index. -- 2.34.1