From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3D7A5382EA30; Thu, 27 Oct 2022 01:27:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D7A5382EA30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666834061; bh=51V/OA1S5L7AHZWk3pcpsjsZVjy+srzLQHGHZOlsrXE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=t6hxK6VDpP7y5skA2c820YY7+/l0T5DIhhr7ca7My6x91L20kMClfSZqo/gXT0kM3 FZ/TavcW1Vx7aE+C5j08L4z+WrmYmhjvD7b4tINfrHyiRCHg0pC0rDR7fe4u7ScyWW zq32eHEsEGsaSgklLDE4peArkPD0ETSU6tGYOiEA= From: "simon.marchi at polymtl dot ca" To: gcc-bugs@gcc.gnu.org Subject: [Bug debug/107414] dwarf 5 C macro support Date: Thu, 27 Oct 2022 01:27:25 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: debug X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: simon.marchi at polymtl dot ca X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: DUPLICATE X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107414 Simon Marchi changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |simon.marchi at polymtl do= t ca --- Comment #5 from Simon Marchi --- The original reproducer Ulrich gave indeed seems like what was fixed in GDB master recently. Macros in the main source file didn't work with DWARF 5.= =20 That works fine now. But he pointed me to a real-life case in gawk, where it didn't work: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29725#c2 That seems to highlight a new problem, that is the use of macros combined w= ith #line directives. I don't think that the debug info is sufficient for GDB = to figure this out. For convenience, here's a copy of what I posted on the GDB bug. --- With a simple case, it works as expected: $ cat test.c #define FOO 2 int main() { return FOO; } $ gcc test.c -g3 -O0 $ ./gdb --data-directory=3Ddata-directory -nx -q -iex "set debuginfod enabl= ed off" ./a.out -ex start -ex "info macro FOO" -batch ... Defined at /home/simark/build/binutils-gdb/gdb/test.c:1 #define FOO 2 But then if you add a line control directive, like you have for a .c file generated from a .y file: $ cat test.c #define FOO 2 #line 17 "potato.c" int main() { return FOO; } $ gcc test.c -g3 -O0 $ ./gdb --data-directory=3Ddata-directory -nx -q -iex "set debuginfod enabl= ed off" ./a.out -ex start -ex "info macro FOO" -batch ... The symbol `FOO' has no definition as a C/C++ preprocessor macro at /home/simark/build/binutils-gdb/gdb/test.c:-1 Looking at the macro debug info (my annotations after the #s): $ readelf --debug-dump=3Dmacro a.out DW_MACRO_import - offset : 0x20 # built-in macros DW_MACRO_start_file - lineno: 0 filenum: 2 # test.c DW_MACRO_start_file - lineno: 0 filenum: 3 # stdc-predef.h DW_MACRO_import - offset : 0x900 # STDC macros DW_MACRO_end_file # end of stdc-predef.h DW_MACRO_define_strp - lineno : 1 macro : FOO 2 <--- here DW_MACRO_end_file # end of test.c The line table tells GDB that the current PC is in potato.c, line 17: CU: ./test.c: File name Line number Starting address Vie= w=20=20=20 Stmt potato.c 17 0x1119=20=20= =20=20=20=20=20=20=20=20=20 x potato.c 17 0x111d=20=20= =20=20=20=20=20=20=20=20=20 x potato.c 17 0x1122=20=20= =20=20=20=20=20=20=20=20=20 x potato.c - 0x1124 But GDB has no way to figure out where this is in the macro inclusion tree,= as potato.c is never represented in there. Ideally, GDB would figure out that= we are where I maked `here`, above. Looking at the DWARF opcodes for macro, I don't really see a way to describe the #line stuff. There's only DW_MACRO_start_file, which represents the inclusion of a complete file.=