84namespace CodeViewYAML {
91 virtual void map(IO &IO) = 0;
92 virtual std::shared_ptr<DebugSubsection>
106 YAMLChecksumsSubsection()
109 void map(IO &IO)
override;
110 std::shared_ptr<DebugSubsection>
117 std::vector<SourceFileChecksumEntry> Checksums;
123 void map(IO &IO)
override;
124 std::shared_ptr<DebugSubsection>
136 YAMLInlineeLinesSubsection()
139 void map(IO &IO)
override;
140 std::shared_ptr<DebugSubsection>
152 YAMLCrossModuleExportsSubsection()
155 void map(IO &IO)
override;
156 std::shared_ptr<DebugSubsection>
162 std::vector<CrossModuleExport> Exports;
166 YAMLCrossModuleImportsSubsection()
169 void map(IO &IO)
override;
170 std::shared_ptr<DebugSubsection>
177 std::vector<YAMLCrossModuleImport> Imports;
183 void map(IO &IO)
override;
184 std::shared_ptr<DebugSubsection>
190 std::vector<CodeViewYAML::SymbolRecord> Symbols;
194 YAMLStringTableSubsection()
197 void map(IO &IO)
override;
198 std::shared_ptr<DebugSubsection>
204 std::vector<StringRef> Strings;
208 YAMLFrameDataSubsection()
211 void map(IO &IO)
override;
212 std::shared_ptr<DebugSubsection>
219 std::vector<YAMLFrameData> Frames;
223 YAMLCoffSymbolRVASubsection()
226 void map(IO &IO)
override;
227 std::shared_ptr<DebugSubsection>
233 std::vector<uint32_t> RVAs;
238void ScalarBitSetTraits<LineFlags>::bitset(IO &io,
LineFlags &Flags) {
240 io.enumFallback<Hex16>(
Flags);
243void ScalarEnumerationTraits<FileChecksumKind>::enumeration(
245 io.enumCase(Kind,
"None", FileChecksumKind::None);
246 io.enumCase(Kind,
"MD5", FileChecksumKind::MD5);
247 io.enumCase(Kind,
"SHA1", FileChecksumKind::SHA1);
248 io.enumCase(Kind,
"SHA256", FileChecksumKind::SHA256);
253 StringRef Bytes(
reinterpret_cast<const char *
>(
Value.Bytes.data()),
260 std::string
H = fromHex(Scalar);
261 Value.Bytes.assign(
H.begin(),
H.end());
266 IO.mapRequired(
"Offset", Obj.
Offset);
267 IO.mapRequired(
"LineStart", Obj.
LineStart);
269 IO.mapRequired(
"EndDelta", Obj.
EndDelta);
274 IO.mapRequired(
"EndColumn", Obj.
EndColumn);
278 IO.mapRequired(
"FileName", Obj.
FileName);
279 IO.mapRequired(
"Lines", Obj.
Lines);
280 IO.mapRequired(
"Columns", Obj.
Columns);
284 IO.mapRequired(
"LocalId", Obj.
Local);
285 IO.mapRequired(
"GlobalId", Obj.
Global);
291 IO.mapRequired(
"Imports", Obj.
ImportIds);
296 IO.mapRequired(
"FileName", Obj.
FileName);
297 IO.mapRequired(
"Kind", Obj.
Kind);
302 IO.mapRequired(
"FileName", Obj.
FileName);
304 IO.mapRequired(
"Inlinee", Obj.
Inlinee);
309 IO.mapRequired(
"CodeSize", Obj.
CodeSize);
310 IO.mapRequired(
"FrameFunc", Obj.
FrameFunc);
311 IO.mapRequired(
"LocalSize", Obj.
LocalSize);
315 IO.mapOptional(
"RvaStart", Obj.
RvaStart);
319void YAMLChecksumsSubsection::map(IO &IO) {
320 IO.mapTag(
"!FileChecksums",
true);
321 IO.mapRequired(
"Checksums", Checksums);
324void YAMLLinesSubsection::map(IO &IO) {
325 IO.mapTag(
"!Lines",
true);
326 IO.mapRequired(
"CodeSize",
Lines.CodeSize);
328 IO.mapRequired(
"Flags",
Lines.Flags);
329 IO.mapRequired(
"RelocOffset",
Lines.RelocOffset);
330 IO.mapRequired(
"RelocSegment",
Lines.RelocSegment);
331 IO.mapRequired(
"Blocks",
Lines.Blocks);
334void YAMLInlineeLinesSubsection::map(IO &IO) {
335 IO.mapTag(
"!InlineeLines",
true);
336 IO.mapRequired(
"HasExtraFiles",
InlineeLines.HasExtraFiles);
340void YAMLCrossModuleExportsSubsection::map(IO &IO) {
341 IO.mapTag(
"!CrossModuleExports",
true);
342 IO.mapOptional(
"Exports", Exports);
345void YAMLCrossModuleImportsSubsection::map(IO &IO) {
346 IO.mapTag(
"!CrossModuleImports",
true);
347 IO.mapOptional(
"Imports", Imports);
350void YAMLSymbolsSubsection::map(IO &IO) {
351 IO.mapTag(
"!Symbols",
true);
352 IO.mapRequired(
"Records", Symbols);
355void YAMLStringTableSubsection::map(IO &IO) {
356 IO.mapTag(
"!StringTable",
true);
357 IO.mapRequired(
"Strings", Strings);
360void YAMLFrameDataSubsection::map(IO &IO) {
361 IO.mapTag(
"!FrameData",
true);
362 IO.mapRequired(
"Frames", Frames);
365void YAMLCoffSymbolRVASubsection::map(IO &IO) {
366 IO.mapTag(
"!COFFSymbolRVAs",
true);
367 IO.mapRequired(
"RVAs", RVAs);
372 if (!IO.outputting()) {
373 if (IO.mapTag(
"!FileChecksums")) {
374 auto SS = std::make_shared<YAMLChecksumsSubsection>();
376 }
else if (IO.mapTag(
"!Lines")) {
377 Subsection.
Subsection = std::make_shared<YAMLLinesSubsection>();
378 }
else if (IO.mapTag(
"!InlineeLines")) {
379 Subsection.
Subsection = std::make_shared<YAMLInlineeLinesSubsection>();
380 }
else if (IO.mapTag(
"!CrossModuleExports")) {
382 std::make_shared<YAMLCrossModuleExportsSubsection>();
383 }
else if (IO.mapTag(
"!CrossModuleImports")) {
385 std::make_shared<YAMLCrossModuleImportsSubsection>();
386 }
else if (IO.mapTag(
"!Symbols")) {
387 Subsection.
Subsection = std::make_shared<YAMLSymbolsSubsection>();
388 }
else if (IO.mapTag(
"!StringTable")) {
389 Subsection.
Subsection = std::make_shared<YAMLStringTableSubsection>();
390 }
else if (IO.mapTag(
"!FrameData")) {
391 Subsection.
Subsection = std::make_shared<YAMLFrameDataSubsection>();
392 }
else if (IO.mapTag(
"!COFFSymbolRVAs")) {
393 Subsection.
Subsection = std::make_shared<YAMLCoffSymbolRVASubsection>();
401std::shared_ptr<DebugSubsection> YAMLChecksumsSubsection::toCodeViewSubsection(
405 auto Result = std::make_shared<DebugChecksumsSubsection>(*
SC.strings());
406 for (
const auto &CS : Checksums) {
407 Result->addChecksum(CS.FileName, CS.Kind, CS.ChecksumBytes.Bytes);
412std::shared_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
417 std::make_shared<DebugLinesSubsection>(*
SC.checksums(), *
SC.strings());
421 for (
const auto &LC :
Lines.Blocks) {
422 Result->createBlock(LC.FileName);
423 if (
Result->hasColumnInfo()) {
424 for (
auto Item :
zip(LC.Lines, LC.Columns)) {
425 auto &
L = std::get<0>(Item);
426 auto &
C = std::get<1>(Item);
428 Result->addLineAndColumnInfo(
L.Offset,
430 C.StartColumn,
C.EndColumn);
433 for (
const auto &L : LC.Lines) {
442std::shared_ptr<DebugSubsection>
443YAMLInlineeLinesSubsection::toCodeViewSubsection(
447 auto Result = std::make_shared<DebugInlineeLinesSubsection>(
456 for (
auto EF : Site.ExtraFiles) {
463std::shared_ptr<DebugSubsection>
464YAMLCrossModuleExportsSubsection::toCodeViewSubsection(
467 auto Result = std::make_shared<DebugCrossModuleExportsSubsection>();
468 for (
const auto &M : Exports)
469 Result->addMapping(
M.Local,
M.Global);
473std::shared_ptr<DebugSubsection>
474YAMLCrossModuleImportsSubsection::toCodeViewSubsection(
480 std::make_shared<DebugCrossModuleImportsSubsection>(*
SC.strings());
481 for (
const auto &M : Imports) {
482 for (
const auto Id :
M.ImportIds)
483 Result->addImport(
M.ModuleName, Id);
488std::shared_ptr<DebugSubsection> YAMLSymbolsSubsection::toCodeViewSubsection(
491 auto Result = std::make_shared<DebugSymbolsSubsection>();
492 for (
const auto &
Sym : Symbols)
494 Sym.toCodeViewSymbol(Allocator, CodeViewContainer::ObjectFile));
498std::shared_ptr<DebugSubsection>
499YAMLStringTableSubsection::toCodeViewSubsection(
502 auto Result = std::make_shared<DebugStringTableSubsection>();
503 for (
const auto &Str : this->Strings)
508std::shared_ptr<DebugSubsection> YAMLFrameDataSubsection::toCodeViewSubsection(
513 auto Result = std::make_shared<DebugFrameDataSubsection>(
true);
514 for (
const auto &YF : Frames) {
516 F.CodeSize = YF.CodeSize;
518 F.LocalSize = YF.LocalSize;
519 F.MaxStackSize = YF.MaxStackSize;
520 F.ParamsSize = YF.ParamsSize;
521 F.PrologSize = YF.PrologSize;
522 F.RvaStart = YF.RvaStart;
523 F.SavedRegsSize = YF.SavedRegsSize;
524 F.FrameFunc =
SC.strings()->insert(YF.FrameFunc);
530std::shared_ptr<DebugSubsection>
531YAMLCoffSymbolRVASubsection::toCodeViewSubsection(
534 auto Result = std::make_shared<DebugSymbolRVASubsection>();
535 for (
const auto &RVA : RVAs)
545 return ExpectedString.takeError();
548 Result.ChecksumBytes.Bytes = CS.
Checksum;
549 Result.Kind = CS.
Kind;
550 Result.FileName = *ExpectedString;
559 return make_error<CodeViewError>(cv_error_code::no_records);
561 return Strings.getString(
Offset);
565YAMLChecksumsSubsection::fromCodeViewSubsection(
568 auto Result = std::make_shared<YAMLChecksumsSubsection>();
570 for (
const auto &CS : FC) {
573 return ConvertedCS.takeError();
574 Result->Checksums.push_back(*ConvertedCS);
580YAMLLinesSubsection::fromCodeViewSubsection(
584 auto Result = std::make_shared<YAMLLinesSubsection>();
586 Result->Lines.RelocOffset =
Lines.header()->RelocOffset;
587 Result->Lines.RelocSegment =
Lines.header()->RelocSegment;
589 for (
const auto &L :
Lines) {
593 return EF.takeError();
594 Block.FileName = *EF;
595 if (
Lines.hasColumnInfo()) {
596 for (
const auto &
C :
L.Columns) {
598 SCE.EndColumn =
C.EndColumn;
599 SCE.StartColumn =
C.StartColumn;
603 for (
const auto &LN :
L.LineNumbers) {
610 Block.Lines.push_back(SLE);
618YAMLInlineeLinesSubsection::fromCodeViewSubsection(
622 auto Result = std::make_shared<YAMLInlineeLinesSubsection>();
624 Result->InlineeLines.HasExtraFiles =
Lines.hasExtraFiles();
625 for (
const auto &IL :
Lines) {
627 auto ExpF =
getFileName(Strings, Checksums, IL.Header->FileID);
629 return ExpF.takeError();
631 Site.
Inlinee = IL.Header->Inlinee.getIndex();
633 if (
Lines.hasExtraFiles()) {
634 for (
const auto EF : IL.ExtraFiles) {
637 return ExpF2.takeError();
641 Result->InlineeLines.Sites.push_back(Site);
647YAMLCrossModuleExportsSubsection::fromCodeViewSubsection(
649 auto Result = std::make_shared<YAMLCrossModuleExportsSubsection>();
655YAMLCrossModuleImportsSubsection::fromCodeViewSubsection(
658 auto Result = std::make_shared<YAMLCrossModuleImportsSubsection>();
659 for (
const auto &CMI : Imports) {
661 auto ExpectedStr = Strings.getString(CMI.Header->ModuleNameOffset);
663 return ExpectedStr.takeError();
665 YCMI.
ImportIds.assign(CMI.Imports.begin(), CMI.Imports.end());
666 Result->Imports.push_back(YCMI);
672YAMLSymbolsSubsection::fromCodeViewSubsection(
674 auto Result = std::make_shared<YAMLSymbolsSubsection>();
675 for (
const auto &
Sym : Symbols) {
679 cv_error_code::corrupt_record,
680 "Invalid CodeView Symbol Record in SymbolRecord "
681 "subsection of .debug$S while converting to YAML!"),
684 Result->Symbols.push_back(*S);
690YAMLStringTableSubsection::fromCodeViewSubsection(
692 auto Result = std::make_shared<YAMLStringTableSubsection>();
696 if (
auto EC = Reader.readCString(S))
697 return std::move(
EC);
699 while (Reader.bytesRemaining() > 0) {
700 if (
auto EC = Reader.readCString(S))
701 return std::move(
EC);
702 Result->Strings.push_back(S);
708YAMLFrameDataSubsection::fromCodeViewSubsection(
711 auto Result = std::make_shared<YAMLFrameDataSubsection>();
712 for (
const auto &
F : Frames) {
723 auto ES = Strings.getString(
F.FrameFunc);
726 make_error<CodeViewError>(
727 cv_error_code::no_records,
728 "Could not find string for string id while mapping FrameData!"),
731 Result->Frames.push_back(YF);
737YAMLCoffSymbolRVASubsection::fromCodeViewSubsection(
739 auto Result = std::make_shared<YAMLCoffSymbolRVASubsection>();
740 for (
const auto &RVA : Section) {
741 Result->RVAs.push_back(RVA);
750 std::vector<std::shared_ptr<DebugSubsection>> Result;
751 if (Subsections.
empty())
752 return std::move(Result);
754 for (
const auto &SS : Subsections) {
755 std::shared_ptr<DebugSubsection> CVS;
756 CVS = SS.Subsection->toCodeViewSubsection(
Allocator, SC);
758 Result.push_back(std::move(CVS));
760 return std::move(Result);
766 SubsectionConversionVisitor() =
default;
793Error SubsectionConversionVisitor::visitUnknown(
795 return make_error<CodeViewError>(cv_error_code::operation_unsupported);
798Error SubsectionConversionVisitor::visitLines(
800 auto Result = YAMLLinesSubsection::fromCodeViewSubsection(
803 return Result.takeError();
808Error SubsectionConversionVisitor::visitFileChecksums(
811 auto Result = YAMLChecksumsSubsection::fromCodeViewSubsection(State.
strings(),
814 return Result.takeError();
819Error SubsectionConversionVisitor::visitInlineeLines(
822 auto Result = YAMLInlineeLinesSubsection::fromCodeViewSubsection(
825 return Result.takeError();
830Error SubsectionConversionVisitor::visitCrossModuleExports(
834 YAMLCrossModuleExportsSubsection::fromCodeViewSubsection(Exports);
836 return Result.takeError();
841Error SubsectionConversionVisitor::visitCrossModuleImports(
844 auto Result = YAMLCrossModuleImportsSubsection::fromCodeViewSubsection(
847 return Result.takeError();
852Error SubsectionConversionVisitor::visitStringTable(
855 auto Result = YAMLStringTableSubsection::fromCodeViewSubsection(Strings);
857 return Result.takeError();
862Error SubsectionConversionVisitor::visitSymbols(
864 auto Result = YAMLSymbolsSubsection::fromCodeViewSubsection(Symbols);
866 return Result.takeError();
871Error SubsectionConversionVisitor::visitFrameData(
874 YAMLFrameDataSubsection::fromCodeViewSubsection(State.
strings(), Frames);
876 return Result.takeError();
881Error SubsectionConversionVisitor::visitCOFFSymbolRVAs(
883 auto Result = YAMLCoffSymbolRVASubsection::fromCodeViewSubsection(RVAs);
885 return Result.takeError();
893 SubsectionConversionVisitor V;
895 return std::move(
EC);
900std::vector<YAMLDebugSubsection>
913 std::vector<YAMLDebugSubsection> Result;
915 for (
const auto &SS : Subsections) {
917 Result.push_back(YamlSS);
934 if (!SC.hasStrings()) {
935 for (
const auto &SS : Sections) {
936 if (SS.Subsection->Kind != DebugSubsectionKind::StringTable)
939 auto Result = SS.Subsection->toCodeViewSubsection(
Allocator, SC);
941 std::static_pointer_cast<DebugStringTableSubsection>(Result));
946 if (SC.hasStrings() && !SC.hasChecksums()) {
947 for (
const auto &SS : Sections) {
948 if (SS.Subsection->Kind != DebugSubsectionKind::FileChecksums)
951 auto Result = SS.Subsection->toCodeViewSubsection(
Allocator, SC);
953 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.
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.