From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 357363853827; Fri, 21 Oct 2022 16:13:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 357363853827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666368806; bh=Z4e2QlvP6SoXvOZEjdLFs+qAq0l1aQZMcUiym0MfWug=; h=From:To:Subject:Date:From; b=Dowy3cj68XPYURmMm5utz4nK5ubMLXHVFrV7KIFs1gdZEqeeiMkKkzDJEzuIb0mD6 MjZq1D7vMIpW5AeL0KReebAA5Rw2uvd2hpx1qZMrUxmTtzQXezMp53KtmOF4lXfTcR j+isDs4+cRreH/MAix4Mryme+1aTYM5jX+qGEjUg= 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] Fix incorrect .gdb_index with new DWARF scanner X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: e379f6521a9fbc65de8cd90a950e28d0ca522ae3 X-Git-Newrev: 2afd002ac6acb01763d643686345cc0c6ad564bd Message-Id: <20221021161326.357363853827@sourceware.org> Date: Fri, 21 Oct 2022 16:13:26 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D2afd002ac6ac= b01763d643686345cc0c6ad564bd commit 2afd002ac6acb01763d643686345cc0c6ad564bd Author: Tom Tromey Date: Mon Oct 17 12:21:10 2022 -0600 Fix incorrect .gdb_index with new DWARF scanner =20 PR symtab/29694 points out a regression caused by the new DWARF scanner when the cc-with-gdb-index target board is used. =20 What happens here is that an older version of gdb will make an index describing the "A" type as: =20 [737] A: 1 [global, type] =20 whereas the new gdb says: =20 [1008] A: 0 [global, type] =20 Here the old one is correct because the A in CU 0 is just a declaration without a size: =20 <1><45>: Abbrev Number: 10 (DW_TAG_structure_type) <46> DW_AT_name : A <48> DW_AT_declaration : 1 <48> DW_AT_sibling : <0x6d> =20 This patch fixes the problem by introducing the idea of a "type declaration". I think gdb still needs to recurse into these types, searching for methods, but by marking the type itself as a declaration, gdb can skip this type during lookups and when writing the index. =20 Regression tested on x86-64 using the cc-with-gdb-index board. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29694 Diff: --- gdb/dwarf2/cooked-index.h | 15 +++++++++++++++ gdb/dwarf2/index-write.c | 5 +++++ gdb/dwarf2/read.c | 22 ++++++++++++++-------- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index f3c26480a81..2ea32781be5 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -48,6 +48,9 @@ enum cooked_index_flag_enum : unsigned char IS_ENUM_CLASS =3D 4, /* True if this entry uses the linkage name. */ IS_LINKAGE =3D 8, + /* True if this entry is just for the declaration of a type, not the + definition. */ + IS_TYPE_DECLARATION =3D 16, }; DEF_ENUM_FLAGS_TYPE (enum cooked_index_flag_enum, cooked_index_flag); =20 @@ -76,6 +79,10 @@ struct cooked_index_entry : public allocate_on_obstack /* Return true if this entry matches SEARCH_FLAGS. */ bool matches (block_search_flags search_flags) const { + /* Just reject type declarations. */ + if ((flags & IS_TYPE_DECLARATION) !=3D 0) + return false; + if ((search_flags & SEARCH_STATIC_BLOCK) !=3D 0 && (flags & IS_STATIC) !=3D 0) return true; @@ -88,6 +95,10 @@ struct cooked_index_entry : public allocate_on_obstack /* Return true if this entry matches DOMAIN. */ bool matches (domain_enum domain) const { + /* Just reject type declarations. */ + if ((flags & IS_TYPE_DECLARATION) !=3D 0) + return false; + switch (domain) { case LABEL_DOMAIN: @@ -106,6 +117,10 @@ struct cooked_index_entry : public allocate_on_obstack /* Return true if this entry matches KIND. */ bool matches (enum search_domain kind) const { + /* Just reject type declarations. */ + if ((flags & IS_TYPE_DECLARATION) !=3D 0) + return false; + switch (kind) { case VARIABLES_DOMAIN: diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index f592734addc..3d215a6307b 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1167,6 +1167,11 @@ write_cooked_index (cooked_index_vector *table, be redundant are rare and not worth supporting. */ continue; } + else if ((entry->flags & IS_TYPE_DECLARATION) !=3D 0) + { + /* Don't add type declarations to the index. */ + continue; + } =20 gdb_index_symbol_kind kind; if (entry->tag =3D=3D DW_TAG_subprogram) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 7de89dd5923..cde7a5bd01f 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -18191,14 +18191,20 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_da= ta *scanning_per_cu, that is ok. Similarly, we allow an external variable without a location; those are resolved via minimal symbols. */ if (is_declaration && !for_specification - && !(abbrev->tag =3D=3D DW_TAG_variable && (*flags & IS_STATIC) =3D= =3D 0) - && !((abbrev->tag =3D=3D DW_TAG_class_type - || abbrev->tag =3D=3D DW_TAG_structure_type - || abbrev->tag =3D=3D DW_TAG_union_type) - && abbrev->has_children)) - { - *linkage_name =3D nullptr; - *name =3D nullptr; + && !(abbrev->tag =3D=3D DW_TAG_variable && (*flags & IS_STATIC) =3D= =3D 0)) + { + /* We always want to recurse into some types, but we may not + want to treat them as definitions. */ + if ((abbrev->tag =3D=3D DW_TAG_class_type + || abbrev->tag =3D=3D DW_TAG_structure_type + || abbrev->tag =3D=3D DW_TAG_union_type) + && abbrev->has_children) + *flags |=3D IS_TYPE_DECLARATION; + else + { + *linkage_name =3D nullptr; + *name =3D nullptr; + } } else if ((*name =3D=3D nullptr || (*linkage_name =3D=3D nullptr