summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/llvm-pdbdump
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2015-12-30 13:13:10 +0000
committerdim <dim@FreeBSD.org>2015-12-30 13:13:10 +0000
commit9b5bf5c4f53d65d6a48722d7410ed7cb15f5ba3a (patch)
treeb466a4817f79516eb1df8eae92bccf62ecc84003 /contrib/llvm/tools/llvm-pdbdump
parentf09a28d1de99fda4f5517fb12670fc36552f4927 (diff)
parente194cd6d03d91631334d9d5e55b506036f423cc8 (diff)
downloadFreeBSD-src-9b5bf5c4f53d65d6a48722d7410ed7cb15f5ba3a.zip
FreeBSD-src-9b5bf5c4f53d65d6a48722d7410ed7cb15f5ba3a.tar.gz
Update llvm to trunk r256633.
Diffstat (limited to 'contrib/llvm/tools/llvm-pdbdump')
-rw-r--r--contrib/llvm/tools/llvm-pdbdump/BuiltinDumper.cpp66
-rw-r--r--contrib/llvm/tools/llvm-pdbdump/BuiltinDumper.h2
-rw-r--r--contrib/llvm/tools/llvm-pdbdump/LinePrinter.cpp104
-rw-r--r--contrib/llvm/tools/llvm-pdbdump/LinePrinter.h13
-rw-r--r--contrib/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp299
-rw-r--r--contrib/llvm/tools/llvm-pdbdump/llvm-pdbdump.h3
6 files changed, 380 insertions, 107 deletions
diff --git a/contrib/llvm/tools/llvm-pdbdump/BuiltinDumper.cpp b/contrib/llvm/tools/llvm-pdbdump/BuiltinDumper.cpp
index d808298..4327054 100644
--- a/contrib/llvm/tools/llvm-pdbdump/BuiltinDumper.cpp
+++ b/contrib/llvm/tools/llvm-pdbdump/BuiltinDumper.cpp
@@ -19,69 +19,53 @@ BuiltinDumper::BuiltinDumper(LinePrinter &P)
: PDBSymDumper(false), Printer(P) {}
void BuiltinDumper::start(const PDBSymbolTypeBuiltin &Symbol) {
+ WithColor(Printer, PDB_ColorItem::Type).get() << getTypeName(Symbol);
+}
+
+StringRef BuiltinDumper::getTypeName(const PDBSymbolTypeBuiltin &Symbol) {
PDB_BuiltinType Type = Symbol.getBuiltinType();
switch (Type) {
case PDB_BuiltinType::Float:
if (Symbol.getLength() == 4)
- WithColor(Printer, PDB_ColorItem::Type).get() << "float";
- else
- WithColor(Printer, PDB_ColorItem::Type).get() << "double";
- break;
+ return "float";
+ return "double";
case PDB_BuiltinType::UInt:
- WithColor(Printer, PDB_ColorItem::Type).get() << "unsigned";
if (Symbol.getLength() == 8)
- WithColor(Printer, PDB_ColorItem::Type).get() << " __int64";
- break;
+ return "unsigned __int64";
+ return "unsigned";
case PDB_BuiltinType::Int:
if (Symbol.getLength() == 4)
- WithColor(Printer, PDB_ColorItem::Type).get() << "int";
- else
- WithColor(Printer, PDB_ColorItem::Type).get() << "__int64";
- break;
+ return "int";
+ return "__int64";
case PDB_BuiltinType::Char:
- WithColor(Printer, PDB_ColorItem::Type).get() << "char";
- break;
+ return "char";
case PDB_BuiltinType::WCharT:
- WithColor(Printer, PDB_ColorItem::Type).get() << "wchar_t";
- break;
+ return "wchar_t";
case PDB_BuiltinType::Void:
- WithColor(Printer, PDB_ColorItem::Type).get() << "void";
- break;
+ return "void";
case PDB_BuiltinType::Long:
- WithColor(Printer, PDB_ColorItem::Type).get() << "long";
- break;
+ return "long";
case PDB_BuiltinType::ULong:
- WithColor(Printer, PDB_ColorItem::Type).get() << "unsigned long";
- break;
+ return "unsigned long";
case PDB_BuiltinType::Bool:
- WithColor(Printer, PDB_ColorItem::Type).get() << "bool";
- break;
+ return "bool";
case PDB_BuiltinType::Currency:
- WithColor(Printer, PDB_ColorItem::Type).get() << "CURRENCY";
- break;
+ return "CURRENCY";
case PDB_BuiltinType::Date:
- WithColor(Printer, PDB_ColorItem::Type).get() << "DATE";
- break;
+ return "DATE";
case PDB_BuiltinType::Variant:
- WithColor(Printer, PDB_ColorItem::Type).get() << "VARIANT";
- break;
+ return "VARIANT";
case PDB_BuiltinType::Complex:
- WithColor(Printer, PDB_ColorItem::Type).get() << "complex";
- break;
+ return "complex";
case PDB_BuiltinType::Bitfield:
- WithColor(Printer, PDB_ColorItem::Type).get() << "bitfield";
- break;
+ return "bitfield";
case PDB_BuiltinType::BSTR:
- WithColor(Printer, PDB_ColorItem::Type).get() << "BSTR";
- break;
+ return "BSTR";
case PDB_BuiltinType::HResult:
- WithColor(Printer, PDB_ColorItem::Type).get() << "HRESULT";
- break;
+ return "HRESULT";
case PDB_BuiltinType::BCD:
- WithColor(Printer, PDB_ColorItem::Type).get() << "HRESULT";
- break;
+ return "HRESULT";
default:
- WithColor(Printer, PDB_ColorItem::Type).get() << "void";
- break;
+ return "void";
}
}
diff --git a/contrib/llvm/tools/llvm-pdbdump/BuiltinDumper.h b/contrib/llvm/tools/llvm-pdbdump/BuiltinDumper.h
index 8cf984a0..ac666db 100644
--- a/contrib/llvm/tools/llvm-pdbdump/BuiltinDumper.h
+++ b/contrib/llvm/tools/llvm-pdbdump/BuiltinDumper.h
@@ -23,6 +23,8 @@ public:
void start(const PDBSymbolTypeBuiltin &Symbol);
private:
+ StringRef getTypeName(const PDBSymbolTypeBuiltin &Symbol);
+
LinePrinter &Printer;
};
}
diff --git a/contrib/llvm/tools/llvm-pdbdump/LinePrinter.cpp b/contrib/llvm/tools/llvm-pdbdump/LinePrinter.cpp
index 6bbc403..a43727f 100644
--- a/contrib/llvm/tools/llvm-pdbdump/LinePrinter.cpp
+++ b/contrib/llvm/tools/llvm-pdbdump/LinePrinter.cpp
@@ -11,19 +11,49 @@
#include "llvm-pdbdump.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Regex.h"
#include <algorithm>
+namespace {
+bool IsItemExcluded(llvm::StringRef Item,
+ std::list<llvm::Regex> &IncludeFilters,
+ std::list<llvm::Regex> &ExcludeFilters) {
+ if (Item.empty())
+ return false;
+
+ auto match_pred = [Item](llvm::Regex &R) { return R.match(Item); };
+
+ // Include takes priority over exclude. If the user specified include
+ // filters, and none of them include this item, them item is gone.
+ if (!IncludeFilters.empty() && !any_of(IncludeFilters, match_pred))
+ return true;
+
+ if (any_of(ExcludeFilters, match_pred))
+ return true;
+
+ return false;
+}
+}
+
using namespace llvm;
LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
: OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {
- SetFilters(TypeFilters, opts::ExcludeTypes.begin(), opts::ExcludeTypes.end());
- SetFilters(SymbolFilters, opts::ExcludeSymbols.begin(),
+ SetFilters(ExcludeTypeFilters, opts::ExcludeTypes.begin(),
+ opts::ExcludeTypes.end());
+ SetFilters(ExcludeSymbolFilters, opts::ExcludeSymbols.begin(),
opts::ExcludeSymbols.end());
- SetFilters(CompilandFilters, opts::ExcludeCompilands.begin(),
+ SetFilters(ExcludeCompilandFilters, opts::ExcludeCompilands.begin(),
opts::ExcludeCompilands.end());
+
+ SetFilters(IncludeTypeFilters, opts::IncludeTypes.begin(),
+ opts::IncludeTypes.end());
+ SetFilters(IncludeSymbolFilters, opts::IncludeSymbols.begin(),
+ opts::IncludeSymbols.end());
+ SetFilters(IncludeCompilandFilters, opts::IncludeCompilands.begin(),
+ opts::IncludeCompilands.end());
}
void LinePrinter::Indent() { CurrentIndent += IndentSpaces; }
@@ -38,87 +68,53 @@ void LinePrinter::NewLine() {
}
bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName) {
- if (TypeName.empty())
- return false;
-
- for (auto &Expr : TypeFilters) {
- if (Expr.match(TypeName))
- return true;
- }
- return false;
+ return IsItemExcluded(TypeName, IncludeTypeFilters, ExcludeTypeFilters);
}
bool LinePrinter::IsSymbolExcluded(llvm::StringRef SymbolName) {
- if (SymbolName.empty())
- return false;
-
- for (auto &Expr : SymbolFilters) {
- if (Expr.match(SymbolName))
- return true;
- }
- return false;
+ return IsItemExcluded(SymbolName, IncludeSymbolFilters, ExcludeSymbolFilters);
}
bool LinePrinter::IsCompilandExcluded(llvm::StringRef CompilandName) {
- if (CompilandName.empty())
- return false;
-
- for (auto &Expr : CompilandFilters) {
- if (Expr.match(CompilandName))
- return true;
- }
- return false;
+ return IsItemExcluded(CompilandName, IncludeCompilandFilters,
+ ExcludeCompilandFilters);
}
WithColor::WithColor(LinePrinter &P, PDB_ColorItem C) : OS(P.OS) {
- if (C == PDB_ColorItem::None)
- OS.resetColor();
- else {
- raw_ostream::Colors Color;
- bool Bold;
- translateColor(C, Color, Bold);
- OS.changeColor(Color, Bold);
- }
+ applyColor(C);
}
WithColor::~WithColor() { OS.resetColor(); }
-void WithColor::translateColor(PDB_ColorItem C, raw_ostream::Colors &Color,
- bool &Bold) const {
+void WithColor::applyColor(PDB_ColorItem C) {
switch (C) {
+ case PDB_ColorItem::None:
+ OS.resetColor();
+ return;
case PDB_ColorItem::Address:
- Color = raw_ostream::YELLOW;
- Bold = true;
+ OS.changeColor(raw_ostream::YELLOW, /*bold=*/true);
return;
case PDB_ColorItem::Keyword:
- Color = raw_ostream::MAGENTA;
- Bold = true;
+ OS.changeColor(raw_ostream::MAGENTA, true);
return;
case PDB_ColorItem::Register:
case PDB_ColorItem::Offset:
- Color = raw_ostream::YELLOW;
- Bold = false;
+ OS.changeColor(raw_ostream::YELLOW, false);
return;
case PDB_ColorItem::Type:
- Color = raw_ostream::CYAN;
- Bold = true;
+ OS.changeColor(raw_ostream::CYAN, true);
return;
case PDB_ColorItem::Identifier:
- Color = raw_ostream::CYAN;
- Bold = false;
+ OS.changeColor(raw_ostream::CYAN, false);
return;
case PDB_ColorItem::Path:
- Color = raw_ostream::CYAN;
- Bold = false;
+ OS.changeColor(raw_ostream::CYAN, false);
return;
case PDB_ColorItem::SectionHeader:
- Color = raw_ostream::RED;
- Bold = true;
+ OS.changeColor(raw_ostream::RED, true);
return;
case PDB_ColorItem::LiteralValue:
- Color = raw_ostream::GREEN;
- Bold = true;
- default:
+ OS.changeColor(raw_ostream::GREEN, true);
return;
}
}
diff --git a/contrib/llvm/tools/llvm-pdbdump/LinePrinter.h b/contrib/llvm/tools/llvm-pdbdump/LinePrinter.h
index b985e93..b0a9d2c 100644
--- a/contrib/llvm/tools/llvm-pdbdump/LinePrinter.h
+++ b/contrib/llvm/tools/llvm-pdbdump/LinePrinter.h
@@ -48,9 +48,13 @@ private:
int IndentSpaces;
int CurrentIndent;
- std::list<Regex> CompilandFilters;
- std::list<Regex> TypeFilters;
- std::list<Regex> SymbolFilters;
+ std::list<Regex> ExcludeCompilandFilters;
+ std::list<Regex> ExcludeTypeFilters;
+ std::list<Regex> ExcludeSymbolFilters;
+
+ std::list<Regex> IncludeCompilandFilters;
+ std::list<Regex> IncludeTypeFilters;
+ std::list<Regex> IncludeSymbolFilters;
};
template <class T>
@@ -80,8 +84,7 @@ public:
raw_ostream &get() { return OS; }
private:
- void translateColor(PDB_ColorItem C, raw_ostream::Colors &Color,
- bool &Bold) const;
+ void applyColor(PDB_ColorItem C);
raw_ostream &OS;
};
}
diff --git a/contrib/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp b/contrib/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
index 4a4c64b..0e3f0b2 100644
--- a/contrib/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
+++ b/contrib/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
@@ -22,6 +22,8 @@
#include "VariableDumper.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/config.h"
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
@@ -38,12 +40,16 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Signals.h"
#if defined(HAVE_DIA_SDK)
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
#include <Windows.h>
#endif
@@ -79,6 +85,17 @@ cl::opt<uint64_t> LoadAddress(
cl::desc("Assume the module is loaded at the specified address"),
cl::cat(OtherOptions));
+cl::opt<bool> DumpHeaders("dump-headers", cl::desc("dump PDB headers"),
+ cl::cat(OtherOptions));
+cl::opt<bool> DumpStreamSizes("dump-stream-sizes",
+ cl::desc("dump PDB stream sizes"),
+ cl::cat(OtherOptions));
+cl::opt<bool> DumpStreamBlocks("dump-stream-blocks",
+ cl::desc("dump PDB stream blocks"),
+ cl::cat(OtherOptions));
+cl::opt<std::string> DumpStreamData("dump-stream", cl::desc("dump stream data"),
+ cl::cat(OtherOptions));
+
cl::list<std::string>
ExcludeTypes("exclude-types",
cl::desc("Exclude types by regular expression"),
@@ -91,6 +108,20 @@ cl::list<std::string>
ExcludeCompilands("exclude-compilands",
cl::desc("Exclude compilands by regular expression"),
cl::ZeroOrMore, cl::cat(FilterCategory));
+
+cl::list<std::string> IncludeTypes(
+ "include-types",
+ cl::desc("Include only types which match a regular expression"),
+ cl::ZeroOrMore, cl::cat(FilterCategory));
+cl::list<std::string> IncludeSymbols(
+ "include-symbols",
+ cl::desc("Include only symbols which match a regular expression"),
+ cl::ZeroOrMore, cl::cat(FilterCategory));
+cl::list<std::string> IncludeCompilands(
+ "include-compilands",
+ cl::desc("Include only compilands those which match a regular expression"),
+ cl::ZeroOrMore, cl::cat(FilterCategory));
+
cl::opt<bool> ExcludeCompilerGenerated(
"no-compiler-generated",
cl::desc("Don't show compiler generated types and symbols"),
@@ -107,10 +138,264 @@ cl::opt<bool> NoEnumDefs("no-enum-definitions",
cl::cat(FilterCategory));
}
+
+static void reportError(StringRef Input, StringRef Message) {
+ if (Input == "-")
+ Input = "<stdin>";
+ errs() << Input << ": " << Message << "\n";
+ errs().flush();
+ exit(1);
+}
+
+static void reportError(StringRef Input, std::error_code EC) {
+ reportError(Input, EC.message());
+}
+
+static std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr,
+ const uint64_t Size) {
+ if (Addr + Size < Addr || Addr + Size < Size ||
+ Addr + Size > uintptr_t(M.getBufferEnd()) ||
+ Addr < uintptr_t(M.getBufferStart())) {
+ return std::make_error_code(std::errc::bad_address);
+ }
+ return std::error_code();
+}
+
+template <typename T>
+static std::error_code checkOffset(MemoryBufferRef M, ArrayRef<T> AR) {
+ return checkOffset(M, uintptr_t(AR.data()), (uint64_t)AR.size() * sizeof(T));
+}
+
+static std::error_code checkOffset(MemoryBufferRef M, StringRef SR) {
+ return checkOffset(M, uintptr_t(SR.data()), SR.size());
+}
+
+// Sets Obj unless any bytes in [addr, addr + size) fall outsize of m.
+// Returns unexpected_eof if error.
+template <typename T>
+static std::error_code getObject(const T *&Obj, MemoryBufferRef M,
+ const void *Ptr,
+ const uint64_t Size = sizeof(T)) {
+ uintptr_t Addr = uintptr_t(Ptr);
+ if (std::error_code EC = checkOffset(M, Addr, Size))
+ return EC;
+ Obj = reinterpret_cast<const T *>(Addr);
+ return std::error_code();
+}
+
+static uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize) {
+ return RoundUpToAlignment(NumBytes, BlockSize) / BlockSize;
+}
+
+static uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize) {
+ return BlockNumber * BlockSize;
+}
+
+static void dumpStructure(MemoryBufferRef M) {
+ const PDB::SuperBlock *SB;
+ if (auto EC = getObject(SB, M, M.getBufferStart()))
+ reportError(M.getBufferIdentifier(), EC);
+
+ if (opts::DumpHeaders) {
+ outs() << "BlockSize: " << SB->BlockSize << '\n';
+ outs() << "Unknown0: " << SB->Unknown0 << '\n';
+ outs() << "NumBlocks: " << SB->NumBlocks << '\n';
+ outs() << "NumDirectoryBytes: " << SB->NumDirectoryBytes << '\n';
+ outs() << "Unknown1: " << SB->Unknown1 << '\n';
+ outs() << "BlockMapAddr: " << SB->BlockMapAddr << '\n';
+ }
+
+ // We don't support blocksizes which aren't a multiple of four bytes.
+ if (SB->BlockSize % sizeof(support::ulittle32_t) != 0)
+ reportError(M.getBufferIdentifier(),
+ std::make_error_code(std::errc::illegal_byte_sequence));
+
+ // We don't support directories whose sizes aren't a multiple of four bytes.
+ if (SB->NumDirectoryBytes % sizeof(support::ulittle32_t) != 0)
+ reportError(M.getBufferIdentifier(),
+ std::make_error_code(std::errc::illegal_byte_sequence));
+
+ // The number of blocks which comprise the directory is a simple function of
+ // the number of bytes it contains.
+ uint64_t NumDirectoryBlocks =
+ bytesToBlocks(SB->NumDirectoryBytes, SB->BlockSize);
+ if (opts::DumpHeaders)
+ outs() << "NumDirectoryBlocks: " << NumDirectoryBlocks << '\n';
+
+ // The block map, as we understand it, is a block which consists of a list of
+ // block numbers.
+ // It is unclear what would happen if the number of blocks couldn't fit on a
+ // single block.
+ if (NumDirectoryBlocks > SB->BlockSize / sizeof(support::ulittle32_t))
+ reportError(M.getBufferIdentifier(),
+ std::make_error_code(std::errc::illegal_byte_sequence));
+
+
+ uint64_t BlockMapOffset = (uint64_t)SB->BlockMapAddr * SB->BlockSize;
+ if (opts::DumpHeaders)
+ outs() << "BlockMapOffset: " << BlockMapOffset << '\n';
+
+ // The directory is not contiguous. Instead, the block map contains a
+ // contiguous list of block numbers whose contents, when concatenated in
+ // order, make up the directory.
+ auto DirectoryBlocks =
+ makeArrayRef(reinterpret_cast<const support::ulittle32_t *>(
+ M.getBufferStart() + BlockMapOffset),
+ NumDirectoryBlocks);
+ if (auto EC = checkOffset(M, DirectoryBlocks))
+ reportError(M.getBufferIdentifier(), EC);
+
+ if (opts::DumpHeaders) {
+ outs() << "DirectoryBlocks: [";
+ for (const support::ulittle32_t &DirectoryBlockAddr : DirectoryBlocks) {
+ if (&DirectoryBlockAddr != &DirectoryBlocks.front())
+ outs() << ", ";
+ outs() << DirectoryBlockAddr;
+ }
+ outs() << "]\n";
+ }
+
+ bool SeenNumStreams = false;
+ uint32_t NumStreams = 0;
+ std::vector<uint32_t> StreamSizes;
+ DenseMap<uint32_t, std::vector<uint32_t>> StreamMap;
+ uint32_t StreamIdx = 0;
+ uint64_t DirectoryBytesRead = 0;
+ // The structure of the directory is as follows:
+ // struct PDBDirectory {
+ // uint32_t NumStreams;
+ // uint32_t StreamSizes[NumStreams];
+ // uint32_t StreamMap[NumStreams][];
+ // };
+ //
+ // Empty streams don't consume entries in the StreamMap.
+ for (uint32_t DirectoryBlockAddr : DirectoryBlocks) {
+ uint64_t DirectoryBlockOffset =
+ blockToOffset(DirectoryBlockAddr, SB->BlockSize);
+ auto DirectoryBlock =
+ makeArrayRef(reinterpret_cast<const support::ulittle32_t *>(
+ M.getBufferStart() + DirectoryBlockOffset),
+ SB->BlockSize / sizeof(support::ulittle32_t));
+ if (auto EC = checkOffset(M, DirectoryBlock))
+ reportError(M.getBufferIdentifier(), EC);
+
+ // We read data out of the directory four bytes at a time. Depending on
+ // where we are in the directory, the contents may be: the number of streams
+ // in the directory, a stream's size, or a block in the stream map.
+ for (uint32_t Data : DirectoryBlock) {
+ // Don't read beyond the end of the directory.
+ if (DirectoryBytesRead == SB->NumDirectoryBytes)
+ break;
+
+ DirectoryBytesRead += sizeof(Data);
+
+ // This data must be the number of streams if we haven't seen it yet.
+ if (!SeenNumStreams) {
+ NumStreams = Data;
+ SeenNumStreams = true;
+ continue;
+ }
+ // This data must be a stream size if we have not seen them all yet.
+ if (StreamSizes.size() < NumStreams) {
+ // It seems like some streams have their set to -1 when their contents
+ // are not present. Treat them like empty streams for now.
+ if (Data == UINT32_MAX)
+ StreamSizes.push_back(0);
+ else
+ StreamSizes.push_back(Data);
+ continue;
+ }
+
+ // This data must be a stream block number if we have seen all of the
+ // stream sizes.
+ std::vector<uint32_t> *StreamBlocks = nullptr;
+ // Figure out which stream this block number belongs to.
+ while (StreamIdx < NumStreams) {
+ uint64_t NumExpectedStreamBlocks =
+ bytesToBlocks(StreamSizes[StreamIdx], SB->BlockSize);
+ StreamBlocks = &StreamMap[StreamIdx];
+ if (NumExpectedStreamBlocks > StreamBlocks->size())
+ break;
+ ++StreamIdx;
+ }
+ // It seems this block doesn't belong to any stream? The stream is either
+ // corrupt or something more mysterious is going on.
+ if (StreamIdx == NumStreams)
+ reportError(M.getBufferIdentifier(),
+ std::make_error_code(std::errc::illegal_byte_sequence));
+
+ StreamBlocks->push_back(Data);
+ }
+ }
+
+ // We should have read exactly SB->NumDirectoryBytes bytes.
+ assert(DirectoryBytesRead == SB->NumDirectoryBytes);
+
+ if (opts::DumpHeaders)
+ outs() << "NumStreams: " << NumStreams << '\n';
+ if (opts::DumpStreamSizes)
+ for (uint32_t StreamIdx = 0; StreamIdx < NumStreams; ++StreamIdx)
+ outs() << "StreamSizes[" << StreamIdx << "]: " << StreamSizes[StreamIdx]
+ << '\n';
+
+ if (opts::DumpStreamBlocks) {
+ for (uint32_t StreamIdx = 0; StreamIdx < NumStreams; ++StreamIdx) {
+ outs() << "StreamBlocks[" << StreamIdx << "]: [";
+ std::vector<uint32_t> &StreamBlocks = StreamMap[StreamIdx];
+ for (uint32_t &StreamBlock : StreamBlocks) {
+ if (&StreamBlock != &StreamBlocks.front())
+ outs() << ", ";
+ outs() << StreamBlock;
+ }
+ outs() << "]\n";
+ }
+ }
+
+ StringRef DumpStreamStr = opts::DumpStreamData;
+ uint32_t DumpStreamNum;
+ if (!DumpStreamStr.getAsInteger(/*Radix=*/0U, DumpStreamNum) &&
+ DumpStreamNum < NumStreams) {
+ uint32_t StreamBytesRead = 0;
+ uint32_t StreamSize = StreamSizes[DumpStreamNum];
+ std::vector<uint32_t> &StreamBlocks = StreamMap[DumpStreamNum];
+ for (uint32_t &StreamBlockAddr : StreamBlocks) {
+ uint64_t StreamBlockOffset = blockToOffset(StreamBlockAddr, SB->BlockSize);
+ uint32_t BytesLeftToReadInStream = StreamSize - StreamBytesRead;
+ if (BytesLeftToReadInStream == 0)
+ break;
+
+ uint32_t BytesToReadInBlock = std::min(
+ BytesLeftToReadInStream, static_cast<uint32_t>(SB->BlockSize));
+ auto StreamBlockData =
+ StringRef(M.getBufferStart() + StreamBlockOffset, BytesToReadInBlock);
+ if (auto EC = checkOffset(M, StreamBlockData))
+ reportError(M.getBufferIdentifier(), EC);
+
+ outs() << StreamBlockData;
+ StreamBytesRead += StreamBlockData.size();
+ }
+ }
+}
+
static void dumpInput(StringRef Path) {
+ if (opts::DumpHeaders || !opts::DumpStreamData.empty()) {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
+ MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
+ /*RequiresNullTerminator=*/false);
+
+ if (std::error_code EC = ErrorOrBuffer.getError())
+ reportError(Path, EC);
+
+ std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();
+
+ dumpStructure(Buffer->getMemBufferRef());
+
+ outs().flush();
+ return;
+ }
+
std::unique_ptr<IPDBSession> Session;
- PDB_ErrorCode Error =
- llvm::loadDataForPDB(PDB_ReaderType::DIA, Path, Session);
+ PDB_ErrorCode Error = loadDataForPDB(PDB_ReaderType::DIA, Path, Session);
switch (Error) {
case PDB_ErrorCode::Success:
break;
@@ -145,7 +430,7 @@ static void dumpInput(StringRef Path) {
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Size";
- if (!llvm::sys::fs::file_size(FileName, FileSize)) {
+ if (!sys::fs::file_size(FileName, FileSize)) {
Printer << ": " << FileSize << " bytes";
} else {
Printer << ": (Unable to obtain file size)";
@@ -242,11 +527,11 @@ int main(int argc_, const char *argv_[]) {
PrettyStackTraceProgram X(argc_, argv_);
SmallVector<const char *, 256> argv;
- llvm::SpecificBumpPtrAllocator<char> ArgAllocator;
- std::error_code EC = llvm::sys::Process::GetArgumentVector(
- argv, llvm::makeArrayRef(argv_, argc_), ArgAllocator);
+ SpecificBumpPtrAllocator<char> ArgAllocator;
+ std::error_code EC = sys::Process::GetArgumentVector(
+ argv, makeArrayRef(argv_, argc_), ArgAllocator);
if (EC) {
- llvm::errs() << "error: couldn't get arguments: " << EC.message() << '\n';
+ errs() << "error: couldn't get arguments: " << EC.message() << '\n';
return 1;
}
diff --git a/contrib/llvm/tools/llvm-pdbdump/llvm-pdbdump.h b/contrib/llvm/tools/llvm-pdbdump/llvm-pdbdump.h
index 586a9ea..cb5bec6 100644
--- a/contrib/llvm/tools/llvm-pdbdump/llvm-pdbdump.h
+++ b/contrib/llvm/tools/llvm-pdbdump/llvm-pdbdump.h
@@ -27,6 +27,9 @@ extern llvm::cl::opt<bool> NoEnumDefs;
extern llvm::cl::list<std::string> ExcludeTypes;
extern llvm::cl::list<std::string> ExcludeSymbols;
extern llvm::cl::list<std::string> ExcludeCompilands;
+extern llvm::cl::list<std::string> IncludeTypes;
+extern llvm::cl::list<std::string> IncludeSymbols;
+extern llvm::cl::list<std::string> IncludeCompilands;
}
#endif \ No newline at end of file
OpenPOWER on IntegriCloud