public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug symtab/30656] New: [gdb/symtab] optimized out static handled inconsistently
@ 2023-07-20  5:15 vries at gcc dot gnu.org
  2023-07-20  6:42 ` [Bug symtab/30656] " vries at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-07-20  5:15 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 30656
           Summary: [gdb/symtab] optimized out static handled
                    inconsistently
           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 wrote a dwarf assembly test-case simulating an optimized-out static variable:
...
  Compilation Unit @ offset 0xb1:
   Length:        0x1e (32-bit)
   Version:       4
   Abbrev Offset: 0x67
   Pointer Size:  8
 <0><bc>: Abbrev Number: 2 (DW_TAG_compile_unit)
    <bd>   DW_AT_language    : 2        (non-ANSI C)
 <1><be>: Abbrev Number: 3 (DW_TAG_base_type)
    <bf>   DW_AT_byte_size   : 8
    <c0>   DW_AT_encoding    : 5        (signed)
    <c1>   DW_AT_name        : integer
 <1><c9>: Abbrev Number: 4 (DW_TAG_variable)
    <ca>   DW_AT_name        : var
    <ce>   DW_AT_type        : <0xbe>
 <1><d2>: Abbrev Number: 0
...

I get different behaviour for when the symtab is not expanded:
...
$ gdb -q -batch ./static-optimized-out -ex "print var"
No symbol "var" in current context.
...
and when it is expanded:
...
$ gdb -q -batch -readnow ./static-optimized-out -ex "print var"
$1 = <optimized out>
...

I can reproduce this as far back as gdb-8.3-branch (though there's a crash with
gdb-10-branch).

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

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

* [Bug symtab/30656] [gdb/symtab] optimized out static handled inconsistently
  2023-07-20  5:15 [Bug symtab/30656] New: [gdb/symtab] optimized out static handled inconsistently vries at gcc dot gnu.org
@ 2023-07-20  6:42 ` vries at gcc dot gnu.org
  2023-07-20  6:48 ` vries at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-07-20  6:42 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
Tentative fix:
...
$ git diff
diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c
index 1ebf8f6eed5..3a429fd41b1 100644
--- a/gdb/dwarf2/abbrev.c
+++ b/gdb/dwarf2/abbrev.c
@@ -162,7 +162,6 @@ abbrev_table::read (struct dwarf2_section_info *section,
       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.  */
@@ -217,11 +216,6 @@ abbrev_table::read (struct dwarf2_section_info *section,
              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;
@@ -296,9 +290,6 @@ abbrev_table::read (struct dwarf2_section_info *section,
        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;

...

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

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

* [Bug symtab/30656] [gdb/symtab] optimized out static handled inconsistently
  2023-07-20  5:15 [Bug symtab/30656] New: [gdb/symtab] optimized out static handled inconsistently vries at gcc dot gnu.org
  2023-07-20  6:42 ` [Bug symtab/30656] " vries at gcc dot gnu.org
@ 2023-07-20  6:48 ` vries at gcc dot gnu.org
  2023-07-20  7:35 ` vries at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-07-20  6:48 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #0)
> I wrote a dwarf assembly test-case simulating an optimized-out static
> variable:

Also reproduced with a plain C test-case:
...
$ cat whole-program.c
static int aaa;

int
main (void)
{
  return 0;
}
$ gcc-12 whole-program.c -g -flto -O2
$ nm a.out | grep aaa
$
...

Corresponding DIE:
...
 <1><104>: Abbrev Number: 2 (DW_TAG_variable)
    <105>   DW_AT_name        : aaa
    <109>   DW_AT_decl_file   : 1
    <10a>   DW_AT_decl_line   : 1
    <10b>   DW_AT_decl_column : 12
    <10c>   DW_AT_type        : <0x110>
...

Difference in behaviour:
....
$ gdb -q -batch ./a.out -ex "print aaa"
No symbol "aaa" in current context.
$ gdb -q -batch -readnow ./a.out -ex "print aaa"
$1 = <optimized out>
...

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

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

