2016-06-07 04:37:05 +08: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"
|
|
|
|
#include "llvm-pdbdump.h"
|
|
|
|
|
2016-07-12 05:45:26 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
|
2016-07-07 02:05:57 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
|
2016-06-07 04:37:05 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
|
2016-07-01 01:43:00 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
|
2016-06-07 04:37:05 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::pdb;
|
|
|
|
|
|
|
|
YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) : File(File), Out(outs()) {}
|
|
|
|
|
2016-07-01 01:42:48 +08:00
|
|
|
Error YAMLOutputStyle::dump() {
|
2016-07-16 06:16:56 +08:00
|
|
|
if (opts::pdb2yaml::StreamDirectory)
|
2016-07-07 02:05:57 +08:00
|
|
|
opts::pdb2yaml::StreamMetadata = true;
|
|
|
|
|
2016-07-01 01:42:48 +08:00
|
|
|
if (auto EC = dumpFileHeaders())
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
if (auto EC = dumpStreamMetadata())
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
if (auto EC = dumpStreamDirectory())
|
|
|
|
return EC;
|
|
|
|
|
2016-07-07 02:05:57 +08:00
|
|
|
if (auto EC = dumpPDBStream())
|
|
|
|
return EC;
|
|
|
|
|
2016-07-12 05:45:26 +08:00
|
|
|
if (auto EC = dumpDbiStream())
|
|
|
|
return EC;
|
|
|
|
|
2016-07-01 01:42:48 +08:00
|
|
|
flush();
|
|
|
|
return Error::success();
|
|
|
|
}
|
2016-06-07 04:37:05 +08:00
|
|
|
|
2016-07-01 01:42:48 +08:00
|
|
|
Error YAMLOutputStyle::dumpFileHeaders() {
|
2016-07-12 05:45:09 +08:00
|
|
|
if (opts::pdb2yaml::NoFileHeaders)
|
|
|
|
return Error::success();
|
|
|
|
|
2016-06-07 04:37:05 +08:00
|
|
|
yaml::MsfHeaders Headers;
|
2016-07-12 05:45:09 +08:00
|
|
|
Obj.Headers.emplace();
|
|
|
|
Obj.Headers->SuperBlock.NumBlocks = File.getBlockCount();
|
|
|
|
Obj.Headers->SuperBlock.BlockMapAddr = File.getBlockMapIndex();
|
|
|
|
Obj.Headers->SuperBlock.BlockSize = File.getBlockSize();
|
2016-06-07 04:37:05 +08:00
|
|
|
auto Blocks = File.getDirectoryBlockArray();
|
2016-07-12 05:45:09 +08:00
|
|
|
Obj.Headers->DirectoryBlocks.assign(Blocks.begin(), Blocks.end());
|
|
|
|
Obj.Headers->NumDirectoryBlocks = File.getNumDirectoryBlocks();
|
|
|
|
Obj.Headers->SuperBlock.NumDirectoryBytes = File.getNumDirectoryBytes();
|
|
|
|
Obj.Headers->NumStreams =
|
2016-07-01 01:43:00 +08:00
|
|
|
opts::pdb2yaml::StreamMetadata ? File.getNumStreams() : 0;
|
2016-07-16 06:17:19 +08:00
|
|
|
Obj.Headers->SuperBlock.FreeBlockMapBlock = File.getFreeBlockMapBlock();
|
2016-07-12 05:45:09 +08:00
|
|
|
Obj.Headers->SuperBlock.Unknown1 = File.getUnknown1();
|
|
|
|
Obj.Headers->FileSize = File.getFileSize();
|
2016-06-07 04:37:05 +08:00
|
|
|
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2016-07-01 01:42:48 +08:00
|
|
|
Error YAMLOutputStyle::dumpStreamMetadata() {
|
|
|
|
if (!opts::pdb2yaml::StreamMetadata)
|
2016-06-07 04:37:05 +08:00
|
|
|
return Error::success();
|
|
|
|
|
2016-07-16 06:16:56 +08:00
|
|
|
Obj.StreamSizes.emplace();
|
|
|
|
Obj.StreamSizes->assign(File.getStreamSizes().begin(),
|
|
|
|
File.getStreamSizes().end());
|
2016-06-07 04:37:05 +08:00
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2016-07-01 01:42:48 +08:00
|
|
|
Error YAMLOutputStyle::dumpStreamDirectory() {
|
|
|
|
if (!opts::pdb2yaml::StreamDirectory)
|
2016-06-07 04:37:05 +08:00
|
|
|
return Error::success();
|
|
|
|
|
2016-06-15 04:48:36 +08:00
|
|
|
auto StreamMap = File.getStreamMap();
|
|
|
|
Obj.StreamMap.emplace();
|
|
|
|
for (auto &Stream : StreamMap) {
|
|
|
|
pdb::yaml::StreamBlockList BlockList;
|
2016-07-16 06:16:56 +08:00
|
|
|
BlockList.Blocks.assign(Stream.begin(), Stream.end());
|
2016-06-15 04:48:36 +08:00
|
|
|
Obj.StreamMap->push_back(BlockList);
|
2016-06-07 04:37:17 +08:00
|
|
|
}
|
|
|
|
|
2016-06-07 04:37:05 +08:00
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2016-07-07 02:05:57 +08:00
|
|
|
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();
|
2016-07-16 06:17:08 +08:00
|
|
|
for (auto &NS : InfoS.named_streams()) {
|
|
|
|
yaml::NamedStreamMapping Mapping;
|
|
|
|
Mapping.StreamName = NS.getKey();
|
|
|
|
Mapping.StreamNumber = NS.getValue();
|
|
|
|
Obj.PdbStream->NamedStreams.push_back(Mapping);
|
|
|
|
}
|
2016-07-07 02:05:57 +08:00
|
|
|
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2016-07-12 05:45:26 +08: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();
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2016-06-07 04:37:05 +08:00
|
|
|
void YAMLOutputStyle::flush() {
|
|
|
|
Out << Obj;
|
|
|
|
outs().flush();
|
|
|
|
}
|