gas: Name the CU after the primary source file
Rename the Compilation Unit (CU) in DWARF debug info to match the primary source file, improving debug information accuracy.
This patch modifies GAS to correctly name the Compilation Unit (CU) in DWARF debug information. Previously, the CU name was taken from the first file with a line entry, which could lead to confusing names like ‘./arch/x86/include/asm/GEN-for-each-reg.h’ for the main source file. The change ensures the CU name is derived from the first top-level CPP line marker or the first input file, providing a more accurate representation of the primary source file for debugging.
- proposer
Proposes to use the filename from the first top-level CPP line marker, falling back to the first input file, to name the Compilation Unit (CU) for assembler-generated DWARF, improving debug information accuracy.
“Use the filename from the first top-level CPP line marker, falling back to the first input file, and register it before allocating file numbers from line entries. dwarf5-line-3.d now uses foo.S for the CU, matching its first CPP marker; its line entries still refer to dwarf5-line-3.S.”
In Details
This patch addresses how GAS names the Compilation Unit (CU) for DWARF debugging information when using the -g or --gdwarf-N flags. The CU name is currently derived from the first input file that has a line entry. This can lead to the CU being incorrectly named after an included header file instead of the actual source file being compiled. The proposed change uses the first top-level line marker or the primary input filename to set the CU name before line number entries are processed.
- GAS
- The GNU Assembler, part of the GNU Binutils package, responsible for translating assembly language code into machine code.
- DWARF
- A debugging data format used by many Unix and Unix-like systems to store debugging information within executable files.
- CU
- Compilation Unit, a single source file that has been compiled. In DWARF, each CU represents a translation unit and contains debugging information specific to that unit.
- CPP line marker
- A directive, typically generated by the C preprocessor (CPP), that indicates the original source file name and line number. For example,
#line 1 "foo.c".