public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug symtab/30739] [gdb/symtab] wrong parent for cooked index entry
Date: Thu, 10 Aug 2023 19:16:56 +0000	[thread overview]
Message-ID: <bug-30739-4717-0sbuZtkYpe@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-30739-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=30739

--- Comment #3 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=aa5b8b8cc3c0246f00617ec23ebf15203fd75242

commit aa5b8b8cc3c0246f00617ec23ebf15203fd75242
Author: Tom de Vries <tdevries@suse.de>
Date:   Thu Aug 10 21:16:30 2023 +0200

    [gdb/symtab] Fix off-by-one error in cooked_indexer::recurse

    Test-case gdb.dwarf2/pr13961.exp contains:
    ...
     <1><25>: Abbrev Number: 8 (DW_TAG_class_type)
        <26>   DW_AT_specification: <0x2a>
     <1><2a>: Abbrev Number: 2 (DW_TAG_class_type)
        <2b>   DW_AT_name        : foo
        <2f>   DW_AT_byte_size   : 4
        <30>   DW_AT_decl_file   : 1
        <31>   DW_AT_decl_line   : 1
        <32>   DW_AT_sibling     : <0x44>
    ...

    The DIE at 0x25 contains an intra-CU forward reference, and is deferred
during
    DIE indexing in the cooked_index, by adding it to m_deferred_entries.

    The resulting cooked index entries are:
    ...
            [25] ((cooked_index_entry *) 0x333b5d0)
            name:       foo
            canonical:  foo
            qualified:  foo
            DWARF tag:  DW_TAG_class_type
            flags:      0x0 []
            DIE offset: 0x2a
            parent:     ((cooked_index_entry *) 0)

            [26] ((cooked_index_entry *) 0x333b630)
            name:       foo
            canonical:  foo
            qualified:  foo::foo
            DWARF tag:  DW_TAG_class_type
            flags:      0x0 []
            DIE offset: 0x25
            parent:     ((cooked_index_entry *) 0x333b5d0) [foo]
    ...

    Notice that 0x2a is the parent of 0x25, and that this is why the qualified
    name of 0x25 is "foo::foo", which is incorrect, it's supposed to be "foo".

    The parent is set here in cooked_indexer::make_index:
    ...
      for (const auto &entry : m_deferred_entries)
        {
          void *obj = m_die_range_map.find (entry.spec_offset);
          cooked_index_entry *parent = static_cast<cooked_index_entry *> (obj);
          m_index_storage->add (entry.die_offset, entry.tag, entry.flags,
                                entry.name, parent, m_per_cu);
        }
    ...
    and AFAICT, we store in m_die_range_map the parent of the respective
    spec_offset DIE (though that's not clear from the comment describing it).

    So, the root cause of this is that when we lookup the parent for DIE 0x25,
we get
    m_die_range_map.find (0x2a) == 0x2a.

    This is an off-by-one error, fixed in cooked_indexer::recurse by:
    ...
    -      CORE_ADDR start = form_addr (parent_entry->die_offset,
    +      CORE_ADDR start = form_addr (parent_entry->die_offset + 1,
    ...
    which gives us:
    ...
        [12] ((cooked_index_entry *) 0x41e21f0)
        name:       foo
        canonical:  foo
        qualified:  foo
        DWARF tag:  DW_TAG_class_type
        flags:      0x0 []
        DIE offset: 0x25
        parent:     ((cooked_index_entry *) 0)

        [13] ((cooked_index_entry *) 0x41e2190)
        name:       foo
        canonical:  foo
        qualified:  foo
        DWARF tag:  DW_TAG_class_type
        flags:      0x0 []
        DIE offset: 0x2a
        parent:     ((cooked_index_entry *) 0)
    ...

    Tested on x86_64-linux.

    Approved-By: Tom Tromey <tom@tromey.com>

    PR symtab/30739
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30739

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2023-08-10 19:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-09 14:14 [Bug symtab/30739] New: [gdb/symtab] wrong vries at gcc dot gnu.org
2023-08-09 14:15 ` [Bug symtab/30739] [gdb/symtab] wrong parent for cooked index entry vries at gcc dot gnu.org
2023-08-09 15:11 ` vries at gcc dot gnu.org
2023-08-10 19:16 ` cvs-commit at gcc dot gnu.org
2023-08-10 19:16 ` cvs-commit at gcc dot gnu.org [this message]
2023-08-10 19:19 ` vries at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-30739-4717-0sbuZtkYpe@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).