* [Bug symtab/30656] [gdb/symtab] optimized out static handled inconsistently
  2023-07-20  5:15 [Bug symtab/30656] New: [gdb/symtab] optimized out static handled inconsistently vries at gcc dot gnu.org
  2023-07-20  6:42 ` [Bug symtab/30656] " vries at gcc dot gnu.org
  2023-07-20  6:48 ` vries at gcc dot gnu.org
@ 2023-07-20  7:35 ` vries at gcc dot gnu.org
  2023-07-20 14:43 ` vries at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-07-20  7:35 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #1)
> Tentative fix:

Passes regression test on x86_64-linux.

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

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

* [Bug symtab/30656] [gdb/symtab] optimized out static handled inconsistently
  2023-07-20  5:15 [Bug symtab/30656] New: [gdb/symtab] optimized out static handled inconsistently vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-07-20  7:35 ` vries at gcc dot gnu.org
@ 2023-07-20 14:43 ` vries at gcc dot gnu.org
  2023-07-21  6:25 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-07-20 14:43 UTC (permalink / raw)
  To: gdb-prs

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

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

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

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

* [Bug symtab/30656] [gdb/symtab] optimized out static handled inconsistently
  2023-07-20  5:15 [Bug symtab/30656] New: [gdb/symtab] optimized out static handled inconsistently vries at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-07-20 14:43 ` vries at gcc dot gnu.org
@ 2023-07-21  6:25 ` cvs-commit at gcc dot gnu.org
  2023-07-21  6:26 ` vries at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-21  6:25 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #5 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=f4c4456eb4d826f39abb2575ce5c2c4640bb16f3

commit f4c4456eb4d826f39abb2575ce5c2c4640bb16f3
Author: Tom de Vries <tdevries@suse.de>
Date:   Fri Jul 21 08:25:25 2023 +0200

    [gdb/symtab] Add optimized out static var to cooked index

    Consider the test-case:
    ...
    $ cat main.c
    int main (void) { return 0; }
    $ cat static-optimized-out.c
    static int aaa;
    ...
    compiled like this:
    ...
    $ gcc-12 static-optimized-out.c main.c -g -O2 -flto
    ...

    There's a difference in behaviour depending on symtab expansion state:
    ...
    $ gdb -q -batch a.out -ex "print aaa"
    No symbol "aaa" in current context.
    $ gdb -q -batch a.out -ex "maint expand-symtab" -ex "print aaa"
    $1 = <optimized out>
    ...

    The reason for the difference is that the optimized out variable aaa:
    ...
     <1><104>: Abbrev Number: 2 (DW_TAG_variable)
        <105>   DW_AT_name        : aaa
        <109>   DW_AT_decl_file   : 1
        <10a>   DW_AT_decl_line   : 18
        <10b>   DW_AT_decl_column : 12
        <10c>   DW_AT_type        : <0x110>
    ...
    is not added to the cooked index because of this clause in
abbrev_table::read:
    ...
         else if (!has_location && !has_specification_or_origin &&
!has_external
                   && cur_abbrev->tag == DW_TAG_variable)
            cur_abbrev->interesting = false;
    ...

    Fix this inconsistency by making sure that the optimized out variable is
added
    to the cooked index.

    Regression tested on x86_64-linux.

    Add two test-cases, a C test-case gdb.opt/static-optimized-out.exp and a
dwarf
    assembly test-case gdb.dwarf2/static-optimized-out.exp.

    Tested gdb.opt/static-optimized-out.exp with gcc-8 to gcc-12, for which we
now
    consistently get:
    ...
    (gdb) print aaa^M
    $1 = <optimized out>^M
    ...
    and with gcc 7.5.0 and clang 13.0.1, for which we still consistently get:
    ...
    (gdb) print aaa^M
    No symbol "aaa" in current context.^M
    ...
    due to missing debug info for the variable.

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

    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] 10+ messages in thread

* [Bug symtab/30656] [gdb/symtab] optimized out static handled inconsistently
  2023-07-20  5:15 [Bug symtab/30656] New: [gdb/symtab] optimized out static handled inconsistently vries at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-07-21  6:25 ` cvs-commit at gcc dot gnu.org
@ 2023-07-21  6:26 ` vries at gcc dot gnu.org
  2023-07-21  6:51 ` vries at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-07-21  6:26 UTC (permalink / raw)
  To: gdb-prs

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

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

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

