Skip to content

Commit 32df7eb

Browse files
committed
[GSYM]: Use debug line offsets during GSYM creation
This change adds support for using the `DW_AT_LLVM_stmt_sequence` attribute in the GSYM DWARF transformer. When present, the attribute is used to help locate the correct line table entries for a function.
1 parent 62ec7b8 commit 32df7eb

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)