https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113918
Bug ID: 113918 Summary: Incomplete DWARF5 debug information for anonymous unions Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug Assignee: unassigned at gcc dot gnu.org Reporter: tsqurt at outlook dot com Target Milestone: --- Created attachment 57421 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57421&action=edit example.c This is an academic finding and may not be a serious bug that urgently needs to be fixed. Fixing it may help improve the user's debugging experience. According to Programming languages — C, ISO/IEC9899:2017, Chapter 6, Section 7.2.1.13, the members of an anonymous structure or union are considered to be members of the containing structure or union. However, this feature does not seem to be reflected directly in the debug information. To check this problem, I use gcc-13.2.0 on Ubuntu 20.04.6 LTS, with the source code example.c attached. $gcc -o a.elf -std=c17 -gdwarf-5 --pedantic example.c $objdump -g a.elf ... <1><2e>: Abbrev Number: 2 (DW_TAG_union_type) <2f> DW_AT_byte_size : 4 <30> DW_AT_decl_file : 1 <31> DW_AT_decl_line : 4 <32> DW_AT_decl_column : 5 <33> DW_AT_sibling : <0x42> ... According to DWARF Debugging Information Format Version 5, Chapter 5, Section 7.1, this union type declared in ‘A’ should have a DW_AT_export_symbols attribute which indicates that member ‘x’ may be referenced as if ‘x’ is a member of ‘A’. To confirm that this issue is indeed a bug, I use GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2, and start with shell command `gdb a.elf`. $(gdb) b main Breakpoint 1 at 0x40110a: file example.c, line 12. $(gdb) run Starting program: a.elf Breakpoint 1, main () at example.c:12 $(gdb) expr x.z=20 $(gdb) expr x.y=20 gdb command line:1:2: error: ‘<U6720>’ has no member named ‘y’ Compilation failed. In comparison, member ‘z’ does not share this problem. This behavior is inconsistent with the C17 standard. I'm not sure if this problem should be down to DWARF5, gdb or gcc, but I think gcc should be capable to address this issue. Discussion: GCC has specified that the language is C17, so the debugger can deduce that ‘y’ is a member of ‘A’. But in DWARF5, debugging information is language-independent, so the debugger may not be responsible to make the above deduction based on the language C17. GCC should either generate a DW_AT_export_symbols attribute for the anonymous union or a descendant node for ‘A’. I do not know whether this is a bug or a feature. Please confirm this problem.