2016-07-23 20:41:05 +00:00
|
|
|
//===- YAMLOutputStyle.cpp ------------------------------------ *- C++ --*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "YAMLOutputStyle.h"
|
|
|
|
|
|
|
|
#include "PdbYaml.h"
|
2017-06-10 13:44:06 +00:00
|
|
|
#include "llvm-pdbutil.h"
|
2016-07-23 20:41:05 +00:00
|
|
|
|
2017-05-30 17:37:31 +00:00
|
|
|
#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
|
|
|
|
#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
|
|
|
|
#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
|
|
|
|
#include "llvm/DebugInfo/CodeView/DebugSubsection.h"
|
|
|
|
#include "llvm/DebugInfo/CodeView/DebugUnknownSubsection.h"
|
2017-04-26 19:45:00 +00:00
|
|
|
#include "llvm/DebugInfo/CodeView/Line.h"
|
2017-06-16 21:03:24 +00:00
|
|
|
#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
|
2017-01-02 19:17:04 +00:00
|
|
|
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
|
2017-04-16 16:01:22 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
|
2017-05-02 18:30:13 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
|
2017-04-16 16:01:22 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
|
2017-05-02 18:30:13 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/RawError.h"
|
2017-04-16 16:01:22 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
|
2016-07-23 20:41:05 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
2017-05-02 18:30:13 +00:00
|
|
|
using namespace llvm::codeview;
|
2016-07-23 20:41:05 +00:00
|
|
|
using namespace llvm::pdb;
|
|
|
|
|
2017-06-16 21:03:24 +00:00
|
|
|
static bool checkModuleSubsection(opts::ModuleSubsection MS) {
|
|
|
|
return any_of(opts::pdb2yaml::DumpModuleSubsections,
|
|
|
|
[=](opts::ModuleSubsection M) {
|
|
|
|
return M == MS || M == opts::ModuleSubsection::All;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-02 19:17:04 +00:00
|
|
|
YAMLOutputStyle::YAMLOutputStyle(PDBFile &File)
|
2017-04-16 16:01:22 +00:00
|
|
|
: File(File), Out(outs()), Obj(File.getAllocator()) {
|
|
|
|
Out.setWriteDefaultValues(!opts::pdb2yaml::Minimal);
|
|
|
|
}
|
2016-07-23 20:41:05 +00:00
|
|
|
|
|
|
|
Error YAMLOutputStyle::dump() {
|
|
|
|
if (opts::pdb2yaml::StreamDirectory)
|
|
|
|
opts::pdb2yaml::StreamMetadata = true;
|
2017-05-02 18:30:13 +00:00
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
if (auto EC = dumpFileHeaders())
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
if (auto EC = dumpStreamMetadata())
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
if (auto EC = dumpStreamDirectory())
|
|
|
|
return EC;
|
|
|
|
|
2017-04-16 16:01:22 +00:00
|
|
|
if (auto EC = dumpStringTable())
|
|
|
|
return EC;
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
if (auto EC = dumpPDBStream())
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
if (auto EC = dumpDbiStream())
|
|
|
|
return EC;
|
|
|
|
|
2017-01-02 19:17:04 +00:00
|
|
|
if (auto EC = dumpTpiStream())
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
if (auto EC = dumpIpiStream())
|
|
|
|
return EC;
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
flush();
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2017-04-26 19:45:00 +00:00
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
Error YAMLOutputStyle::dumpFileHeaders() {
|
|
|
|
if (opts::pdb2yaml::NoFileHeaders)
|
|
|
|
return Error::success();
|
|
|
|
|
2017-01-02 19:17:04 +00:00
|
|
|
yaml::MSFHeaders Headers;
|
2016-07-23 20:41:05 +00:00
|
|
|
Obj.Headers.emplace();
|
|
|
|
Obj.Headers->SuperBlock.NumBlocks = File.getBlockCount();
|
|
|
|
Obj.Headers->SuperBlock.BlockMapAddr = File.getBlockMapIndex();
|
|
|
|
Obj.Headers->SuperBlock.BlockSize = File.getBlockSize();
|
|
|
|
auto Blocks = File.getDirectoryBlockArray();
|
|
|
|
Obj.Headers->DirectoryBlocks.assign(Blocks.begin(), Blocks.end());
|
|
|
|
Obj.Headers->NumDirectoryBlocks = File.getNumDirectoryBlocks();
|
|
|
|
Obj.Headers->SuperBlock.NumDirectoryBytes = File.getNumDirectoryBytes();
|
|
|
|
Obj.Headers->NumStreams =
|
|
|
|
opts::pdb2yaml::StreamMetadata ? File.getNumStreams() : 0;
|
|
|
|
Obj.Headers->SuperBlock.FreeBlockMapBlock = File.getFreeBlockMapBlock();
|
|
|
|
Obj.Headers->SuperBlock.Unknown1 = File.getUnknown1();
|
|
|
|
Obj.Headers->FileSize = File.getFileSize();
|
|
|
|
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2017-04-16 16:01:22 +00:00
|
|
|
Error YAMLOutputStyle::dumpStringTable() {
|
2017-06-16 21:03:24 +00:00
|
|
|
bool RequiresStringTable = opts::pdb2yaml::DumpModuleFiles ||
|
|
|
|
!opts::pdb2yaml::DumpModuleSubsections.empty();
|
2017-06-03 15:20:36 +00:00
|
|
|
bool RequestedStringTable = opts::pdb2yaml::StringTable;
|
|
|
|
if (!RequiresStringTable && !RequestedStringTable)
|
2017-04-16 16:01:22 +00:00
|
|
|
return Error::success();
|
|
|
|
|
|
|
|
auto ExpectedST = File.getStringTable();
|
|
|
|
if (!ExpectedST)
|
|
|
|
return ExpectedST.takeError();
|
|
|
|
|
2017-06-03 15:20:36 +00:00
|
|
|
Obj.StringTable.emplace();
|
2017-04-16 16:01:22 +00:00
|
|
|
const auto &ST = ExpectedST.get();
|
|
|
|
for (auto ID : ST.name_ids()) {
|
2017-05-03 20:26:11 +00:00
|
|
|
auto S = ST.getStringForID(ID);
|
|
|
|
if (!S)
|
|
|
|
return S.takeError();
|
|
|
|
if (S->empty())
|
|
|
|
continue;
|
|
|
|
Obj.StringTable->push_back(*S);
|
2017-04-16 16:01:22 +00:00
|
|
|
}
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
Error YAMLOutputStyle::dumpStreamMetadata() {
|
|
|
|
if (!opts::pdb2yaml::StreamMetadata)
|
|
|
|
return Error::success();
|
|
|
|
|
|
|
|
Obj.StreamSizes.emplace();
|
|
|
|
Obj.StreamSizes->assign(File.getStreamSizes().begin(),
|
|
|
|
File.getStreamSizes().end());
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error YAMLOutputStyle::dumpStreamDirectory() {
|
|
|
|
if (!opts::pdb2yaml::StreamDirectory)
|
|
|
|
return Error::success();
|
|
|
|
|
|
|
|
auto StreamMap = File.getStreamMap();
|
|
|
|
Obj.StreamMap.emplace();
|
|
|
|
for (auto &Stream : StreamMap) {
|
|
|
|
pdb::yaml::StreamBlockList BlockList;
|
|
|
|
BlockList.Blocks.assign(Stream.begin(), Stream.end());
|
|
|
|
Obj.StreamMap->push_back(BlockList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error YAMLOutputStyle::dumpPDBStream() {
|
|
|
|
if (!opts::pdb2yaml::PdbStream)
|
|
|
|
return Error::success();
|
|
|
|
|
|
|
|
auto IS = File.getPDBInfoStream();
|
|
|
|
if (!IS)
|
|
|
|
return IS.takeError();
|
|
|
|
|
|
|
|
auto &InfoS = IS.get();
|
|
|
|
Obj.PdbStream.emplace();
|
|
|
|
Obj.PdbStream->Age = InfoS.getAge();
|
|
|
|
Obj.PdbStream->Guid = InfoS.getGuid();
|
|
|
|
Obj.PdbStream->Signature = InfoS.getSignature();
|
|
|
|
Obj.PdbStream->Version = InfoS.getVersion();
|
2017-04-16 16:01:22 +00:00
|
|
|
Obj.PdbStream->Features = InfoS.getFeatureSignatures();
|
2016-07-23 20:41:05 +00:00
|
|
|
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2017-06-10 13:44:06 +00:00
|
|
|
static opts::ModuleSubsection convertSubsectionKind(DebugSubsectionKind K) {
|
|
|
|
switch (K) {
|
|
|
|
case DebugSubsectionKind::CrossScopeExports:
|
|
|
|
return opts::ModuleSubsection::CrossScopeExports;
|
|
|
|
case DebugSubsectionKind::CrossScopeImports:
|
|
|
|
return opts::ModuleSubsection::CrossScopeImports;
|
|
|
|
case DebugSubsectionKind::FileChecksums:
|
|
|
|
return opts::ModuleSubsection::FileChecksums;
|
|
|
|
case DebugSubsectionKind::InlineeLines:
|
|
|
|
return opts::ModuleSubsection::InlineeLines;
|
|
|
|
case DebugSubsectionKind::Lines:
|
|
|
|
return opts::ModuleSubsection::Lines;
|
|
|
|
case DebugSubsectionKind::Symbols:
|
|
|
|
return opts::ModuleSubsection::Symbols;
|
|
|
|
case DebugSubsectionKind::StringTable:
|
|
|
|
return opts::ModuleSubsection::StringTable;
|
|
|
|
case DebugSubsectionKind::FrameData:
|
|
|
|
return opts::ModuleSubsection::FrameData;
|
|
|
|
default:
|
|
|
|
return opts::ModuleSubsection::Unknown;
|
|
|
|
}
|
|
|
|
llvm_unreachable("Unreachable!");
|
|
|
|
}
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
Error YAMLOutputStyle::dumpDbiStream() {
|
|
|
|
if (!opts::pdb2yaml::DbiStream)
|
|
|
|
return Error::success();
|
|
|
|
|
|
|
|
auto DbiS = File.getPDBDbiStream();
|
|
|
|
if (!DbiS)
|
|
|
|
return DbiS.takeError();
|
|
|
|
|
|
|
|
auto &DS = DbiS.get();
|
|
|
|
Obj.DbiStream.emplace();
|
|
|
|
Obj.DbiStream->Age = DS.getAge();
|
|
|
|
Obj.DbiStream->BuildNumber = DS.getBuildNumber();
|
|
|
|
Obj.DbiStream->Flags = DS.getFlags();
|
|
|
|
Obj.DbiStream->MachineType = DS.getMachineType();
|
|
|
|
Obj.DbiStream->PdbDllRbld = DS.getPdbDllRbld();
|
|
|
|
Obj.DbiStream->PdbDllVersion = DS.getPdbDllVersion();
|
|
|
|
Obj.DbiStream->VerHeader = DS.getDbiVersion();
|
2017-06-16 21:03:24 +00:00
|
|
|
if (opts::pdb2yaml::DumpModules) {
|
2017-05-08 17:12:57 +00:00
|
|
|
const auto &Modules = DS.modules();
|
|
|
|
for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) {
|
|
|
|
DbiModuleDescriptor MI = Modules.getModuleDescriptor(I);
|
|
|
|
|
2017-05-02 18:30:13 +00:00
|
|
|
Obj.DbiStream->ModInfos.emplace_back();
|
|
|
|
yaml::PdbDbiModuleInfo &DMI = Obj.DbiStream->ModInfos.back();
|
|
|
|
|
2017-05-08 17:12:57 +00:00
|
|
|
DMI.Mod = MI.getModuleName();
|
|
|
|
DMI.Obj = MI.getObjFileName();
|
2017-06-16 21:03:24 +00:00
|
|
|
if (opts::pdb2yaml::DumpModuleFiles) {
|
2017-05-08 17:12:57 +00:00
|
|
|
auto Files = Modules.source_files(I);
|
|
|
|
DMI.SourceFiles.assign(Files.begin(), Files.end());
|
|
|
|
}
|
2017-01-02 19:17:04 +00:00
|
|
|
|
2017-05-08 17:12:57 +00:00
|
|
|
uint16_t ModiStream = MI.getModuleStreamIndex();
|
2017-05-02 18:30:13 +00:00
|
|
|
if (ModiStream == kInvalidStreamIndex)
|
|
|
|
continue;
|
|
|
|
|
2017-04-26 19:45:00 +00:00
|
|
|
auto ModStreamData = msf::MappedBlockStream::createIndexedStream(
|
2017-06-03 15:20:36 +00:00
|
|
|
File.getMsfLayout(), File.getMsfBuffer(), ModiStream,
|
|
|
|
File.getAllocator());
|
2017-04-26 19:45:00 +00:00
|
|
|
|
2017-05-08 17:12:57 +00:00
|
|
|
pdb::ModuleDebugStreamRef ModS(MI, std::move(ModStreamData));
|
2017-04-26 19:45:00 +00:00
|
|
|
if (auto EC = ModS.reload())
|
|
|
|
return EC;
|
|
|
|
|
2017-06-03 15:20:36 +00:00
|
|
|
auto ExpectedST = File.getStringTable();
|
|
|
|
if (!ExpectedST)
|
|
|
|
return ExpectedST.takeError();
|
2017-06-16 21:03:24 +00:00
|
|
|
if (!opts::pdb2yaml::DumpModuleSubsections.empty() &&
|
2017-06-03 15:20:36 +00:00
|
|
|
ModS.hasDebugSubsections()) {
|
|
|
|
auto ExpectedChecksums = ModS.findChecksumsSubsection();
|
|
|
|
if (!ExpectedChecksums)
|
|
|
|
return ExpectedChecksums.takeError();
|
|
|
|
|
2017-06-16 21:03:24 +00:00
|
|
|
StringsAndChecksumsRef SC(ExpectedST->getStringTable(),
|
|
|
|
*ExpectedChecksums);
|
|
|
|
|
2017-06-03 15:20:36 +00:00
|
|
|
for (const auto &SS : ModS.subsections()) {
|
2017-06-10 13:44:06 +00:00
|
|
|
opts::ModuleSubsection OptionKind = convertSubsectionKind(SS.kind());
|
2017-06-16 21:03:24 +00:00
|
|
|
if (!checkModuleSubsection(OptionKind))
|
2017-06-10 13:44:06 +00:00
|
|
|
continue;
|
|
|
|
|
2017-06-03 15:20:36 +00:00
|
|
|
auto Converted =
|
2017-06-16 21:03:24 +00:00
|
|
|
CodeViewYAML::YAMLDebugSubsection::fromCodeViewSubection(SC, SS);
|
2017-06-03 15:20:36 +00:00
|
|
|
if (!Converted)
|
|
|
|
return Converted.takeError();
|
|
|
|
DMI.Subsections.push_back(*Converted);
|
|
|
|
}
|
2017-04-26 19:45:00 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 21:03:24 +00:00
|
|
|
if (opts::pdb2yaml::DumpModuleSyms) {
|
2017-01-02 19:17:04 +00:00
|
|
|
DMI.Modi.emplace();
|
|
|
|
|
|
|
|
DMI.Modi->Signature = ModS.signature();
|
|
|
|
bool HadError = false;
|
|
|
|
for (auto &Sym : ModS.symbols(&HadError)) {
|
2017-06-01 20:58:36 +00:00
|
|
|
auto ES = CodeViewYAML::SymbolRecord::fromCodeViewSymbol(Sym);
|
|
|
|
if (!ES)
|
|
|
|
return ES.takeError();
|
|
|
|
|
|
|
|
DMI.Modi->Symbols.push_back(*ES);
|
2017-01-02 19:17:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error YAMLOutputStyle::dumpTpiStream() {
|
|
|
|
if (!opts::pdb2yaml::TpiStream)
|
|
|
|
return Error::success();
|
|
|
|
|
|
|
|
auto TpiS = File.getPDBTpiStream();
|
|
|
|
if (!TpiS)
|
|
|
|
return TpiS.takeError();
|
|
|
|
|
|
|
|
auto &TS = TpiS.get();
|
|
|
|
Obj.TpiStream.emplace();
|
|
|
|
Obj.TpiStream->Version = TS.getTpiVersion();
|
|
|
|
for (auto &Record : TS.types(nullptr)) {
|
2017-06-01 20:58:36 +00:00
|
|
|
auto ExpectedRecord = CodeViewYAML::LeafRecord::fromCodeViewRecord(Record);
|
|
|
|
if (!ExpectedRecord)
|
|
|
|
return ExpectedRecord.takeError();
|
|
|
|
Obj.TpiStream->Records.push_back(*ExpectedRecord);
|
2017-01-02 19:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
Error YAMLOutputStyle::dumpIpiStream() {
|
|
|
|
if (!opts::pdb2yaml::IpiStream)
|
|
|
|
return Error::success();
|
|
|
|
|
2017-06-16 21:03:24 +00:00
|
|
|
auto InfoS = File.getPDBInfoStream();
|
|
|
|
if (!InfoS)
|
|
|
|
return InfoS.takeError();
|
|
|
|
if (!InfoS->containsIdStream())
|
|
|
|
return Error::success();
|
|
|
|
|
2017-01-02 19:17:04 +00:00
|
|
|
auto IpiS = File.getPDBIpiStream();
|
|
|
|
if (!IpiS)
|
|
|
|
return IpiS.takeError();
|
|
|
|
|
|
|
|
auto &IS = IpiS.get();
|
|
|
|
Obj.IpiStream.emplace();
|
|
|
|
Obj.IpiStream->Version = IS.getTpiVersion();
|
|
|
|
for (auto &Record : IS.types(nullptr)) {
|
2017-06-01 20:58:36 +00:00
|
|
|
auto ExpectedRecord = CodeViewYAML::LeafRecord::fromCodeViewRecord(Record);
|
|
|
|
if (!ExpectedRecord)
|
|
|
|
return ExpectedRecord.takeError();
|
|
|
|
|
|
|
|
Obj.IpiStream->Records.push_back(*ExpectedRecord);
|
2017-01-02 19:17:04 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
void YAMLOutputStyle::flush() {
|
|
|
|
Out << Obj;
|
|
|
|
outs().flush();
|
|
|
|
}
|