public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/29060] New: no local variables shown at call site despite being correctly defined in DWARF
@ 2022-04-13 11:36 assaiante at diag dot uniroma1.it
  2022-04-13 16:01 ` [Bug gdb/29060] " simon.marchi at polymtl dot ca
  2022-04-13 16:02 ` simon.marchi at polymtl dot ca
  0 siblings, 2 replies; 3+ messages in thread
From: assaiante at diag dot uniroma1.it @ 2022-04-13 11:36 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 29060
           Summary: no local variables shown at call site despite being
                    correctly defined in DWARF
           Product: gdb
           Version: 11.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: assaiante at diag dot uniroma1.it
  Target Milestone: ---

In this minimized C example, variables i and j, defined within the scope of the
function b, have no value being displayed upon the call of the function test,
which is defined in an external module. To reproduce the issue, the program
should be compiled with a recent version of gcc using -O2 or -O3 as
optimization level. We believe this may be a bug in gdb since debugging the
same executable file in lldb shows us the correct values.

We provide an initial analysis below on x64. We tested gdb 11.2 and 10.1.

This gcc bug report may also be of interest:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105261

$ cat a.c
int a;
static int b()
{
    int l_5 = 0,  l_54 = 5,  l_362 = 4,  i, j;
    short l_53 = 4,  l_55 = 0;
    i = 0;
    for (; i < 6; i++)
        j = a ;
    test(l_5, l_53, l_54, l_55, l_362, i, j);
}
int main ()
{
    b();
}

$ cat lib.c
#include <stdio.h>

void test(int l_5, int l_53, int l_54, int l_55, int l_362, int i, int j) {
    printf("%d %d %d %d %d %d %d", l_5, l_53, l_54, l_55, l_362, i, j);
}

GCC and GDB version:
- GNU gdb (GDB) 11.2
- gcc (GCC) 12.0.0 20211227 (experimental) - commit id: 500d3f0a302

GDB trace:
$ gcc -O2 -g a.c lib.c -o opt
$ gdb -q opt
Reading symbols from opt...
(gdb) b 9
Breakpoint 1 at 0x400410: file a.c, line 9.
(gdb) r
Starting program: /tmp/opt 

Breakpoint 1, main () at a.c:9
9           test(l_5, l_53, l_54, l_55, l_362, i, j);
(gdb) info loc
No locals.

ASM at -O2:
0000000000400410 <main>:
  400410:       48 83 ec 10             sub    $0x10,%rsp
  400414:       8b 05 1a 0c 20 00       mov    0x200c1a(%rip),%eax        #
601034 <a>
  40041a:       31 c9                   xor    %ecx,%ecx
  40041c:       31 ff                   xor    %edi,%edi
  40041e:       41 b9 06 00 00 00       mov    $0x6,%r9d
  400424:       41 b8 04 00 00 00       mov    $0x4,%r8d
  40042a:       ba 05 00 00 00          mov    $0x5,%edx
  40042f:       be 04 00 00 00          mov    $0x4,%esi
  400434:       50                      push   %rax
  400435:       31 c0                   xor    %eax,%eax
  400437:       e8 04 01 00 00          callq  400540 <test>
  40043c:       31 c0                   xor    %eax,%eax
  40043e:       48 83 c4 18             add    $0x18,%rsp
  400442:       c3                      retq


DWARF info at -O2:
0x000000a2:         DW_TAG_variable
                      DW_AT_abstract_origin     (0x00000124 "i")
                      DW_AT_location    (0x0000001a: 
                         [0x0000000000400410, 0x0000000000400410): DW_OP_lit0,
DW_OP_stack_value
                         [0x0000000000400410, 0x0000000000400410): DW_OP_lit1,
DW_OP_stack_value
                         [0x0000000000400410, 0x0000000000400410): DW_OP_lit2,
DW_OP_stack_value
                         [0x0000000000400410, 0x0000000000400410): DW_OP_lit3,
DW_OP_stack_value
                         [0x0000000000400410, 0x0000000000400410): DW_OP_lit4,
DW_OP_stack_value
                         [0x0000000000400410, 0x0000000000400410): DW_OP_lit5,
DW_OP_stack_value
                         [0x0000000000400410, 0x000000000040043c): DW_OP_lit6,
DW_OP_stack_value)
                      DW_AT_GNU_locviews        (0x0000000c)

0x000000af:         DW_TAG_variable
                      DW_AT_abstract_origin     (0x0000012c "j")
                      DW_AT_location    (0x00000050: 
                         [0x0000000000400410, 0x000000000040043b): DW_OP_addr
0x601034)
                      DW_AT_GNU_locviews        (0x0000004e)


>From DWARF info we can see how variables i and j have correct location
definition but still no locals are available during debugging. As we can see
from the assembly of function b, the call instruction to function test is at
address 400437 and it is included in both the ranges of variable i
[0x0000000000400410, 0x000000000040043c) and variable j [0x0000000000400410,
0x000000000040043b).

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

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

* [Bug gdb/29060] no local variables shown at call site despite being correctly defined in DWARF
  2022-04-13 11:36 [Bug gdb/29060] New: no local variables shown at call site despite being correctly defined in DWARF assaiante at diag dot uniroma1.it
@ 2022-04-13 16:01 ` simon.marchi at polymtl dot ca
  2022-04-13 16:02 ` simon.marchi at polymtl dot ca
  1 sibling, 0 replies; 3+ messages in thread
From: simon.marchi at polymtl dot ca @ 2022-04-13 16:01 UTC (permalink / raw)
  To: gdb-prs

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

Simon Marchi <simon.marchi at polymtl dot ca> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simon.marchi at polymtl dot ca

--- Comment #1 from Simon Marchi <simon.marchi at polymtl dot ca> ---
Probably related to the fact that the function is inlined, and the abstract die
hierarchy doesn't match the concrete die hierarchy.

