diff options
Diffstat (limited to 'llvm/lib/DebugInfo')
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFDie.cpp | 49 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp | 16 |
2 files changed, 54 insertions, 11 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp index 212a0c0..db5cc37 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -107,6 +107,28 @@ static DWARFDie resolveReferencedType(DWARFDie D, DWARFFormValue F) { return D.getAttributeValueAsReferencedDie(F).resolveTypeUnitReference(); } +static llvm::StringRef +prettyLanguageVersionString(const DWARFAttribute &AttrValue, + const DWARFDie &Die) { + if (AttrValue.Attr != DW_AT_language_version) + return {}; + + auto NameForm = Die.find(DW_AT_language_name); + if (!NameForm) + return {}; + + auto LName = NameForm->getAsUnsignedConstant(); + if (!LName) + return {}; + + auto LVersion = AttrValue.Value.getAsUnsignedConstant(); + if (!LVersion) + return {}; + + return llvm::dwarf::LanguageDescription( + static_cast<SourceLanguageName>(*LName), *LVersion); +} + static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, const DWARFAttribute &AttrValue, unsigned Indent, DIDumpOptions DumpOpts) { @@ -146,15 +168,28 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, } else if (std::optional<uint64_t> Val = FormValue.getAsUnsignedConstant()) Name = AttributeValueString(Attr, *Val); - if (!Name.empty()) - WithColor(OS, Color) << Name; - else if (Attr == DW_AT_decl_line || Attr == DW_AT_decl_column || - Attr == DW_AT_call_line || Attr == DW_AT_call_column || - Attr == DW_AT_language_version) { + auto DumpUnsignedConstant = [&OS, + &DumpOpts](const DWARFFormValue &FormValue) { if (std::optional<uint64_t> Val = FormValue.getAsUnsignedConstant()) OS << *Val; else FormValue.dump(OS, DumpOpts); + }; + + llvm::StringRef PrettyVersionName = + prettyLanguageVersionString(AttrValue, Die); + bool ShouldDumpRawLanguageVersion = + Attr == DW_AT_language_version && + (DumpOpts.Verbose || PrettyVersionName.empty()); + + if (!Name.empty()) + WithColor(OS, Color) << Name; + else if (Attr == DW_AT_decl_line || Attr == DW_AT_decl_column || + Attr == DW_AT_call_line || Attr == DW_AT_call_column) { + DumpUnsignedConstant(FormValue); + } else if (Attr == DW_AT_language_version) { + if (ShouldDumpRawLanguageVersion) + DumpUnsignedConstant(FormValue); } else if (Attr == DW_AT_low_pc && (FormValue.getAsAddress() == dwarf::computeTombstoneAddress(U->getAddressByteSize()))) { @@ -226,6 +261,10 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, DumpOpts.RecoverableErrorHandler(createStringError( errc::invalid_argument, "decoding address ranges: %s", toString(RangesOrError.takeError()).c_str())); + } else if (Attr == DW_AT_language_version) { + if (!PrettyVersionName.empty()) + WithColor(OS, Color) << (ShouldDumpRawLanguageVersion ? " " : "") + << PrettyVersionName; } OS << ")\n"; diff --git a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp index fa39603..a326a01 100644 --- a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp +++ b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp @@ -320,12 +320,16 @@ static void convertFunctionLineTable(OutputAggregator &Out, CUInfo &CUI, // 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. - uint64_t StmtSeqVal = dwarf::toSectionOffset(StmtSeqAttr, UINT64_MAX); - if (StmtSeqVal != UINT64_MAX) + // The `DW_AT_LLVM_stmt_sequence` attribute might be set to an invalid + // sentinel value 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 the sentinel value to the `DW_AT_LLVM_stmt_sequence` + // attribute. The sentinel value is UINT32_MAX for DWARF32 and UINT64_MAX + // for DWARF64. + const uint64_t InvalidOffset = + Die.getDwarfUnit()->getFormParams().getDwarfMaxOffset(); + uint64_t StmtSeqVal = dwarf::toSectionOffset(StmtSeqAttr, InvalidOffset); + if (StmtSeqVal != InvalidOffset) StmtSeqOffset = StmtSeqVal; } |