public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug symtab/30739] New: [gdb/symtab] wrong
@ 2023-08-09 14:14 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
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2023-08-09 14:14 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 30739
           Summary: [gdb/symtab] wrong
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: symtab
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

I went looking for a test-case that triggers the m_deferred_entries case, and
found gdb.dwarf2/pr13961.exp, which 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.

Then I looked at the resulting cooked index entries:
...
    [12] ((cooked_index_entry *) 0x3dbbd00)
    name:       foo
    canonical:  foo
    DWARF tag:  DW_TAG_class_type
    flags:      0x0 []
    DIE offset: 0x25
    parent:     ((cooked_index_entry *) 0x3dbbca0) [foo]

    [13] ((cooked_index_entry *) 0x3dbbca0)
    name:       foo
    canonical:  foo
    DWARF tag:  DW_TAG_class_type
    flags:      0x0 []
    DIE offset: 0x2a
    parent:     ((cooked_index_entry *) 0)
...
and noticed that 0x2a is the parent of 0x25.

The parent field is documented as:
...
  /* The parent entry.  This is NULL for top-level entries.                     
     Otherwise, it points to the parent entry, such as a namespace or           
     class.  */
  const cooked_index_entry *parent_entry;
...
so I'd expect no parent for 0x25.

I'd expect the current situation to match in a foo::foo name lookup.

The parent is set here:
...
  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 DIE
(though that's not clear from the comment describing it).

But, for DIE 0x2a we have m_die_range_map.find (0x2a) == 0x2a.

AFAICT, this is an off-by-one error, fixed by:
...
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index dd4fac52ca8..d60a592669a 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16477,7 +16477,7 @@ cooked_indexer::recurse (cutu_reader *reader,

   if (parent_entry != nullptr)
     {
-      CORE_ADDR start = form_addr (parent_entry->die_offset,
+      CORE_ADDR start = form_addr (parent_entry->die_offset + 1,
                                   reader->cu->per_cu->is_dwz);
       CORE_ADDR end = form_addr (sect_offset (info_ptr - 1 - reader->buffer),
                                 reader->cu->per_cu->is_dwz);
...
which gives us:
...
    [12] ((cooked_index_entry *) 0x41e21f0)
    name:       foo
    canonical:  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
    DWARF tag:  DW_TAG_class_type
    flags:      0x0 []
    DIE offset: 0x2a
    parent:     ((cooked_index_entry *) 0)
...

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug symtab/30739] [gdb/symtab] wrong parent for cooked index entry
  2023-08-09 14:14 [Bug symtab/30739] New: [gdb/symtab] wrong vries at gcc dot gnu.org
@ 2023-08-09 14:15 ` vries at gcc dot gnu.org
  2023-08-09 15:11 ` vries at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2023-08-09 14:15 UTC (permalink / raw)
  To: gdb-prs

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

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[gdb/symtab] wrong          |[gdb/symtab] wrong parent
                   |                            |for cooked index entry

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug symtab/30739] [gdb/symtab] wrong parent for cooked index entry
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2023-08-09 15:11 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
https://sourceware.org/pipermail/gdb-patches/2023-August/201485.html

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug symtab/30739] [gdb/symtab] wrong parent for cooked index entry
  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
  2023-08-10 19:19 ` vries at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-10 19:16 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 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=8f258a6c979420c33845f60575e7ed025e6dcd9d

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

    [gdb/symtab] Dump qualified name of cooked_index_entry

    When doing "maint print objfiles" for the exec of test-case
    gdb.dwarf2/pr13961.exp, we get:
    ...
        [25] ((cooked_index_entry *) 0x37b25d0)
        name:       foo
        canonical:  foo
        DWARF tag:  DW_TAG_class_type
        flags:      0x0 []
        DIE offset: 0x2a
        parent:     ((cooked_index_entry *) 0)

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

    By following the parent links in the text, we can conclude that the
qualified
    name of DIE 0x25 is foo::foo (which is incorrect, that's PR symtab/30739).

    But it's not evident, and also hard to verify in a test-case.

    Add dumping of the qualified name, such that we have:
    ...
        [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]
    ...

    Tested on x86_64-linux.

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

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug symtab/30739] [gdb/symtab] wrong parent for cooked index entry
  2023-08-09 14:14 [Bug symtab/30739] New: [gdb/symtab] wrong vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-08-10 19:16 ` cvs-commit at gcc dot gnu.org
@ 2023-08-10 19:16 ` cvs-commit at gcc dot gnu.org
  2023-08-10 19:19 ` vries at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-10 19:16 UTC (permalink / raw)
  To: gdb-prs

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug symtab/30739] [gdb/symtab] wrong parent for cooked index entry
  2023-08-09 14:14 [Bug symtab/30739] New: [gdb/symtab] wrong vries at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-08-10 19:16 ` cvs-commit at gcc dot gnu.org
@ 2023-08-10 19:19 ` vries at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: vries at gcc dot gnu.org @ 2023-08-10 19:19 UTC (permalink / raw)
  To: gdb-prs

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

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.1
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
Fixed.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-08-10 19:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2023-08-10 19:19 ` vries at gcc dot gnu.org

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).