2017-03-14 00:28:25 +01:00
|
|
|
//===- StreamUtil.cpp - PDB stream utilities --------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-03-14 00:28:25 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "StreamUtil.h"
|
2017-07-05 23:54:58 +02:00
|
|
|
#include "FormatUtil.h"
|
2017-03-14 00:28:25 +01:00
|
|
|
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/DenseMapInfo.h"
|
2017-04-27 18:11:19 +02:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
|
2017-05-05 01:53:29 +02:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/DbiModuleList.h"
|
2017-03-14 00:28:25 +01: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-05 23:54:58 +02:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::pdb;
|
|
|
|
|
2017-08-21 16:53:25 +02: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;
|
2020-01-28 20:23:46 +01:00
|
|
|
Result.Name = std::string(Name);
|
2017-08-21 16:53:25 +02:00
|
|
|
Result.StreamIndex = StreamIndex;
|
|
|
|
Result.Purpose = Purpose;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamInfo StreamInfo::createModuleStream(StringRef Module,
|
|
|
|
uint32_t StreamIndex, uint32_t Modi) {
|
|
|
|
StreamInfo Result;
|
2020-01-28 20:23:46 +01:00
|
|
|
Result.Name = std::string(Module);
|
2017-08-21 16:53:25 +02:00
|
|
|
Result.StreamIndex = StreamIndex;
|
|
|
|
Result.ModuleIndex = Modi;
|
|
|
|
Result.Purpose = StreamPurpose::ModuleStream;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2018-03-30 19:16:50 +02:00
|
|
|
static inline StreamInfo stream(StreamPurpose Purpose, StringRef Label,
|
|
|
|
uint32_t Idx) {
|
|
|
|
return StreamInfo::createStream(Purpose, Label, Idx);
|
2017-08-21 16:53:25 +02: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 00:28:25 +01: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 16:53:25 +02:00
|
|
|
DenseMap<uint16_t, IndexedModuleDescriptor> ModStreams;
|
2017-03-14 00:28:25 +01:00
|
|
|
DenseMap<uint16_t, std::string> NamedStreams;
|
|
|
|
|
|
|
|
if (Dbi) {
|
2017-05-05 01:53:29 +02:00
|
|
|
const DbiModuleList &Modules = Dbi->modules();
|
|
|
|
for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) {
|
2017-08-21 16:53:25 +02:00
|
|
|
IndexedModuleDescriptor IMD;
|
|
|
|
IMD.Modi = I;
|
|
|
|
IMD.Descriptor = Modules.getModuleDescriptor(I);
|
|
|
|
uint16_t SN = IMD.Descriptor.getModuleStreamIndex();
|
2017-03-14 00:28:25 +01:00
|
|
|
if (SN != kInvalidStreamIndex)
|
2017-08-21 16:53:25 +02:00
|
|
|
ModStreams[SN] = IMD;
|
2017-03-14 00:28:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Info) {
|
|
|
|
for (auto &NSE : Info->named_streams()) {
|
|
|
|
if (NSE.second != kInvalidStreamIndex)
|
2020-01-28 20:23:46 +01:00
|
|
|
NamedStreams[NSE.second] = std::string(NSE.first());
|
2017-03-14 00:28:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-21 16:53:25 +02:00
|
|
|
Streams.resize(StreamCount);
|
2017-03-14 00:28:25 +01:00
|
|
|
for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
|
|
|
|
if (StreamIdx == OldMSFDirectory)
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Old MSF Directory", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (StreamIdx == StreamPDB)
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::PDB, "PDB Stream", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (StreamIdx == StreamDBI)
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::DBI, "DBI Stream", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (StreamIdx == StreamTPI)
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::TPI, "TPI Stream", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (StreamIdx == StreamIPI)
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::IPI, "IPI Stream", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getGlobalSymbolStreamIndex())
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::GlobalHash, "Global Symbol Hash", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getPublicSymbolStreamIndex())
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::PublicHash, "Public Symbol Hash", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getSymRecordStreamIndex())
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Symbols, "Symbol Records", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Tpi && StreamIdx == Tpi->getTypeHashStreamIndex())
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::TpiHash, "TPI Hash", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Tpi && StreamIdx == Tpi->getTypeHashStreamAuxIndex())
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "TPI Aux Hash", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Ipi && StreamIdx == Ipi->getTypeHashStreamIndex())
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::IpiHash, "IPI Hash", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Ipi && StreamIdx == Ipi->getTypeHashStreamAuxIndex())
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "IPI Aux Hash", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Exception))
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Exception Data", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Fixup))
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Fixup Data", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::FPO))
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::Other, "FPO Data", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::NewFPO))
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "New FPO Data", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapFromSrc))
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Omap From Source Data", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapToSrc))
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Omap To Source Data", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Pdata))
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::Other, "Pdata", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdr))
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Section Header Data", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx ==
|
|
|
|
Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdrOrig))
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::Other,
|
|
|
|
"Section Header Original Data", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi &&
|
|
|
|
StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::TokenRidMap))
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::Other, "Token Rid Data", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Xdata))
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::Other, "Xdata", StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
else {
|
|
|
|
auto ModIter = ModStreams.find(StreamIdx);
|
|
|
|
auto NSIter = NamedStreams.find(StreamIdx);
|
|
|
|
if (ModIter != ModStreams.end()) {
|
2017-08-21 16:53:25 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
moduleStream(ModIter->second.Descriptor.getModuleName(), StreamIdx,
|
|
|
|
ModIter->second.Modi);
|
2017-03-14 00:28:25 +01:00
|
|
|
} else if (NSIter != NamedStreams.end()) {
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] =
|
|
|
|
stream(StreamPurpose::NamedStream, NSIter->second, StreamIdx);
|
2017-03-14 00:28:25 +01:00
|
|
|
} else {
|
2018-03-30 19:16:50 +02:00
|
|
|
Streams[StreamIdx] = stream(StreamPurpose::Other, "???", StreamIdx);
|
2017-03-14 00:28:25 +01: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());
|
|
|
|
}
|