Bug 29694 - [gdb, gdb-index] FAIL: gdb.cp/stub-array-size.exp: print sizeof(a)/sizeof(a[0])
Summary: [gdb, gdb-index] FAIL: gdb.cp/stub-array-size.exp: print sizeof(a)/sizeof(a[0])
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: symtab (show other bugs)
Version: unknown
: P2 normal
Target Milestone: 13.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks: 29366
  Show dependency treegraph
 
Reported: 2022-10-16 07:41 UTC by Tom de Vries
Modified: 2022-10-21 16:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Patch adding hardcoded .s test-case (4.56 KB, patch)
2022-10-16 15:39 UTC, Tom de Vries
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2022-10-16 07:41:21 UTC
On openSUSE Tumbleweed with test-case gdb.cp/stub-array-size.exp and target board cc-with-gdb-index, I run into:
...
(gdb) print sizeof(a)/sizeof(a[0])^M
Division by zero^M
(gdb) FAIL: gdb.cp/stub-array-size.exp: print sizeof(a)/sizeof(a[0])
...

This is a regression since gdb 12 branch point.

Bisects to:
...
6acc36f71dfc60e357496174672103f133f85e97 is the first bad commit
commit 6acc36f71dfc60e357496174672103f133f85e97
Author: Tom Tromey <tromey@adacore.com>
Date:   Thu Apr 21 09:37:24 2022 -0600

    Fix method naming bug in new DWARF indexer
...
Comment 1 Tom de Vries 2022-10-16 07:43:43 UTC
This is not reproducible sofar on Leap 15.4.
Comment 2 Tom de Vries 2022-10-16 15:39:21 UTC
Created attachment 14400 [details]
Patch adding hardcoded .s test-case

Using this test-case, I can reproduce the problem on Leap 15.4.
Comment 3 Tom Tromey 2022-10-16 16:10:36 UTC
I was able to reproduce on Fedora 34.
On Monday I'll check if my gdb-index series fixes it.
Comment 4 Tom de Vries 2022-10-17 03:59:07 UTC
(In reply to Tom Tromey from comment #3)
> I was able to reproduce on Fedora 34.
> On Monday I'll check if my gdb-index series fixes it.

Unfortunately, for me it doesn't.
Comment 5 Tom Tromey 2022-10-17 15:48:22 UTC
The new index says:

[1008] A: 0 [global, type]

whereas the old one says:

[737] A: 1 [global, type]

Here the old one is correct because the A in CU 0 is
just a declaration without a size:

 <1><45>: Abbrev Number: 10 (DW_TAG_structure_type)
    <46>   DW_AT_name        : A
    <48>   DW_AT_declaration : 1
    <48>   DW_AT_sibling     : <0x6d>

So, I think the solution is probably for the scanner to
avoid creating entries for these declaration types.
Comment 7 Sourceware Commits 2022-10-21 16:13:27 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

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

commit 2afd002ac6acb01763d643686345cc0c6ad564bd
Author: Tom Tromey <tromey@adacore.com>
Date:   Mon Oct 17 12:21:10 2022 -0600

    Fix incorrect .gdb_index with new DWARF scanner
    
    PR symtab/29694 points out a regression caused by the new DWARF
    scanner when the cc-with-gdb-index target board is used.
    
    What happens here is that an older version of gdb will make an index
    describing the "A" type as:
    
    [737] A: 1 [global, type]
    
    whereas the new gdb says:
    
    [1008] A: 0 [global, type]
    
    Here the old one is correct because the A in CU 0 is just a
    declaration without a size:
    
     <1><45>: Abbrev Number: 10 (DW_TAG_structure_type)
        <46>   DW_AT_name        : A
        <48>   DW_AT_declaration : 1
        <48>   DW_AT_sibling     : <0x6d>
    
    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.
    
    Regression tested on x86-64 using the cc-with-gdb-index board.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29694
Comment 8 Tom Tromey 2022-10-21 16:14:58 UTC
Fixed.