public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/107414] New: dwarf 5 C macro support
@ 2022-10-26  9:25 drepper.fsp+rhbz at gmail dot com
  2022-10-26  9:34 ` [Bug debug/107414] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: drepper.fsp+rhbz at gmail dot com @ 2022-10-26  9:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107414

            Bug ID: 107414
           Summary: dwarf 5 C macro support
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: drepper.fsp+rhbz at gmail dot com
  Target Milestone: ---

Take this code:

union node {
  struct {
    int a;
  } l;
} x;

#define memory l.a

int main()
{
  return x.memory;
}

When compiled with -gdwarf-4 -g3 and run in gdb, it is possible to use

Breakpoint 1, main () at u.c:11
11        return x.memory;
(gdb) p x.memory
$1 = 0

When instead -gdwarf-5 -g3 is used 'memory' is not known to be a macro and one
gets

Breakpoint 1, main () at u.c:11
11        return x.memory;
(gdb) p x.memory
There is no member named memory.

Shouldn't the Dwarf 5 data be a superset of what Dwarf 4 provides?

This is not new in the trunk/13 version.  12.1 fails as well and likely prior
versions, too.

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

* [Bug debug/107414] dwarf 5 C macro support
  2022-10-26  9:25 [Bug debug/107414] New: dwarf 5 C macro support drepper.fsp+rhbz at gmail dot com
@ 2022-10-26  9:34 ` jakub at gcc dot gnu.org
  2022-10-26 10:00 ` drepper.fsp+rhbz at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-10-26  9:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107414

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Just skimming -dA -gdwarf-4 -g3 and -dA -gdwarf-5 -g3 assembly differences, I
don't see anything wrong on the compiler side.  So, I think it is much more
likely this is a gdb bug.

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

* [Bug debug/107414] dwarf 5 C macro support
  2022-10-26  9:25 [Bug debug/107414] New: dwarf 5 C macro support drepper.fsp+rhbz at gmail dot com
  2022-10-26  9:34 ` [Bug debug/107414] " jakub at gcc dot gnu.org
@ 2022-10-26 10:00 ` drepper.fsp+rhbz at gmail dot com
  2022-10-26 11:37 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: drepper.fsp+rhbz at gmail dot com @ 2022-10-26 10:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107414

--- Comment #2 from Ulrich Drepper <drepper.fsp+rhbz at gmail dot com> ---
OK, I submitted:

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

Let's see what they say.

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

* [Bug debug/107414] dwarf 5 C macro support
  2022-10-26  9:25 [Bug debug/107414] New: dwarf 5 C macro support drepper.fsp+rhbz at gmail dot com
  2022-10-26  9:34 ` [Bug debug/107414] " jakub at gcc dot gnu.org
  2022-10-26 10:00 ` drepper.fsp+rhbz at gmail dot com
@ 2022-10-26 11:37 ` pinskia at gcc dot gnu.org
  2022-10-26 22:05 ` drepper.fsp+rhbz at gmail dot com
  2022-10-27  1:27 ` simon.marchi at polymtl dot ca
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-26 11:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107414

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 107012

*** This bug has been marked as a duplicate of bug 107012 ***

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

* [Bug debug/107414] dwarf 5 C macro support
  2022-10-26  9:25 [Bug debug/107414] New: dwarf 5 C macro support drepper.fsp+rhbz at gmail dot com
                   ` (2 preceding siblings ...)
  2022-10-26 11:37 ` pinskia at gcc dot gnu.org
@ 2022-10-26 22:05 ` drepper.fsp+rhbz at gmail dot com
  2022-10-27  1:27 ` simon.marchi at polymtl dot ca
  4 siblings, 0 replies; 6+ messages in thread
From: drepper.fsp+rhbz at gmail dot com @ 2022-10-26 22:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107414

--- Comment #4 from Ulrich Drepper <drepper.fsp+rhbz at gmail dot com> ---
Actually, Jakub was right.  This is a gdb issue.  The gdb maintainers pointed
me to the trunk version and this indeed works with this simple code sequence. 
There might have been a bug as in 107012 but even after that fix gdb didn't
handle the dwarf data correctly before a recent commit.

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

* [Bug debug/107414] dwarf 5 C macro support
  2022-10-26  9:25 [Bug debug/107414] New: dwarf 5 C macro support drepper.fsp+rhbz at gmail dot com
                   ` (3 preceding siblings ...)
  2022-10-26 22:05 ` drepper.fsp+rhbz at gmail dot com
@ 2022-10-27  1:27 ` simon.marchi at polymtl dot ca
  4 siblings, 0 replies; 6+ messages in thread
From: simon.marchi at polymtl dot ca @ 2022-10-27  1:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107414

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

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

--- Comment #5 from Simon Marchi <simon.marchi at polymtl dot ca> ---
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. 
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=29725#c2

That seems to highlight a new problem, that is the use of macros combined with
#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=data-directory -nx -q -iex "set debuginfod enabled
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=data-directory -nx -q -iex "set debuginfod enabled
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=macro 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    View   
Stmt
potato.c                                      17              0x1119           
   x
potato.c                                      17              0x111d           
   x
potato.c                                      17              0x1122           
   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.

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

end of thread, other threads:[~2022-10-27  1:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-26  9:25 [Bug debug/107414] New: dwarf 5 C macro support drepper.fsp+rhbz at gmail dot com
2022-10-26  9:34 ` [Bug debug/107414] " jakub at gcc dot gnu.org
2022-10-26 10:00 ` drepper.fsp+rhbz at gmail dot com
2022-10-26 11:37 ` pinskia at gcc dot gnu.org
2022-10-26 22:05 ` drepper.fsp+rhbz at gmail dot com
2022-10-27  1:27 ` 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).