2017-03-14 07:28:25 +08:00
|
|
|
//===- StreamUtil.cpp - PDB stream utilities --------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "StreamUtil.h"
|
2017-07-06 05:54:58 +08:00
|
|
|
#include "FormatUtil.h"
|
2017-03-14 07:28:25 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/DenseMapInfo.h"
|
2017-04-28 00:11:19 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
|
2017-05-05 07:53:29 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/DbiModuleList.h"
|
2017-03-14 07:28:25 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
|
|
|
|
|
2017-07-06 05:54:58 +08:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::pdb;
|
|
|
|
|
2017-08-21 22:53:25 +08:00
|
|
|
std::string StreamInfo::getLongName() const {
|
|
|
|
if (Purpose == StreamPurpose::NamedStream)
|
|
|
|
return formatv("Named Stream \"{0}\"", Name).str();
|
|
|
|
if (Purpose == StreamPurpose::ModuleStream)
|
|
|
|
return formatv("Module \"{0}\"", Name).str();
|
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamInfo StreamInfo::createStream(StreamPurpose Purpose, StringRef Name,
|
|
|
|
uint32_t StreamIndex) {
|
|
|
|
StreamInfo Result;
|
|
|
|
Result.Name = Name;
|
|
|
|
Result.StreamIndex = StreamIndex;
|
|
|
|
Result.Purpose = Purpose;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamInfo StreamInfo::createModuleStream(StringRef Module,
|
|
|
|
uint32_t StreamIndex, uint32_t Modi) {
|
|
|
|
StreamInfo Result;
|
|
|
|
Result.Name = Module;
|
|
|
|
Result.StreamIndex = StreamIndex;
|
|
|
|
Result.ModuleIndex = Modi;
|
|
|
|
Result.Purpose = StreamPurpose::ModuleStream;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2018-03-31 01:16:50 +08:00
|
|
|
static inline StreamInfo stream(StreamPurpose Purpose, StringRef Label,
|
|
|
|
uint32_t Idx) {
|
|
|
|
return StreamInfo::createStream(Purpose, Label, Idx);
|
2017-08-21 22:53:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline StreamInfo moduleStream(StringRef Label, uint32_t StreamIdx,
|
|
|
|
uint32_t Modi) {
|
|
|
|
return StreamInfo::createModuleStream(Label, StreamIdx, Modi);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct IndexedModuleDescriptor {
|
|
|
|
uint32_t Modi;
|
|
|
|
DbiModuleDescriptor Descriptor;
|
|
|
|
};
|
|
|
|
|
|
|
|
void llvm::pdb::discoverStreamPurposes(PDBFile &File,
|
|
|
|
SmallVectorImpl<StreamInfo> &Streams) {
|
2017-03-14 07:28:25 +08:00
|
|
|
// It's OK if we fail to load some of these streams, we still attempt to print
|
|
|
|
// what we can.
|
|
|
|
auto Dbi = File.getPDBDbiStream();
|
|
|
|
auto Tpi = File.getPDBTpiStream();
|
|
|
|
auto Ipi = File.getPDBIpiStream();
|
|
|
|
auto Info = File.getPDBInfoStream();
|
|
|
|
|
|
|
|
uint32_t StreamCount = File.getNumStreams();
|
2017-08-21 22:53:25 +08:00
|
|
|
DenseMap<uint16_t, IndexedModuleDescriptor> ModStreams;
|
2017-03-14 07:28:25 +08:00
|
|
|
DenseMap<uint16_t, std::string> NamedStreams;
|
|
|
|
|
|
|
|
if (Dbi) {
|
2017-05-05 07:53:29 +08:00
|
|
|
const DbiModuleList &Modules = Dbi->modules();
|
|
|
|
for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) {
|
2017-08-21 22:53:25 +08:00
|
|
|
IndexedModuleDescriptor IMD;
|
|
|
|
IMD.Modi = I;
|
|
|
|
IMD.Descriptor = Modules.getModuleDescriptor(I);
|
|
|
|
uint16_t SN = IMD.Descriptor.getModuleStreamIndex();
|
2017-03-14 07:28:25 +08:00
|
|
|
if (SN != kInvalidStreamIndex)
|
2017-08-21 22:53:25 +08:00
|
|
|
ModStreams[SN] = IMD;
|
2017-03-14 07:28:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Info) {
|
|
|
|
for (auto &NSE : Info->named_streams()) {
|
|
|
|
if (NSE.second != kInvalidStreamIndex)
|
|
|
|
NamedStreams[NSE.second] = NSE.first();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-21 22:53:25 +08:00
|
|
|
Streams.resize(StreamCount);
|
2017-03-14 07:28:25 +08:00
|
|
|
for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
|
|
|
|
if (StreamIdx == OldMSFDirectory)
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Old MSF Directory", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (StreamIdx == StreamPDB)
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::PDB, "PDB Stream", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (StreamIdx == StreamDBI)
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::DBI, "DBI Stream", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (StreamIdx == StreamTPI)
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::TPI, "TPI Stream", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (StreamIdx == StreamIPI)
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::IPI, "IPI Stream", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getGlobalSymbolStreamIndex())
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::GlobalHash, "Global Symbol Hash", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getPublicSymbolStreamIndex())
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::PublicHash, "Public Symbol Hash", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getSymRecordStreamIndex())
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Symbols, "Symbol Records", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Tpi && StreamIdx == Tpi->getTypeHashStreamIndex())
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::TpiHash, "TPI Hash", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Tpi && StreamIdx == Tpi->getTypeHashStreamAuxIndex())
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "TPI Aux Hash", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Ipi && StreamIdx == Ipi->getTypeHashStreamIndex())
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::IpiHash, "IPI Hash", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Ipi && StreamIdx == Ipi->getTypeHashStreamAuxIndex())
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "IPI Aux Hash", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Exception))
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Exception Data", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Fixup))
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Fixup Data", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::FPO))
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::Other, "FPO Data", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::NewFPO))
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "New FPO Data", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapFromSrc))
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Omap From Source Data", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapToSrc))
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Omap To Source Data", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Pdata))
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::Other, "Pdata", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdr))
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Section Header Data", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx ==
|
|
|
|
Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdrOrig))
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::Other,
|
|
|
|
"Section Header Original Data", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::TokenRidMap))
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Token Rid Data", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Xdata))
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::Other, "Xdata", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
else {
|
|
|
|
auto ModIter = ModStreams.find(StreamIdx);
|
|
|
|
auto NSIter = NamedStreams.find(StreamIdx);
|
|
|
|
if (ModIter != ModStreams.end()) {
|
2017-08-21 22:53:25 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
moduleStream(ModIter->second.Descriptor.getModuleName(), StreamIdx,
|
|
|
|
ModIter->second.Modi);
|
2017-03-14 07:28:25 +08:00
|
|
|
} else if (NSIter != NamedStreams.end()) {
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::NamedStream, NSIter->second, StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
} else {
|
2018-03-31 01:16:50 +08:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::Other, "???", StreamIdx);
|
2017-03-14 07:28:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Consume errors from missing streams.
|
|
|
|
if (!Dbi)
|
|
|
|
consumeError(Dbi.takeError());
|
|
|
|
if (!Tpi)
|
|
|
|
consumeError(Tpi.takeError());
|
|
|
|
if (!Ipi)
|
|
|
|
consumeError(Ipi.takeError());
|
|
|
|
if (!Info)
|
|
|
|
consumeError(Info.takeError());
|
|
|
|
}
|