72 LLVM_YAML_DECLARE_BITSET_TRAITS(
LineFlags)
85 namespace CodeViewYAML {
92 virtual void map(IO &IO) = 0;
93 virtual std::shared_ptr<DebugSubsection>
107 YAMLChecksumsSubsection()
110 void map(IO &IO)
override;
111 std::shared_ptr<DebugSubsection>
118 std::vector<SourceFileChecksumEntry> Checksums;
124 void map(IO &IO)
override;
125 std::shared_ptr<DebugSubsection>
137 YAMLInlineeLinesSubsection()
140 void map(IO &IO)
override;
141 std::shared_ptr<DebugSubsection>
153 YAMLCrossModuleExportsSubsection()
156 void map(IO &IO)
override;
157 std::shared_ptr<DebugSubsection>
163 std::vector<CrossModuleExport> Exports;
167 YAMLCrossModuleImportsSubsection()
170 void map(IO &IO)
override;
171 std::shared_ptr<DebugSubsection>
178 std::vector<YAMLCrossModuleImport> Imports;
184 void map(IO &IO)
override;
185 std::shared_ptr<DebugSubsection>
191 std::vector<CodeViewYAML::SymbolRecord>
Symbols;
195 YAMLStringTableSubsection()
198 void map(IO &IO)
override;
199 std::shared_ptr<DebugSubsection>
205 std::vector<StringRef> Strings;
209 YAMLFrameDataSubsection()
212 void map(IO &IO)
override;
213 std::shared_ptr<DebugSubsection>
220 std::vector<YAMLFrameData> Frames;
224 YAMLCoffSymbolRVASubsection()
227 void map(IO &IO)
override;
228 std::shared_ptr<DebugSubsection>
234 std::vector<uint32_t> RVAs;
239 void ScalarBitSetTraits<LineFlags>::bitset(IO &io,
LineFlags &Flags) {
241 io.enumFallback<Hex16>(Flags);
244 void ScalarEnumerationTraits<FileChecksumKind>::enumeration(
254 StringRef Bytes(reinterpret_cast<const char *>(Value.
Bytes.data()),
262 Value.
Bytes.assign(H.begin(), H.end());
267 IO.mapRequired(
"Offset", Obj.
Offset);
268 IO.mapRequired(
"LineStart", Obj.
LineStart);
270 IO.mapRequired(
"EndDelta", Obj.
EndDelta);
275 IO.mapRequired(
"EndColumn", Obj.
EndColumn);
279 IO.mapRequired(
"FileName", Obj.
FileName);
280 IO.mapRequired(
"Lines", Obj.
Lines);
281 IO.mapRequired(
"Columns", Obj.
Columns);
285 IO.mapRequired(
"LocalId", Obj.
Local);
286 IO.mapRequired(
"GlobalId", Obj.
Global);
292 IO.mapRequired(
"Imports", Obj.
ImportIds);
297 IO.mapRequired(
"FileName", Obj.
FileName);
298 IO.mapRequired(
"Kind", Obj.
Kind);
303 IO.mapRequired(
"FileName", Obj.
FileName);
305 IO.mapRequired(
"Inlinee", Obj.
Inlinee);
310 IO.mapRequired(
"CodeSize", Obj.
CodeSize);
311 IO.mapRequired(
"FrameFunc", Obj.
FrameFunc);
312 IO.mapRequired(
"LocalSize", Obj.
LocalSize);
316 IO.mapOptional(
"RvaStart", Obj.
RvaStart);
320 void YAMLChecksumsSubsection::map(IO &IO) {
321 IO.mapTag(
"!FileChecksums",
true);
322 IO.mapRequired(
"Checksums", Checksums);
325 void YAMLLinesSubsection::map(IO &IO) {
326 IO.mapTag(
"!Lines",
true);
327 IO.mapRequired(
"CodeSize",
Lines.CodeSize);
329 IO.mapRequired(
"Flags",
Lines.Flags);
330 IO.mapRequired(
"RelocOffset",
Lines.RelocOffset);
331 IO.mapRequired(
"RelocSegment",
Lines.RelocSegment);
332 IO.mapRequired(
"Blocks",
Lines.Blocks);
335 void YAMLInlineeLinesSubsection::map(IO &IO) {
336 IO.mapTag(
"!InlineeLines",
true);
337 IO.mapRequired(
"HasExtraFiles",
InlineeLines.HasExtraFiles);
341 void YAMLCrossModuleExportsSubsection::map(IO &IO) {
342 IO.mapTag(
"!CrossModuleExports",
true);
343 IO.mapOptional(
"Exports", Exports);
346 void YAMLCrossModuleImportsSubsection::map(IO &IO) {
347 IO.mapTag(
"!CrossModuleImports",
true);
348 IO.mapOptional(
"Imports", Imports);
351 void YAMLSymbolsSubsection::map(IO &IO) {
352 IO.mapTag(
"!Symbols",
true);
353 IO.mapRequired(
"Records",
Symbols);
356 void YAMLStringTableSubsection::map(IO &IO) {
357 IO.mapTag(
"!StringTable",
true);
358 IO.mapRequired(
"Strings", Strings);
361 void YAMLFrameDataSubsection::map(IO &IO) {
362 IO.mapTag(
"!FrameData",
true);
363 IO.mapRequired(
"Frames", Frames);
366 void YAMLCoffSymbolRVASubsection::map(IO &IO) {
367 IO.mapTag(
"!COFFSymbolRVAs",
true);
368 IO.mapRequired(
"RVAs", RVAs);
373 if (!IO.outputting()) {
374 if (IO.mapTag(
"!FileChecksums")) {
375 auto SS = std::make_shared<YAMLChecksumsSubsection>();
377 }
else if (IO.mapTag(
"!Lines")) {
378 Subsection.
Subsection = std::make_shared<YAMLLinesSubsection>();
379 }
else if (IO.mapTag(
"!InlineeLines")) {
380 Subsection.
Subsection = std::make_shared<YAMLInlineeLinesSubsection>();
381 }
else if (IO.mapTag(
"!CrossModuleExports")) {
383 std::make_shared<YAMLCrossModuleExportsSubsection>();
384 }
else if (IO.mapTag(
"!CrossModuleImports")) {
386 std::make_shared<YAMLCrossModuleImportsSubsection>();
387 }
else if (IO.mapTag(
"!Symbols")) {
388 Subsection.
Subsection = std::make_shared<YAMLSymbolsSubsection>();
389 }
else if (IO.mapTag(
"!StringTable")) {
390 Subsection.
Subsection = std::make_shared<YAMLStringTableSubsection>();
391 }
else if (IO.mapTag(
"!FrameData")) {
392 Subsection.
Subsection = std::make_shared<YAMLFrameDataSubsection>();
393 }
else if (IO.mapTag(
"!COFFSymbolRVAs")) {
394 Subsection.
Subsection = std::make_shared<YAMLCoffSymbolRVASubsection>();
402 std::shared_ptr<DebugSubsection> YAMLChecksumsSubsection::toCodeViewSubsection(
406 auto Result = std::make_shared<DebugChecksumsSubsection>(*SC.
strings());
407 for (
const auto &CS : Checksums) {
408 Result->addChecksum(CS.FileName, CS.Kind, CS.ChecksumBytes.Bytes);
413 std::shared_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
419 Result->setCodeSize(
Lines.CodeSize);
420 Result->setRelocationAddress(
Lines.RelocSegment,
Lines.RelocOffset);
421 Result->setFlags(
Lines.Flags);
422 for (
const auto &LC :
Lines.Blocks) {
423 Result->createBlock(LC.FileName);
424 if (Result->hasColumnInfo()) {
425 for (
const auto &Item :
zip(LC.Lines, LC.Columns)) {
426 auto &L = std::get<0>(Item);
427 auto &
C = std::get<1>(Item);
429 Result->addLineAndColumnInfo(L.Offset,
430 LineInfo(L.LineStart, LE, L.IsStatement),
431 C.StartColumn, C.EndColumn);
434 for (
const auto &L : LC.Lines) {
436 Result->addLineInfo(L.Offset,
LineInfo(L.LineStart, LE, L.IsStatement));
443 std::shared_ptr<DebugSubsection>
444 YAMLInlineeLinesSubsection::toCodeViewSubsection(
448 auto Result = std::make_shared<DebugInlineeLinesSubsection>(
452 Result->addInlineSite(
TypeIndex(Site.Inlinee), Site.FileName,
457 for (
auto EF : Site.ExtraFiles) {
458 Result->addExtraFile(EF);
464 std::shared_ptr<DebugSubsection>
465 YAMLCrossModuleExportsSubsection::toCodeViewSubsection(
468 auto Result = std::make_shared<DebugCrossModuleExportsSubsection>();
469 for (
const auto &M : Exports)
470 Result->addMapping(M.Local, M.Global);
474 std::shared_ptr<DebugSubsection>
475 YAMLCrossModuleImportsSubsection::toCodeViewSubsection(
481 std::make_shared<DebugCrossModuleImportsSubsection>(*SC.
strings());
482 for (
const auto &M : Imports) {
483 for (
const auto Id : M.ImportIds)
484 Result->addImport(M.ModuleName,
Id);
489 std::shared_ptr<DebugSubsection> YAMLSymbolsSubsection::toCodeViewSubsection(
492 auto Result = std::make_shared<DebugSymbolsSubsection>();
493 for (
const auto &Sym :
Symbols)
499 std::shared_ptr<DebugSubsection>
500 YAMLStringTableSubsection::toCodeViewSubsection(
503 auto Result = std::make_shared<DebugStringTableSubsection>();
504 for (
const auto &Str : this->Strings)
509 std::shared_ptr<DebugSubsection> YAMLFrameDataSubsection::toCodeViewSubsection(
514 auto Result = std::make_shared<DebugFrameDataSubsection>(
true);
515 for (
const auto &YF : Frames) {
526 Result->addFrameData(F);
531 std::shared_ptr<DebugSubsection>
532 YAMLCoffSymbolRVASubsection::toCodeViewSubsection(
535 auto Result = std::make_shared<DebugSymbolRVASubsection>();
536 for (
const auto &RVA : RVAs)
546 return ExpectedString.takeError();
566 YAMLChecksumsSubsection::fromCodeViewSubsection(
569 auto Result = std::make_shared<YAMLChecksumsSubsection>();
571 for (
const auto &CS : FC) {
574 return ConvertedCS.takeError();
575 Result->Checksums.push_back(*ConvertedCS);
581 YAMLLinesSubsection::fromCodeViewSubsection(
585 auto Result = std::make_shared<YAMLLinesSubsection>();
590 for (
const auto &L : Lines) {
592 auto EF =
getFileName(Strings, Checksums, L.NameIndex);
594 return EF.takeError();
596 if (Lines.hasColumnInfo()) {
597 for (
const auto &
C : L.Columns) {
604 for (
const auto &LN : L.LineNumbers) {
611 Block.
Lines.push_back(SLE);
613 Result->Lines.Blocks.push_back(Block);
619 YAMLInlineeLinesSubsection::fromCodeViewSubsection(
623 auto Result = std::make_shared<YAMLInlineeLinesSubsection>();
626 for (
const auto &IL : Lines) {
628 auto ExpF =
getFileName(Strings, Checksums, IL.Header->FileID);
630 return ExpF.takeError();
632 Site.
Inlinee = IL.Header->Inlinee.getIndex();
634 if (Lines.hasExtraFiles()) {
635 for (
const auto EF : IL.ExtraFiles) {
638 return ExpF2.takeError();
642 Result->InlineeLines.Sites.push_back(Site);
648 YAMLCrossModuleExportsSubsection::fromCodeViewSubsection(
650 auto Result = std::make_shared<YAMLCrossModuleExportsSubsection>();
651 Result->Exports.assign(Exports.
begin(), Exports.
end());
656 YAMLCrossModuleImportsSubsection::fromCodeViewSubsection(
659 auto Result = std::make_shared<YAMLCrossModuleImportsSubsection>();
660 for (
const auto &CMI : Imports) {
662 auto ExpectedStr = Strings.
getString(CMI.Header->ModuleNameOffset);
664 return ExpectedStr.takeError();
666 YCMI.
ImportIds.assign(CMI.Imports.begin(), CMI.Imports.end());
667 Result->Imports.push_back(YCMI);
673 YAMLSymbolsSubsection::fromCodeViewSubsection(
675 auto Result = std::make_shared<YAMLSymbolsSubsection>();
676 for (
const auto &Sym : Symbols) {
681 "Invalid CodeView Symbol Record in SymbolRecord " 682 "subsection of .debug$S while converting to YAML!"),
685 Result->Symbols.push_back(*S);
691 YAMLStringTableSubsection::fromCodeViewSubsection(
693 auto Result = std::make_shared<YAMLStringTableSubsection>();
697 if (
auto EC = Reader.readCString(S))
698 return std::move(
EC);
700 while (Reader.bytesRemaining() > 0) {
701 if (
auto EC = Reader.readCString(S))
702 return std::move(
EC);
703 Result->Strings.push_back(S);
709 YAMLFrameDataSubsection::fromCodeViewSubsection(
712 auto Result = std::make_shared<YAMLFrameDataSubsection>();
713 for (
const auto &
F : Frames) {
727 make_error<CodeViewError>(
729 "Could not find string for string id while mapping FrameData!"),
732 Result->Frames.push_back(YF);
738 YAMLCoffSymbolRVASubsection::fromCodeViewSubsection(
740 auto Result = std::make_shared<YAMLCoffSymbolRVASubsection>();
741 for (
const auto &RVA : Section) {
742 Result->RVAs.push_back(RVA);
751 std::vector<std::shared_ptr<DebugSubsection>> Result;
752 if (Subsections.
empty())
753 return std::move(Result);
755 for (
const auto &SS : Subsections) {
756 std::shared_ptr<DebugSubsection> CVS;
757 CVS = SS.Subsection->toCodeViewSubsection(Allocator, SC);
759 Result.push_back(std::move(CVS));
761 return std::move(Result);
767 SubsectionConversionVisitor() =
default;
794 Error SubsectionConversionVisitor::visitUnknown(
799 Error SubsectionConversionVisitor::visitLines(
801 auto Result = YAMLLinesSubsection::fromCodeViewSubsection(
804 return Result.takeError();
809 Error SubsectionConversionVisitor::visitFileChecksums(
812 auto Result = YAMLChecksumsSubsection::fromCodeViewSubsection(State.
strings(),
815 return Result.takeError();
820 Error SubsectionConversionVisitor::visitInlineeLines(
823 auto Result = YAMLInlineeLinesSubsection::fromCodeViewSubsection(
826 return Result.takeError();
831 Error SubsectionConversionVisitor::visitCrossModuleExports(
835 YAMLCrossModuleExportsSubsection::fromCodeViewSubsection(Exports);
837 return Result.takeError();
842 Error SubsectionConversionVisitor::visitCrossModuleImports(
845 auto Result = YAMLCrossModuleImportsSubsection::fromCodeViewSubsection(
848 return Result.takeError();
853 Error SubsectionConversionVisitor::visitStringTable(
856 auto Result = YAMLStringTableSubsection::fromCodeViewSubsection(Strings);
858 return Result.takeError();
863 Error SubsectionConversionVisitor::visitSymbols(
865 auto Result = YAMLSymbolsSubsection::fromCodeViewSubsection(Symbols);
867 return Result.takeError();
872 Error SubsectionConversionVisitor::visitFrameData(
875 YAMLFrameDataSubsection::fromCodeViewSubsection(State.
strings(), Frames);
877 return Result.takeError();
882 Error SubsectionConversionVisitor::visitCOFFSymbolRVAs(
884 auto Result = YAMLCoffSymbolRVASubsection::fromCodeViewSubsection(RVAs);
886 return Result.takeError();
894 SubsectionConversionVisitor V;
896 return std::move(
EC);
901 std::vector<YAMLDebugSubsection>
914 std::vector<YAMLDebugSubsection> Result;
916 for (
const auto &SS : Subsections) {
917 auto YamlSS = Err(YAMLDebugSubsection::fromCodeViewSubection(SC, SS));
918 Result.push_back(YamlSS);
936 for (
const auto &SS : Sections) {
940 auto Result = SS.Subsection->toCodeViewSubsection(Allocator, SC);
942 std::static_pointer_cast<DebugStringTableSubsection>(Result));
948 for (
const auto &SS : Sections) {
952 auto Result = SS.Subsection->toCodeViewSubsection(Allocator, SC);
954 std::static_pointer_cast<DebugChecksumsSubsection>(Result));
std::vector< SourceLineEntry > Lines
This class represents lattice values for constants.
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
Data in the SUBSEC_FRAMEDATA subection.
uint32_t getStartLine() const
support::ulittle32_t RvaStart
Helper for check-and-exit error handling.
std::vector< YAMLDebugSubsection > fromDebugS(ArrayRef< uint8_t > Data, const codeview::StringsAndChecksumsRef &SC)
Expected< StringRef > getString(uint32_t Offset) const
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation.
support::ulittle16_t PrologSize
support::ulittle32_t CodeSize
HexFormattedString ChecksumBytes
support::ulittle32_t MaxStackSize
const DebugStringTableSubsectionRef & strings() const
Tagged union holding either a T or a Error.
uint32_t getLineDelta() const
void initializeStringsAndChecksums(ArrayRef< YAMLDebugSubsection > Sections, codeview::StringsAndChecksums &SC)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static Expected< SourceFileChecksumEntry > convertOneChecksum(const DebugStringTableSubsectionRef &Strings, const FileChecksumEntry &CS)
const FileChecksumArray & getArray() const
static Expected< StringRef > getFileName(const DebugStringTableSubsectionRef &Strings, const DebugChecksumsSubsectionRef &Checksums, uint32_t FileID)
support::ulittle32_t ParamsSize
Allocate memory in an ever growing pool, as if by bump-pointer.
support::ulittle32_t Flags
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&... args)
zip iterator for two or more iteratable types.
static Expected< SymbolRecord > fromCodeViewSymbol(codeview::CVSymbol Symbol)
std::vector< uint32_t > ImportIds
std::vector< SourceColumnEntry > Columns
support::ulittle32_t LocalSize
bool hasExtraFiles() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setChecksums(const ChecksumsPtr &CP)
const ChecksumsPtr & checksums() const
void setStrings(const StringsPtr &SP)
static const char *const Magic
const StringsPtr & strings() const
static ErrorSuccess success()
Create a success value.
BinaryStreamRef getBuffer() const
CHAIN = SC CHAIN, Imm128 - System call.
std::shared_ptr< detail::YAMLSubsectionBase > Subsection
Error visitDebugSubsection(const DebugSubsectionRecord &R, DebugSubsectionVisitor &V, const StringsAndChecksumsRef &State)
Represents a read-only view of a CodeView string table.
Error joinErrors(Error E1, Error E2)
Concatenate errors.
support::ulittle32_t Local
uint32_t bytesRemaining() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Iterator at(uint32_t Offset) const
given an offset into the array's underlying stream, return an iterator to the record at that offset...
ArrayRef< uint8_t > Checksum
LLVM Value Representation.
const DebugChecksumsSubsectionRef & checksums() const
Lightweight error class with error context and mandatory checking.
support::ulittle32_t FrameFunc
This class implements an extremely fast bulk output stream that can only output to a stream...
Provides read only access to a subclass of BinaryStream.
StringRef - Represent a constant reference to a string, i.e.
const LineFragmentHeader * header() const
bool hasChecksums() const
std::string toHex(StringRef Input, bool LowerCase=false)
Convert buffer Input to its hexadecimal representation.
Expected< std::vector< std::shared_ptr< codeview::DebugSubsection > > > toCodeViewSubsectionList(BumpPtrAllocator &Allocator, ArrayRef< YAMLDebugSubsection > Subsections, const codeview::StringsAndChecksums &SC)
codeview::FileChecksumKind Kind
YAMLSubsectionBase(DebugSubsectionKind Kind)
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...
support::ulittle32_t Global
bool empty() const
empty - Check if the array is empty.
support::ulittle16_t SavedRegsSize
std::vector< StringRef > ExtraFiles