From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0B0E2385DC1C; Sat, 25 Apr 2020 09:11:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B0E2385DC1C From: "ricky at rzhou dot org" To: gdb-prs@sourceware.org Subject: [Bug symtab/25874] New: Printing variables after noreturn functions use the wrong DWARF info Date: Sat, 25 Apr 2020 09:11:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: symtab X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ricky at rzhou dot org 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 attachments.created 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: Sat, 25 Apr 2020 09:11:55 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D25874 Bug ID: 25874 Summary: Printing variables after noreturn functions use the wrong DWARF info Product: gdb Version: HEAD Status: UNCONFIRMED Severity: normal Priority: P2 Component: symtab Assignee: unassigned at sourceware dot org Reporter: ricky at rzhou dot org Target Milestone: --- Created attachment 12490 --> https://sourceware.org/bugzilla/attachment.cgi?id=3D12490&action=3Ded= it bug1 In the following program: ``` #include #include template void no_optimize(T& v) { asm volatile("" : "+m"(v)); } void crash() { printf("test\n"); __builtin_debugtrap(); abort(); } int main(int argc, char** argv) { bool a =3D true; bool b =3D true; no_optimize(a); no_optimize(b); if (a && b) { crash(); } printf("a =3D %d, b =3D %d\n", a, b); return 0; } ``` compiled with: ``` clang++ -O1 -g -fno-exceptions -o bug1 bug1.cc ``` (see attached binary) Attempting to print "b" at the breakpoint prints an invalid value: ``` $ gdb ./bug1 (gdb) r Starting program: /tmp/bug1 test Program received signal SIGTRAP, Trace/breakpoint trap. crash () at bug1.cc:12 12 abort(); =3D> 0x000000000040115c : e8 df fe ff ff callq 0x401040 0x0000000000401161: 66 2e 0f 1f 84 00 00 00 00 00 nopw=20=20 %cs:0x0(%rax,%rax,1) 0x000000000040116b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) (gdb) up #1 0x00000000004011b8 in main (argc=3D, argv=3D) at bug1.cc:22 22 crash(); 0x00000000004011b3 : e8 98 ff ff ff callq 0x40= 1150 (gdb) p b $1 =3D 5 (gdb) info address b Symbol "b" is multi-location: Range 0x401176-0x40118a: the constant 1 Range 0x40118a-0x401198: a complex DWARF expression: 0: DW_OP_breg7 6 [$rsp] Range 0x401198-0x4011aa: a variable in $rax Range 0x4011b3-0x4011b8: a variable in $rax . (gdb) p $rax $2 =3D 5 (gdb) x/i $pc =3D> 0x4011b8: nopl 0x0(%rax,%rax,1) (gdb) disas Dump of assembler code for function main(int, char**): 0x0000000000401170 <+0>: push %rax 0x0000000000401171 <+1>: movb $0x1,0x7(%rsp) 0x0000000000401176 <+6>: movb $0x1,0x6(%rsp) 0x000000000040117b <+11>: lea 0x7(%rsp),%rdi 0x0000000000401180 <+16>: callq 0x4011c0 (bool&)> 0x0000000000401185 <+21>: lea 0x6(%rsp),%rdi 0x000000000040118a <+26>: callq 0x4011c0 (bool&)> 0x000000000040118f <+31>: movzbl 0x7(%rsp),%esi 0x0000000000401194 <+36>: mov 0x6(%rsp),%al 0x0000000000401198 <+40>: test %esi,%esi 0x000000000040119a <+42>: je 0x4011a0 0x000000000040119c <+44>: test %al,%al 0x000000000040119e <+46>: jne 0x4011b3 0x00000000004011a0 <+48>: movzbl %al,%edx 0x00000000004011a3 <+51>: mov $0x402004,%edi 0x00000000004011a8 <+56>: xor %eax,%eax 0x00000000004011aa <+58>: callq 0x401030 0x00000000004011af <+63>: xor %eax,%eax 0x00000000004011b1 <+65>: pop %rcx 0x00000000004011b2 <+66>: retq 0x00000000004011b3 <+67>: callq 0x401150 End of assembler dump. ``` Even though pc is 0x4011b8, which is out of range of "Range 0x4011b3-0x4011= b8: a variable in $rax", the value of $rax (which now contains the return value= of printf) is printed for "b". The bug seems to be that get_frame_address_in_block [0], called from places such as [1] sometimes subtracts 1 from pc when it points past the end of a function (as it can sometimes do after a call to a noreturn function). This= may make sense in some places where pc needs to point inside of a function, but= not for matching DWARF address ranges, where the end address is exclusive. [0] https://sourceware.org/git/?p=3Dbinutils-gdb.git;a=3Dblob;f=3Dgdb/frame.c;h= =3Dac1016b083fc17a51373d51b875cb03bf5bc2b56;hb=3DHEAD#l2425 [1] https://sourceware.org/git/?p=3Dbinutils-gdb.git;a=3Dblob;f=3Dgdb/dwarf2/lo= c.c;h=3D5b690ca9276ed1accd55ec03f97667a1bde7913e;hb=3DHEAD#l4426 --=20 You are receiving this mail because: You are on the CC list for the bug.=