From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway32.websitewelcome.com (gateway32.websitewelcome.com [192.185.145.101]) by sourceware.org (Postfix) with ESMTPS id 1C6A63857823 for ; Thu, 26 Aug 2021 02:20:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1C6A63857823 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tromey.com Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 648549BB73A for ; Wed, 25 Aug 2021 21:19:45 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id J4zZmP0eaBvjyJ4zZmziwq; Wed, 25 Aug 2021 21:19:45 -0500 X-Authority-Reason: nr=8 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=Aa3GPTq+rAaPpgPRmXNIy+v+1tSE/rAPAMu2s1GE+WM=; b=xfInKaT31dOqpXlHP+3MWM71+x zy+hsYR/CZ9ic47eqa4o1bggZDJUv7wYyZzQJNxOctygG9QoHKQxJ882CNAgQEIjdLraslHi3cgR4 t+ECoOpDkHvdCYg9BWkLeWne6; Received: from 97-122-86-84.hlrn.qwest.net ([97.122.86.84]:46876 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mJ4zZ-003LSg-6c; Wed, 25 Aug 2021 20:19:45 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 26/30] Adapt .gdb_index writer to new DWARF scanner Date: Wed, 25 Aug 2021 20:19:33 -0600 Message-Id: <20210826021937.1490292-27-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210826021937.1490292-1-tom@tromey.com> References: <20210826021937.1490292-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: 97.122.86.84 X-Source-L: No X-Exim-ID: 1mJ4zZ-003LSg-6c X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-84.hlrn.qwest.net (localhost.localdomain) [97.122.86.84]:46876 X-Source-Auth: tom+tromey.com X-Email-Count: 27 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, URIBL_CSS_A 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: Thu, 26 Aug 2021 02:20:24 -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 367db046f17..4a5ba484379 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. */ @@ -1604,15 +1649,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 0b7adb5379d..19b47907dee 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.31.1