From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2DBA23858025; Wed, 13 Apr 2022 11:36:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2DBA23858025 From: "assaiante at diag dot uniroma1.it" To: gdb-prs@sourceware.org Subject: [Bug gdb/29060] New: no local variables shown at call site despite being correctly defined in DWARF Date: Wed, 13 Apr 2022 11:36:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: gdb X-Bugzilla-Version: 11.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: assaiante at diag dot uniroma1.it X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Apr 2022 11:36:15 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29060 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 tes= t, 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=3D105261 $ cat a.c int a; static int b() { int l_5 =3D 0, l_54 =3D 5, l_362 =3D 4, i, j; short l_53 =3D 4, l_55 =3D 0; i =3D 0; for (; i < 6; i++) j =3D a ; test(l_5, l_53, l_54, l_55, l_362, i, j); } int main () { b(); } $ cat lib.c #include 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=20 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
: 400410: 48 83 ec 10 sub $0x10,%rsp 400414: 8b 05 1a 0c 20 00 mov 0x200c1a(%rip),%eax # 601034 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 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:=20 [0x0000000000400410, 0x0000000000400410): DW_OP_li= t0, DW_OP_stack_value [0x0000000000400410, 0x0000000000400410): DW_OP_li= t1, DW_OP_stack_value [0x0000000000400410, 0x0000000000400410): DW_OP_li= t2, DW_OP_stack_value [0x0000000000400410, 0x0000000000400410): DW_OP_li= t3, DW_OP_stack_value [0x0000000000400410, 0x0000000000400410): DW_OP_li= t4, DW_OP_stack_value [0x0000000000400410, 0x0000000000400410): DW_OP_li= t5, DW_OP_stack_value [0x0000000000400410, 0x000000000040043c): DW_OP_li= t6, DW_OP_stack_value) DW_AT_GNU_locviews (0x0000000c) 0x000000af: DW_TAG_variable DW_AT_abstract_origin (0x0000012c "j") DW_AT_location (0x00000050:=20 [0x0000000000400410, 0x000000000040043b): DW_OP_ad= dr 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). --=20 You are receiving this mail because: You are on the CC list for the bug.=