82namespace CodeViewYAML {
89 virtual void map(IO &IO) = 0;
90 virtual std::shared_ptr<DebugSubsection>
104 YAMLChecksumsSubsection()
107 void map(IO &IO)
override;
108 std::shared_ptr<DebugSubsection>
115 std::vector<SourceFileChecksumEntry> Checksums;
121 void map(IO &IO)
override;
122 std::shared_ptr<DebugSubsection>
134 YAMLInlineeLinesSubsection()
137 void map(IO &IO)
override;
138 std::shared_ptr<DebugSubsection>
150 YAMLCrossModuleExportsSubsection()
153 void map(IO &IO)
override;
154 std::shared_ptr<DebugSubsection>
160 std::vector<CrossModuleExport> Exports;
164 YAMLCrossModuleImportsSubsection()
167 void map(IO &IO)
override;
168 std::shared_ptr<DebugSubsection>
175 std::vector<YAMLCrossModuleImport> Imports;
181 void map(IO &IO)
override;
182 std::shared_ptr<DebugSubsection>
188 std::vector<CodeViewYAML::SymbolRecord> Symbols;
192 YAMLStringTableSubsection()
195 void map(IO &IO)
override;
196 std::shared_ptr<DebugSubsection>
202 std::vector<StringRef> Strings;
206 YAMLFrameDataSubsection()
209 void map(IO &IO)
override;
210 std::shared_ptr<DebugSubsection>
217 std::vector<YAMLFrameData> Frames;
221 YAMLCoffSymbolRVASubsection()
224 void map(IO &IO)
override;
225 std::shared_ptr<DebugSubsection>
231 std::vector<uint32_t> RVAs;
236void ScalarBitSetTraits<LineFlags>::bitset(IO &io,
LineFlags &Flags) {
238 io.enumFallback<Hex16>(
Flags);
241void ScalarEnumerationTraits<FileChecksumKind>::enumeration(
243 io.enumCase(Kind,
"None", FileChecksumKind::None);
244 io.enumCase(Kind,
"MD5", FileChecksumKind::MD5);
245 io.enumCase(Kind,
"SHA1", FileChecksumKind::SHA1);
246 io.enumCase(Kind,
"SHA256", FileChecksumKind::SHA256);
251 StringRef Bytes(
reinterpret_cast<const char *
>(
Value.Bytes.data()),
258 std::string
H = fromHex(Scalar);
259 Value.Bytes.assign(
H.begin(),
H.end());
264 IO.mapRequired(
"Offset", Obj.
Offset);
265 IO.mapRequired(
"LineStart", Obj.
LineStart);
267 IO.mapRequired(
"EndDelta", Obj.
EndDelta);
272 IO.mapRequired(
"EndColumn", Obj.
EndColumn);
276 IO.mapRequired(
"FileName", Obj.
FileName);
277 IO.mapRequired(
"Lines", Obj.
Lines);
278 IO.mapRequired(
"Columns", Obj.
Columns);
282 IO.mapRequired(
"LocalId", Obj.
Local);
283 IO.mapRequired(
"GlobalId", Obj.
Global);
289 IO.mapRequired(
"Imports", Obj.
ImportIds);
294 IO.mapRequired(
"FileName", Obj.
FileName);
295 IO.mapRequired(
"Kind", Obj.
Kind);
300 IO.mapRequired(
"FileName", Obj.
FileName);
302 IO.mapRequired(
"Inlinee", Obj.
Inlinee);
307 IO.mapRequired(
"CodeSize", Obj.
CodeSize);
308 IO.mapRequired(
"FrameFunc", Obj.
FrameFunc);
309 IO.mapRequired(
"LocalSize", Obj.
LocalSize);
313 IO.mapOptional(
"RvaStart", Obj.
RvaStart);
317void YAMLChecksumsSubsection::map(IO &IO) {
318 IO.mapTag(
"!FileChecksums",
true);
319 IO.mapRequired(
"Checksums", Checksums);
322void YAMLLinesSubsection::map(IO &IO) {
323 IO.mapTag(
"!Lines",
true);
324 IO.mapRequired(
"CodeSize",
Lines.CodeSize);
326 IO.mapRequired(
"Flags",
Lines.Flags);
327 IO.mapRequired(
"RelocOffset",
Lines.RelocOffset);
328 IO.mapRequired(
"RelocSegment",
Lines.RelocSegment);
329 IO.mapRequired(
"Blocks",
Lines.Blocks);
332void YAMLInlineeLinesSubsection::map(IO &IO) {
333 IO.mapTag(
"!InlineeLines",
true);
334 IO.mapRequired(
"HasExtraFiles",
InlineeLines.HasExtraFiles);
338void YAMLCrossModuleExportsSubsection::map(IO &IO) {
339 IO.mapTag(
"!CrossModuleExports",
true);
340 IO.mapOptional(
"Exports", Exports);
343void YAMLCrossModuleImportsSubsection::map(IO &IO) {
344 IO.mapTag(
"!CrossModuleImports",
true);
345 IO.mapOptional(
"Imports", Imports);
348void YAMLSymbolsSubsection::map(IO &IO) {
349 IO.mapTag(
"!Symbols",
true);
350 IO.mapRequired(
"Records", Symbols);
353void YAMLStringTableSubsection::map(IO &IO) {
354 IO.mapTag(
"!StringTable",
true);
355 IO.mapRequired(
"Strings", Strings);
358void YAMLFrameDataSubsection::map(IO &IO) {
359 IO.mapTag(
"!FrameData",
true);
360 IO.mapRequired(
"Frames", Frames);
363void YAMLCoffSymbolRVASubsection::map(IO &IO) {
364 IO.mapTag(
"!COFFSymbolRVAs",
true);
365 IO.mapRequired(
"RVAs", RVAs);
370 if (!IO.outputting()) {
371 if (IO.mapTag(
"!FileChecksums")) {
372 auto SS = std::make_shared<YAMLChecksumsSubsection>();
374 }
else if (IO.mapTag(
"!Lines")) {
375 Subsection.
Subsection = std::make_shared<YAMLLinesSubsection>();
376 }
else if (IO.mapTag(
"!InlineeLines")) {
377 Subsection.
Subsection = std::make_shared<YAMLInlineeLinesSubsection>();
378 }
else if (IO.mapTag(
"!CrossModuleExports")) {
380 std::make_shared<YAMLCrossModuleExportsSubsection>();
381 }
else if (IO.mapTag(
"!CrossModuleImports")) {
383 std::make_shared<YAMLCrossModuleImportsSubsection>();
384 }
else if (IO.mapTag(
"!Symbols")) {
385 Subsection.
Subsection = std::make_shared<YAMLSymbolsSubsection>();
386 }
else if (IO.mapTag(
"!StringTable")) {
387 Subsection.
Subsection = std::make_shared<YAMLStringTableSubsection>();
388 }
else if (IO.mapTag(
"!FrameData")) {
389 Subsection.
Subsection = std::make_shared<YAMLFrameDataSubsection>();
390 }
else if (IO.mapTag(
"!COFFSymbolRVAs")) {
391 Subsection.
Subsection = std::make_shared<YAMLCoffSymbolRVASubsection>();
399std::shared_ptr<DebugSubsection> YAMLChecksumsSubsection::toCodeViewSubsection(
403 auto Result = std::make_shared<DebugChecksumsSubsection>(*
SC.strings());
404 for (
const auto &CS : Checksums) {
405 Result->addChecksum(CS.FileName, CS.Kind, CS.ChecksumBytes.Bytes);
410std::shared_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
415 std::make_shared<DebugLinesSubsection>(*
SC.checksums(), *
SC.strings());
419 for (
const auto &LC :
Lines.Blocks) {
420 Result->createBlock(LC.FileName);
421 if (
Result->hasColumnInfo()) {
422 for (
auto Item :
zip(LC.Lines, LC.Columns)) {
423 auto &
L = std::get<0>(Item);
424 auto &
C = std::get<1>(Item);
426 Result->addLineAndColumnInfo(
L.Offset,
428 C.StartColumn,
C.EndColumn);
431 for (
const auto &L : LC.Lines) {
440std::shared_ptr<DebugSubsection>
441YAMLInlineeLinesSubsection::toCodeViewSubsection(
445 auto Result = std::make_shared<DebugInlineeLinesSubsection>(
454 for (
auto EF : Site.ExtraFiles) {
461std::shared_ptr<DebugSubsection>
462YAMLCrossModuleExportsSubsection::toCodeViewSubsection(
465 auto Result = std::make_shared<DebugCrossModuleExportsSubsection>();
466 for (
const auto &M : Exports)
467 Result->addMapping(
M.Local,
M.Global);
471std::shared_ptr<DebugSubsection>
472YAMLCrossModuleImportsSubsection::toCodeViewSubsection(
478 std::make_shared<DebugCrossModuleImportsSubsection>(*
SC.strings());
479 for (
const auto &M : Imports) {
480 for (
const auto Id :
M.ImportIds)
481 Result->addImport(
M.ModuleName, Id);
486std::shared_ptr<DebugSubsection> YAMLSymbolsSubsection::toCodeViewSubsection(
489 auto Result = std::make_shared<DebugSymbolsSubsection>();
490 for (
const auto &
Sym : Symbols)
492 Sym.toCodeViewSymbol(Allocator, CodeViewContainer::ObjectFile));
496std::shared_ptr<DebugSubsection>
497YAMLStringTableSubsection::toCodeViewSubsection(
500 auto Result = std::make_shared<DebugStringTableSubsection>();
501 for (
const auto &Str : this->Strings)
506std::shared_ptr<DebugSubsection> YAMLFrameDataSubsection::toCodeViewSubsection(
511 auto Result = std::make_shared<DebugFrameDataSubsection>(
true);
512 for (
const auto &YF : Frames) {
514 F.CodeSize = YF.CodeSize;
516 F.LocalSize = YF.LocalSize;
517 F.MaxStackSize = YF.MaxStackSize;
518 F.ParamsSize = YF.ParamsSize;
519 F.PrologSize = YF.PrologSize;
520 F.RvaStart = YF.RvaStart;
521 F.SavedRegsSize = YF.SavedRegsSize;
522 F.FrameFunc =
SC.strings()->insert(YF.FrameFunc);
528std::shared_ptr<DebugSubsection>
529YAMLCoffSymbolRVASubsection::toCodeViewSubsection(
532 auto Result = std::make_shared<DebugSymbolRVASubsection>();
533 for (
const auto &RVA : RVAs)
543 return ExpectedString.takeError();
546 Result.ChecksumBytes.Bytes = CS.
Checksum;
547 Result.Kind = CS.
Kind;
548 Result.FileName = *ExpectedString;
557 return make_error<CodeViewError>(cv_error_code::no_records);
559 return Strings.getString(
Offset);
563YAMLChecksumsSubsection::fromCodeViewSubsection(
566 auto Result = std::make_shared<YAMLChecksumsSubsection>();
568 for (
const auto &CS : FC) {
571 return ConvertedCS.takeError();
572 Result->Checksums.push_back(*ConvertedCS);
578YAMLLinesSubsection::fromCodeViewSubsection(
582 auto Result = std::make_shared<YAMLLinesSubsection>();
584 Result->Lines.RelocOffset =
Lines.header()->RelocOffset;
585 Result->Lines.RelocSegment =
Lines.header()->RelocSegment;
587 for (
const auto &L :
Lines) {
591 return EF.takeError();
592 Block.FileName = *EF;
593 if (
Lines.hasColumnInfo()) {
594 for (
const auto &
C :
L.Columns) {
596 SCE.EndColumn =
C.EndColumn;
597 SCE.StartColumn =
C.StartColumn;
601 for (
const auto &LN :
L.LineNumbers) {
608 Block.Lines.push_back(SLE);
616YAMLInlineeLinesSubsection::fromCodeViewSubsection(
620 auto Result = std::make_shared<YAMLInlineeLinesSubsection>();
622 Result->InlineeLines.HasExtraFiles =
Lines.hasExtraFiles();
623 for (
const auto &IL :
Lines) {
625 auto ExpF =
getFileName(Strings, Checksums, IL.Header->FileID);
627 return ExpF.takeError();
629 Site.
Inlinee = IL.Header->Inlinee.getIndex();
631 if (
Lines.hasExtraFiles()) {
632 for (
const auto EF : IL.ExtraFiles) {
635 return ExpF2.takeError();
639 Result->InlineeLines.Sites.push_back(Site);
645YAMLCrossModuleExportsSubsection::fromCodeViewSubsection(
647 auto Result = std::make_shared<YAMLCrossModuleExportsSubsection>();
653YAMLCrossModuleImportsSubsection::fromCodeViewSubsection(
656 auto Result = std::make_shared<YAMLCrossModuleImportsSubsection>();
657 for (
const auto &CMI : Imports) {
659 auto ExpectedStr = Strings.getString(CMI.Header->ModuleNameOffset);
661 return ExpectedStr.takeError();
663 YCMI.
ImportIds.assign(CMI.Imports.begin(), CMI.Imports.end());
664 Result->Imports.push_back(YCMI);
670YAMLSymbolsSubsection::fromCodeViewSubsection(
672 auto Result = std::make_shared<YAMLSymbolsSubsection>();
673 for (
const auto &
Sym : Symbols) {
677 cv_error_code::corrupt_record,
678 "Invalid CodeView Symbol Record in SymbolRecord "
679 "subsection of .debug$S while converting to YAML!"),
682 Result->Symbols.push_back(*S);
688YAMLStringTableSubsection::fromCodeViewSubsection(
690 auto Result = std::make_shared<YAMLStringTableSubsection>();
694 if (
auto EC = Reader.readCString(S))
695 return std::move(
EC);
697 while (Reader.bytesRemaining() > 0) {
698 if (
auto EC = Reader.readCString(S))
699 return std::move(
EC);
700 Result->Strings.push_back(S);
706YAMLFrameDataSubsection::fromCodeViewSubsection(
709 auto Result = std::make_shared<YAMLFrameDataSubsection>();
710 for (
const auto &
F : Frames) {
721 auto ES = Strings.getString(
F.FrameFunc);
724 make_error<CodeViewError>(
725 cv_error_code::no_records,
726 "Could not find string for string id while mapping FrameData!"),
729 Result->Frames.push_back(YF);
735YAMLCoffSymbolRVASubsection::fromCodeViewSubsection(
737 auto Result = std::make_shared<YAMLCoffSymbolRVASubsection>();
738 for (
const auto &RVA : Section) {
739 Result->RVAs.push_back(RVA);
748 std::vector<std::shared_ptr<DebugSubsection>> Result;
749 if (Subsections.
empty())
750 return std::move(Result);
752 for (
const auto &SS : Subsections) {
753 std::shared_ptr<DebugSubsection> CVS;
754 CVS = SS.Subsection->toCodeViewSubsection(
Allocator, SC);
756 Result.push_back(std::move(CVS));
758 return std::move(Result);
764 SubsectionConversionVisitor() =
default;
791Error SubsectionConversionVisitor::visitUnknown(
793 return make_error<CodeViewError>(cv_error_code::operation_unsupported);
796Error SubsectionConversionVisitor::visitLines(
798 auto Result = YAMLLinesSubsection::fromCodeViewSubsection(
801 return Result.takeError();
806Error SubsectionConversionVisitor::visitFileChecksums(
809 auto Result = YAMLChecksumsSubsection::fromCodeViewSubsection(State.
strings(),
812 return Result.takeError();
817Error SubsectionConversionVisitor::visitInlineeLines(
820 auto Result = YAMLInlineeLinesSubsection::fromCodeViewSubsection(
823 return Result.takeError();
828Error SubsectionConversionVisitor::visitCrossModuleExports(
832 YAMLCrossModuleExportsSubsection::fromCodeViewSubsection(Exports);
834 return Result.takeError();
839Error SubsectionConversionVisitor::visitCrossModuleImports(
842 auto Result = YAMLCrossModuleImportsSubsection::fromCodeViewSubsection(
845 return Result.takeError();
850Error SubsectionConversionVisitor::visitStringTable(
853 auto Result = YAMLStringTableSubsection::fromCodeViewSubsection(Strings);
855 return Result.takeError();
860Error SubsectionConversionVisitor::visitSymbols(
862 auto Result = YAMLSymbolsSubsection::fromCodeViewSubsection(Symbols);
864 return Result.takeError();
869Error SubsectionConversionVisitor::visitFrameData(
872 YAMLFrameDataSubsection::fromCodeViewSubsection(State.
strings(), Frames);
874 return Result.takeError();
879Error SubsectionConversionVisitor::visitCOFFSymbolRVAs(
881 auto Result = YAMLCoffSymbolRVASubsection::fromCodeViewSubsection(RVAs);
883 return Result.takeError();
891 SubsectionConversionVisitor V;
893 return std::move(
EC);
898std::vector<YAMLDebugSubsection>
911 std::vector<YAMLDebugSubsection> Result;
913 for (
const auto &SS : Subsections) {
915 Result.push_back(YamlSS);
932 if (!SC.hasStrings()) {
933 for (
const auto &SS : Sections) {
934 if (SS.Subsection->Kind != DebugSubsectionKind::StringTable)
937 auto Result = SS.Subsection->toCodeViewSubsection(
Allocator, SC);
939 std::static_pointer_cast<DebugStringTableSubsection>(Result));
944 if (SC.hasStrings() && !SC.hasChecksums()) {
945 for (
const auto &SS : Sections) {
946 if (SS.Subsection->Kind != DebugSubsectionKind::FileChecksums)
949 auto Result = SS.Subsection->toCodeViewSubsection(
Allocator, SC);
951 std::static_pointer_cast<DebugChecksumsSubsection>(Result));
This file defines the BumpPtrAllocator interface.
static Expected< StringRef > getFileName(const DebugStringTableSubsectionRef &Strings, const DebugChecksumsSubsectionRef &Checksums, uint32_t FileID)
static Expected< SourceFileChecksumEntry > convertOneChecksum(const DebugStringTableSubsectionRef &Strings, const FileChecksumEntry &CS)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type)
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
#define LLVM_YAML_DECLARE_SCALAR_TRAITS(Type, MustQuote)
#define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type)
#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
Provides read only access to a subclass of BinaryStream.
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
uint64_t bytesRemaining() const
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 ...
Allocate memory in an ever growing pool, as if by bump-pointer.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Helper for check-and-exit error handling.
Tagged union holding either a T or a Error.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
A table of densely packed, null-terminated strings indexed by offset.
LLVM Value Representation.
Iterator at(uint32_t Offset) const
given an offset into the array's underlying stream, return an iterator to the record at that offset.
const FileChecksumArray & getArray() const
Represents a read-only view of a CodeView string table.
virtual Error visitCOFFSymbolRVAs(DebugSymbolRVASubsectionRef &RVAs, const StringsAndChecksumsRef &State)=0
virtual Error visitSymbols(DebugSymbolsSubsectionRef &CSE, const StringsAndChecksumsRef &State)=0
virtual Error visitFrameData(DebugFrameDataSubsectionRef &FD, const StringsAndChecksumsRef &State)=0
virtual Error visitInlineeLines(DebugInlineeLinesSubsectionRef &Inlinees, const StringsAndChecksumsRef &State)=0
virtual Error visitCrossModuleExports(DebugCrossModuleExportsSubsectionRef &CSE, const StringsAndChecksumsRef &State)=0
virtual Error visitUnknown(DebugUnknownSubsectionRef &Unknown)
virtual Error visitFileChecksums(DebugChecksumsSubsectionRef &Checksums, const StringsAndChecksumsRef &State)=0
virtual Error visitStringTable(DebugStringTableSubsectionRef &ST, const StringsAndChecksumsRef &State)=0
virtual Error visitLines(DebugLinesSubsectionRef &Lines, const StringsAndChecksumsRef &State)=0
virtual Error visitCrossModuleImports(DebugCrossModuleImportsSubsectionRef &CSE, const StringsAndChecksumsRef &State)=0
const DebugStringTableSubsectionRef & strings() const
const DebugChecksumsSubsectionRef & checksums() const
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void initializeStringsAndChecksums(ArrayRef< YAMLDebugSubsection > Sections, codeview::StringsAndChecksums &SC)
Expected< std::vector< std::shared_ptr< codeview::DebugSubsection > > > toCodeViewSubsectionList(BumpPtrAllocator &Allocator, ArrayRef< YAMLDebugSubsection > Subsections, const codeview::StringsAndChecksums &SC)
std::vector< YAMLDebugSubsection > fromDebugS(ArrayRef< uint8_t > Data, const codeview::StringsAndChecksumsRef &SC)
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
Error visitDebugSubsection(const DebugSubsectionRecord &R, DebugSubsectionVisitor &V, const StringsAndChecksumsRef &State)
This is an optimization pass for GlobalISel generic memory operations.
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
Error joinErrors(Error E1, Error E2)
Concatenate errors.
@ SCE
Tune debug info for SCE targets (e.g. PS4).
std::vector< StringRef > ExtraFiles
HexFormattedString ChecksumBytes
codeview::FileChecksumKind Kind
std::vector< SourceLineEntry > Lines
std::vector< SourceColumnEntry > Columns
static Expected< SymbolRecord > fromCodeViewSymbol(codeview::CVSymbol Symbol)
std::vector< uint32_t > ImportIds
std::shared_ptr< detail::YAMLSubsectionBase > Subsection
static Expected< YAMLDebugSubsection > fromCodeViewSubection(const codeview::StringsAndChecksumsRef &SC, const codeview::DebugSubsectionRecord &SS)
virtual void map(IO &IO)=0
virtual ~YAMLSubsectionBase()=default
YAMLSubsectionBase(DebugSubsectionKind Kind)
virtual std::shared_ptr< DebugSubsection > toCodeViewSubsection(BumpPtrAllocator &Allocator, const codeview::StringsAndChecksums &SC) const =0
support::ulittle32_t Local
support::ulittle32_t Global
ArrayRef< uint8_t > Checksum
Data in the SUBSEC_FRAMEDATA subection.