Skip to content

Commit

Permalink
[GSYM] Use debug line offsets during GSYM creation (llvm#129196)
Browse files Browse the repository at this point in the history
This patch introduces support for the `DW_AT_LLVM_stmt_sequence`
attribute in the GSYM DWARF transformer. With this change, the DWARF
GSYM creation process can now accurately associate debug information
with the correct functions, even when multiple functions have been
merged together.

The `macho-gsym-merged-callsites-dsym.yaml` test data is regenerated to
include the fixes in the DWARF linker
(llvm#128953) and the test is
updated to check that debug data is correctly associated for merged
functions.
  • Loading branch information
alx32 authored Mar 3, 2025
1 parent 70b95d1 commit 28fc00b
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 93 deletions.
14 changes: 13 additions & 1 deletion llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,20 @@ static void convertFunctionLineTable(OutputAggregator &Out, CUInfo &CUI,
const object::SectionedAddress SecAddress{
StartAddress, object::SectionedAddress::UndefSection};

// Attempt to retrieve DW_AT_LLVM_stmt_sequence if present.
std::optional<uint64_t> StmtSeqOffset;
if (auto StmtSeqAttr = Die.find(llvm::dwarf::DW_AT_LLVM_stmt_sequence)) {
// The `DW_AT_LLVM_stmt_sequence` attribute might be set to `UINT64_MAX`
// when it refers to an empty line sequence. In such cases, the DWARF linker
// will exclude the empty sequence from the final output and assign
// `UINT64_MAX` to the `DW_AT_LLVM_stmt_sequence` attribute.
auto StmtSeqVal = dwarf::toSectionOffset(StmtSeqAttr, UINT64_MAX);
if (StmtSeqVal != UINT32_MAX)
StmtSeqOffset = StmtSeqVal;
}

if (!CUI.LineTable->lookupAddressRange(SecAddress, RangeSize, RowVector)) {
if (!CUI.LineTable->lookupAddressRange(SecAddress, RangeSize, RowVector,
StmtSeqOffset)) {
// If we have a DW_TAG_subprogram but no line entries, fall back to using
// the DW_AT_decl_file an d DW_AT_decl_line if we have both attributes.
std::string FilePath = Die.getDeclFile(
Expand Down
Loading

0 comments on commit 28fc00b

Please sign in to comment.