The concrete hierarchy:

0x00000078:     DW_TAG_inlined_subroutine
                  DW_AT_abstract_origin [DW_FORM_ref4]  (0x000000f4 "b")
                  DW_AT_entry_pc [DW_FORM_addr] (0x0000000000401054)
                  DW_AT_GNU_entry_view [DW_FORM_data1]  (0x01)
                  DW_AT_ranges [DW_FORM_sec_offset]     (0x00000000
                     [0x0000000000401054, 0x0000000000401054)
                     [0x0000000000401058, 0x0000000000401080))
                  DW_AT_call_file [DW_FORM_data1]      
("/home/smarchi/build/binutils-gdb/gdb/a.c")
                  DW_AT_call_line [DW_FORM_data1]       (13)
                  DW_AT_call_column [DW_FORM_data1]     (0x05)

0x0000008d:       DW_TAG_lexical_block
                    DW_AT_ranges [DW_FORM_sec_offset]   (0x00000000
                       [0x0000000000401054, 0x0000000000401054)
                       [0x0000000000401058, 0x0000000000401080))

0x00000092:         DW_TAG_variable
                      DW_AT_abstract_origin [DW_FORM_ref4]      (0x00000103
"l_5")

0x00000097:         DW_TAG_variable
                      DW_AT_abstract_origin [DW_FORM_ref4]      (0x0000010f
"l_54")

0x0000009c:         DW_TAG_variable
                      DW_AT_abstract_origin [DW_FORM_ref4]      (0x0000011b
"l_362")

0x000000a1:         DW_TAG_variable
                      DW_AT_abstract_origin [DW_FORM_ref4]      (0x00000127
"i")
                      DW_AT_location [DW_FORM_sec_offset]       (0x0000000e: 


The concrete hierarchy:

0x000000f4:   DW_TAG_subprogram
                DW_AT_name [DW_FORM_string]     ("b")
                DW_AT_decl_file [DW_FORM_data1]
("/home/smarchi/build/binutils-gdb/gdb/a.c")
                DW_AT_decl_line [DW_FORM_data1] (2)
                DW_AT_decl_column [DW_FORM_data1]       (0x0c)
                DW_AT_type [DW_FORM_ref4]       (0x0000003d "int")
                DW_AT_inline [DW_FORM_data1]    (DW_INL_inlined)
                DW_AT_sibling [DW_FORM_ref4]    (0x00000162)

0x00000103:     DW_TAG_variable
                  DW_AT_name [DW_FORM_string]   ("l_5")
                  DW_AT_decl_file [DW_FORM_data1]      
("/home/smarchi/build/binutils-gdb/gdb/a.c")
                  DW_AT_decl_line [DW_FORM_data1]       (4)
                  DW_AT_decl_column [DW_FORM_data1]     (0x09)
                  DW_AT_type [DW_FORM_ref4]     (0x0000003d "int")

0x0000010f:     DW_TAG_variable
                  DW_AT_name [DW_FORM_strp]     ("l_54")
                  DW_AT_decl_file [DW_FORM_data1]      
("/home/smarchi/build/binutils-gdb/gdb/a.c")
                  DW_AT_decl_line [DW_FORM_data1]       (4)
                  DW_AT_decl_column [DW_FORM_data1]     (0x13)
                  DW_AT_type [DW_FORM_ref4]     (0x0000003d "int")

0x0000011b:     DW_TAG_variable
                  DW_AT_name [DW_FORM_strp]     ("l_362")
                  DW_AT_decl_file [DW_FORM_data1]      
("/home/smarchi/build/binutils-gdb/gdb/a.c")
                  DW_AT_decl_line [DW_FORM_data1]       (4)
                  DW_AT_decl_column [DW_FORM_data1]     (0x1e)
                  DW_AT_type [DW_FORM_ref4]     (0x0000003d "int")

0x00000127:     DW_TAG_variable
                  DW_AT_name [DW_FORM_string]   ("i")
                  DW_AT_decl_file [DW_FORM_data1]      
("/home/smarchi/build/binutils-gdb/gdb/a.c")
                  DW_AT_decl_line [DW_FORM_data1]       (4)
                  DW_AT_decl_column [DW_FORM_data1]     (0x2a)
                  DW_AT_type [DW_FORM_ref4]     (0x0000003d "int")


The concrete hierarchy contains a lexical block the abstract hierarchy doesn't.

Related:

https://sourceware.org/bugzilla/show_bug.cgi?id=25695
http://lists.dwarfstd.org/pipermail/dwarf-discuss-dwarfstd.org/2017-September/004394.html

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

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

* [Bug gdb/29060] no local variables shown at call site despite being correctly defined in DWARF
  2022-04-13 11:36 [Bug gdb/29060] New: no local variables shown at call site despite being correctly defined in DWARF assaiante at diag dot uniroma1.it
  2022-04-13 16:01 ` [Bug gdb/29060] " simon.marchi at polymtl dot ca
@ 2022-04-13 16:02 ` simon.marchi at polymtl dot ca
  1 sibling, 0 replies; 3+ messages in thread
From: simon.marchi at polymtl dot ca @ 2022-04-13 16:02 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 from Simon Marchi <simon.marchi at polymtl dot ca> ---
Sorry, I said "The concrete hierarchy" twice.  The second should say
"abstract".

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

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

end of thread, other threads:[~2022-04-13 16:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-13 11:36 [Bug gdb/29060] New: no local variables shown at call site despite being correctly defined in DWARF assaiante at diag dot uniroma1.it
2022-04-13 16:01 ` [Bug gdb/29060] " simon.marchi at polymtl dot ca
2022-04-13 16:02 ` simon.marchi at polymtl dot ca

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