--- Comment #6 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] 10+ messages in thread

* [Bug symtab/30656] [gdb/symtab] optimized out static handled inconsistently
  2023-07-20  5:15 [Bug symtab/30656] New: [gdb/symtab] optimized out static handled inconsistently vries at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-07-21  6:26 ` vries at gcc dot gnu.org
@ 2023-07-21  6:51 ` vries at gcc dot gnu.org
  2023-07-21 14:14 ` vries at gcc dot gnu.org
  2023-07-21 14:16 ` vries at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-07-21  6:51 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #7 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #2)
> (In reply to Tom de Vries from comment #0)
> > I wrote a dwarf assembly test-case simulating an optimized-out static
> > variable:
> 
> Also reproduced with a plain C test-case:
> ...
> $ cat whole-program.c
> static int aaa;
> 
> int
> main (void)
> {
>   return 0;
> }
> $ gcc-12 whole-program.c -g -flto -O2
> $ nm a.out | grep aaa
> $
> ...
> 
> Corresponding DIE:
> ...
>  <1><104>: Abbrev Number: 2 (DW_TAG_variable)
>     <105>   DW_AT_name        : aaa
>     <109>   DW_AT_decl_file   : 1
>     <10a>   DW_AT_decl_line   : 1
>     <10b>   DW_AT_decl_column : 12
>     <10c>   DW_AT_type        : <0x110>
> ...
> 
> Difference in behaviour:
> ....
> $ gdb -q -batch ./a.out -ex "print aaa"
> No symbol "aaa" in current context.
> $ gdb -q -batch -readnow ./a.out -ex "print aaa"
> $1 = <optimized out>
> ...

FTR, while writing the test-case I realized I couldn't reproduce this, I
probably got the system gdb and devel gdb mixed up.  Anyway, this does
reproduce with system gdb based on 12.1.  This points to the fact that we've
regressed in terms of not requiring to expand the symtab in order to find the
language of main, I suppose because we're not tracking the language of entries
in the cooked index.

For the test-case I split up the source in two CUs, to make sure that

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

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

* [Bug symtab/30656] [gdb/symtab] optimized out static handled inconsistently
  2023-07-20  5:15 [Bug symtab/30656] New: [gdb/symtab] optimized out static handled inconsistently vries at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-07-21  6:51 ` vries at gcc dot gnu.org
@ 2023-07-21 14:14 ` vries at gcc dot gnu.org
  2023-07-21 14:16 ` vries at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-07-21 14:14 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #8 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #7)
> ... .  This points to the fact that we've
> regressed in terms of not requiring to expand the symtab in order to find
> the language of main

Filed as PR30661.

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

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

* [Bug symtab/30656] [gdb/symtab] optimized out static handled inconsistently
  2023-07-20  5:15 [Bug symtab/30656] New: [gdb/symtab] optimized out static handled inconsistently vries at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2023-07-21 14:14 ` vries at gcc dot gnu.org
@ 2023-07-21 14:16 ` vries at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: vries at gcc dot gnu.org @ 2023-07-21 14:16 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #9 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #7)
> For the test-case I split up the source in two CUs, to make sure that

[ To finish my sentence ... ]

For the test-case I split up the source in two CUs, to make sure that expanding
the CU containing main does not expand the CU containing the static var.

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

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

end of thread, other threads:[~2023-07-21 14:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-20  5:15 [Bug symtab/30656] New: [gdb/symtab] optimized out static handled inconsistently vries at gcc dot gnu.org
2023-07-20  6:42 ` [Bug symtab/30656] " vries at gcc dot gnu.org
2023-07-20  6:48 ` vries at gcc dot gnu.org
2023-07-20  7:35 ` vries at gcc dot gnu.org
2023-07-20 14:43 ` vries at gcc dot gnu.org
2023-07-21  6:25 ` cvs-commit at gcc dot gnu.org
2023-07-21  6:26 ` vries at gcc dot gnu.org
2023-07-21  6:51 ` vries at gcc dot gnu.org
2023-07-21 14:14 ` vries at gcc dot gnu.org
2023-07-21 14:16 ` 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).