Skip to content

Commit 46369f8

Browse files
alx32jph-13
authored andcommitted
[GSYM] Use debug line offsets during GSYM creation (llvm#129196)
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.
1 parent 1a15231 commit 46369f8

File tree

2 files changed

+102
-93
lines changed

2 files changed

+102
-93
lines changed

llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,20 @@ static void convertFunctionLineTable(OutputAggregator &Out, CUInfo &CUI,
317317
const object::SectionedAddress SecAddress{
318318
StartAddress, object::SectionedAddress::UndefSection};
319319

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

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

0 commit comments

Comments
 (0)