diff options
author | Zachary Turner <zturner@google.com> | 2017-05-30 21:53:05 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-05-30 21:53:05 +0000 |
commit | d427383cb883aee50386a247df985bd12133e2db (patch) | |
tree | 3974b9bac0a66cddcc6cd2d87e164aa558ebbc92 /llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp | |
parent | 5e394c3d6f2731b22a4632071b9b0aed116989f9 (diff) | |
download | bcm5719-llvm-d427383cb883aee50386a247df985bd12133e2db.tar.gz bcm5719-llvm-d427383cb883aee50386a247df985bd12133e2db.zip |
[CodeView] Move CodeView YAML code to ObjectYAML.
This is the beginning of an effort to move the codeview yaml
reader / writer into ObjectYAML so that it can be shared.
Currently the only consumer / producer of CodeView YAML is
llvm-pdbdump, but CodeView can exist outside of PDB files, and
indeed is put into object files and passed to the linker to
produce PDB files. Furthermore, there are subtle differences
in the types of records that show up in object file CodeView
vs PDB file CodeView, but they are otherwise 99% the same.
By having this code in ObjectYAML, we can have llvm-pdbdump
reuse this code, while teaching obj2yaml and yaml2obj to use
this syntax for dealing with object files that can contain
CodeView.
This patch only adds support for CodeView type information
to ObjectYAML. Subsequent patches will add support for
CodeView symbol information.
llvm-svn: 304248
Diffstat (limited to 'llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp')
-rw-r--r-- | llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp b/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp index 7aa68dee7d4..6173804c375 100644 --- a/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp +++ b/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp @@ -28,6 +28,7 @@ #include "llvm/DebugInfo/PDB/Native/RawConstants.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" +#include "llvm/ObjectYAML/CodeViewYAML.h" using namespace llvm; using namespace llvm::codeview; @@ -104,12 +105,12 @@ Error YAMLOutputStyle::dump() { namespace { class C13YamlVisitor : public C13DebugFragmentVisitor { public: - C13YamlVisitor(llvm::pdb::yaml::PdbSourceFileInfo &Info, PDBFile &F) + C13YamlVisitor(CodeViewYAML::SourceFileInfo &Info, PDBFile &F) : C13DebugFragmentVisitor(F), Info(Info) {} Error handleFileChecksums() override { for (const auto &C : *Checksums) { - llvm::pdb::yaml::PdbSourceFileChecksumEntry Entry; + CodeViewYAML::SourceFileChecksumEntry Entry; if (auto Result = getNameFromStringTable(C.FileNameOffset)) Entry.FileName = *Result; else @@ -143,7 +144,7 @@ public: return Result.takeError(); for (const auto &N : L.LineNumbers) { - llvm::pdb::yaml::PdbSourceLineEntry Line; + CodeViewYAML::SourceLineEntry Line; Line.Offset = N.Offset; codeview::LineInfo LI(N.Flags); Line.LineStart = LI.getStartLine(); @@ -154,7 +155,7 @@ public: if (LF.hasColumnInfo()) { for (const auto &C : L.Columns) { - llvm::pdb::yaml::PdbSourceColumnEntry Column; + CodeViewYAML::SourceColumnEntry Column; Column.StartColumn = C.StartColumn; Column.EndColumn = C.EndColumn; Block.Columns.push_back(Column); @@ -179,7 +180,7 @@ public: else return Result.takeError(); - Site.Inlinee = IL.Header->Inlinee; + Site.Inlinee = IL.Header->Inlinee.getIndex(); Site.SourceLineNum = IL.Header->SourceLineNum; if (ILF.hasExtraFiles()) { for (const auto &EF : IL.ExtraFiles) { @@ -195,17 +196,16 @@ public: } private: - - llvm::pdb::yaml::PdbSourceFileInfo &Info; + CodeViewYAML::SourceFileInfo &Info; }; } -Expected<Optional<llvm::pdb::yaml::PdbSourceFileInfo>> +Expected<Optional<CodeViewYAML::SourceFileInfo>> YAMLOutputStyle::getFileLineInfo(const pdb::ModuleDebugStreamRef &ModS) { if (!ModS.hasLineInfo()) return None; - yaml::PdbSourceFileInfo Info; + CodeViewYAML::SourceFileInfo Info; C13YamlVisitor Visitor(Info, File); if (auto EC = codeview::visitDebugSubsections(ModS.linesAndChecksums(), Visitor)) @@ -378,13 +378,10 @@ Error YAMLOutputStyle::dumpTpiStream() { Obj.TpiStream.emplace(); Obj.TpiStream->Version = TS.getTpiVersion(); for (auto &Record : TS.types(nullptr)) { - yaml::PdbTpiRecord R; - // It's not necessary to set R.RecordData here. That only exists as a - // way to have the `PdbTpiRecord` structure own the memory that `R.Record` - // references. In the case of reading an existing PDB though, that memory - // is owned by the backing stream. - R.Record = Record; - Obj.TpiStream->Records.push_back(R); + auto ExpectedRecord = CodeViewYAML::LeafRecord::fromCodeViewRecord(Record); + if (!ExpectedRecord) + return ExpectedRecord.takeError(); + Obj.TpiStream->Records.push_back(*ExpectedRecord); } return Error::success(); @@ -402,9 +399,11 @@ Error YAMLOutputStyle::dumpIpiStream() { Obj.IpiStream.emplace(); Obj.IpiStream->Version = IS.getTpiVersion(); for (auto &Record : IS.types(nullptr)) { - yaml::PdbTpiRecord R; - R.Record = Record; - Obj.IpiStream->Records.push_back(R); + auto ExpectedRecord = CodeViewYAML::LeafRecord::fromCodeViewRecord(Record); + if (!ExpectedRecord) + return ExpectedRecord.takeError(); + + Obj.IpiStream->Records.push_back(*ExpectedRecord); } return Error::success(); |