From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [192.185.179.30]) by sourceware.org (Postfix) with ESMTPS id E34A7385840F for ; Thu, 4 Nov 2021 18:09:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E34A7385840F 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 cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 922D7F647 for ; Thu, 4 Nov 2021 13:09:12 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id ihAmm4cdcIWzGihAmmB85W; Thu, 04 Nov 2021 13:09:12 -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=oVbbwS2cyf44e07fdSZaeKALJsuRnEwgcosUSyDz0yA=; b=wQLI+gVn+jWD99ymWz3wN22m+V Rq+g9AEsTjowGPiNpU3SjdyzLMEPd5lh28ZmfHCCfmVWIrX5Q21gAu+CobRhkMAj97Kns+LNBm1X5 NuWQKeCeW/herN3PXtDkrGkHk; Received: from 75-166-134-234.hlrn.qwest.net ([75.166.134.234]:51958 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 1mihAm-003Gzb-Bv; Thu, 04 Nov 2021 12:09:12 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 14/32] Statically examine abbrev properties Date: Thu, 4 Nov 2021 12:08:49 -0600 Message-Id: <20211104180907.2360627-15-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211104180907.2360627-1-tom@tromey.com> References: <20211104180907.2360627-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: 75.166.134.234 X-Source-L: No X-Exim-ID: 1mihAm-003Gzb-Bv X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-134-234.hlrn.qwest.net (localhost.localdomain) [75.166.134.234]:51958 X-Source-Auth: tom+tromey.com X-Email-Count: 19 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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, 04 Nov 2021 18:09:15 -0000 The new DIE scanner works more or less along the lines indicated by the text for the .debug_names section, disregarding the bugs in the specification. While working on this, I noticed that whether a DIE is interesting is a static property of the DIE's abbrev. It also turns out that many abbrevs imply a static size for the DIE data, and additionally that for many abbrevs, the sibling offset is stored at a constant offset from the start of the DIE. This patch changes the abbrev reader to analyze each abbrev and stash the results on the abbrev. These combine to speed up the new indexer. If the "interesting" flag is false, GDB knows to skip the DIE immediately. If the sibling offset is statically known, skipping can be done without reading any attributes; and in some other cases, the DIE can be skipped using simple arithmetic. --- gdb/dwarf2/abbrev.c | 153 ++++++++++++++++++++++++++++++++++++++++++++ gdb/dwarf2/abbrev.h | 7 +- 2 files changed, 158 insertions(+), 2 deletions(-) diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c index c84f21256fd..b36a52cd5be 100644 --- a/gdb/dwarf2/abbrev.c +++ b/gdb/dwarf2/abbrev.c @@ -76,6 +76,43 @@ abbrev_table::add_abbrev (struct abbrev_info *abbrev) *slot = abbrev; } +/* Helper function that returns true if a DIE with the given tag might + plausibly be indexed. */ + +static bool +tag_interesting_for_index (dwarf_tag tag) +{ + switch (tag) + { + case DW_TAG_array_type: + case DW_TAG_base_type: + case DW_TAG_class_type: + case DW_TAG_constant: + case DW_TAG_enumeration_type: + case DW_TAG_enumerator: + case DW_TAG_imported_declaration: + case DW_TAG_imported_unit: + case DW_TAG_inlined_subroutine: + case DW_TAG_interface_type: + case DW_TAG_module: + case DW_TAG_namespace: + case DW_TAG_ptr_to_member_type: + case DW_TAG_set_type: + case DW_TAG_string_type: + case DW_TAG_structure_type: + case DW_TAG_subprogram: + case DW_TAG_subrange_type: + case DW_TAG_subroutine_type: + case DW_TAG_typedef: + case DW_TAG_union_type: + case DW_TAG_unspecified_type: + case DW_TAG_variable: + return true; + } + + return false; +} + /* Read in an abbrev table. */ abbrev_table_up @@ -116,6 +153,17 @@ abbrev_table::read (struct dwarf2_section_info *section, cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); abbrev_ptr += 1; + unsigned int size = 0; + unsigned int sibling_offset = -1; + bool is_csize = true; + + bool has_hardcoded_declaration = false; + bool has_specification_or_origin = false; + bool has_name = false; + bool has_linkage_name = false; + bool has_location = false; + bool has_external = false; + /* Now read in declarations. */ int num_attrs = 0; for (;;) @@ -142,12 +190,117 @@ abbrev_table::read (struct dwarf2_section_info *section, if (cur_attr.name == 0) break; + switch (cur_attr.name) + { + case DW_AT_declaration: + if (cur_attr.form == DW_FORM_flag_present) + has_hardcoded_declaration = true; + break; + + case DW_AT_external: + has_external = true; + break; + + case DW_AT_specification: + case DW_AT_abstract_origin: + case DW_AT_extension: + has_specification_or_origin = true; + break; + + case DW_AT_name: + has_name = true; + break; + + case DW_AT_MIPS_linkage_name: + case DW_AT_linkage_name: + has_linkage_name = true; + break; + + case DW_AT_const_value: + case DW_AT_location: + has_location = true; + break; + + case DW_AT_sibling: + if (is_csize && cur_attr.form == DW_FORM_ref4) + sibling_offset = size; + break; + } + + switch (cur_attr.form) + { + case DW_FORM_data1: + case DW_FORM_ref1: + case DW_FORM_flag: + case DW_FORM_strx1: + size += 1; + break; + case DW_FORM_flag_present: + case DW_FORM_implicit_const: + break; + case DW_FORM_data2: + case DW_FORM_ref2: + case DW_FORM_strx2: + size += 2; + break; + case DW_FORM_strx3: + size += 3; + break; + case DW_FORM_data4: + case DW_FORM_ref4: + case DW_FORM_strx4: + size += 4; + break; + case DW_FORM_data8: + case DW_FORM_ref8: + case DW_FORM_ref_sig8: + size += 8; + break; + case DW_FORM_data16: + size += 16; + break; + + default: + is_csize = false; + break; + } + ++num_attrs; obstack_grow (obstack, &cur_attr, sizeof (cur_attr)); } cur_abbrev = (struct abbrev_info *) obstack_finish (obstack); cur_abbrev->num_attrs = num_attrs; + + if (!has_name && !has_linkage_name && !has_specification_or_origin) + { + /* Some anonymous DIEs are worth examining. */ + cur_abbrev->interesting + = (cur_abbrev->tag == DW_TAG_namespace + || cur_abbrev->tag == DW_TAG_enumeration_type); + } + else if (has_hardcoded_declaration + && (cur_abbrev->tag != DW_TAG_variable || !has_external)) + cur_abbrev->interesting = false; + else if (!tag_interesting_for_index (cur_abbrev->tag)) + cur_abbrev->interesting = false; + else if (!has_location && !has_specification_or_origin && !has_external + && cur_abbrev->tag == DW_TAG_variable) + cur_abbrev->interesting = false; + else + cur_abbrev->interesting = true; + + /* If there are no children, and the abbrev has a constant size, + then we don't care about the sibling offset, because it's + simple to just skip the entire DIE without reading a sibling + offset. */ + if ((!cur_abbrev->has_children && is_csize) + /* Overflow. */ + || sibling_offset != (unsigned short) sibling_offset) + sibling_offset = -1; + cur_abbrev->size_if_constant = is_csize ? size : 0; + cur_abbrev->sibling_offset = sibling_offset; + abbrev_table->add_abbrev (cur_abbrev); } diff --git a/gdb/dwarf2/abbrev.h b/gdb/dwarf2/abbrev.h index 0a1ca4d39b4..ae02f76885d 100644 --- a/gdb/dwarf2/abbrev.h +++ b/gdb/dwarf2/abbrev.h @@ -44,9 +44,12 @@ struct abbrev_info /* Number identifying abbrev. */ unsigned int number; /* DWARF tag. */ - enum dwarf_tag tag; + ENUM_BITFIELD (dwarf_tag) tag : 16; /* True if the DIE has children. */ - unsigned short has_children; + bool has_children; + bool interesting; + unsigned short size_if_constant; + unsigned short sibling_offset; /* Number of attributes. */ unsigned short num_attrs; /* An array of attribute descriptions, allocated using the struct -- 2.31.1