aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-06-23 20:18:38 +0000
committerZachary Turner <zturner@google.com>2017-06-23 20:18:38 +0000
commita77c3fdb212d6a9b687b2ec239616d78fcab504b (patch)
treedfb2c07217e7e458cd3a0cec546397bc681655f7
parentddb4efa8b2bec97dedf9580bca5fff38af6670ba (diff)
downloadllvm-a77c3fdb212d6a9b687b2ec239616d78fcab504b.tar.gz
[llvm-pdbutil] Dump raw bytes of pdb name map.
This patch dumps the raw bytes of the pdb name map which contains the mapping of stream name to stream index for the string table and other reserved streams. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306148 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/DebugInfo/PDB/Native/InfoStream.h4
-rw-r--r--lib/DebugInfo/PDB/Native/InfoStream.cpp8
-rw-r--r--test/DebugInfo/PDB/pdbdump-raw-bytes.test10
-rw-r--r--tools/llvm-pdbutil/BytesOutputStyle.cpp17
-rw-r--r--tools/llvm-pdbutil/BytesOutputStyle.h2
-rw-r--r--tools/llvm-pdbutil/LinePrinter.cpp19
-rw-r--r--tools/llvm-pdbutil/LinePrinter.h3
-rw-r--r--tools/llvm-pdbutil/llvm-pdbutil.cpp3
-rw-r--r--tools/llvm-pdbutil/llvm-pdbutil.h1
9 files changed, 52 insertions, 15 deletions
diff --git a/include/llvm/DebugInfo/PDB/Native/InfoStream.h b/include/llvm/DebugInfo/PDB/Native/InfoStream.h
index fc91fc7097b..37bf5f3b573 100644
--- a/include/llvm/DebugInfo/PDB/Native/InfoStream.h
+++ b/include/llvm/DebugInfo/PDB/Native/InfoStream.h
@@ -47,6 +47,8 @@ public:
const NamedStreamMap &getNamedStreams() const;
+ BinarySubstreamRef getNamedStreamsBuffer() const;
+
uint32_t getNamedStreamIndex(llvm::StringRef Name) const;
iterator_range<StringMapConstIterator<uint32_t>> named_streams() const;
@@ -71,6 +73,8 @@ private:
// universally unique.
PDB_UniqueId Guid;
+ BinarySubstreamRef SubNamedStreams;
+
std::vector<PdbRaw_FeatureSig> FeatureSignatures;
PdbRaw_Features Features = PdbFeatureNone;
diff --git a/lib/DebugInfo/PDB/Native/InfoStream.cpp b/lib/DebugInfo/PDB/Native/InfoStream.cpp
index a3979d480bf..21b66b3e7bc 100644
--- a/lib/DebugInfo/PDB/Native/InfoStream.cpp
+++ b/lib/DebugInfo/PDB/Native/InfoStream.cpp
@@ -57,6 +57,10 @@ Error InfoStream::reload() {
uint32_t NewOffset = Reader.getOffset();
NamedStreamMapByteSize = NewOffset - Offset;
+ Reader.setOffset(Offset);
+ if (auto EC = Reader.readSubstream(SubNamedStreams, NamedStreamMapByteSize))
+ return EC;
+
bool Stop = false;
while (!Stop && !Reader.empty()) {
PdbRaw_FeatureSig Sig;
@@ -129,3 +133,7 @@ ArrayRef<PdbRaw_FeatureSig> InfoStream::getFeatureSignatures() const {
const NamedStreamMap &InfoStream::getNamedStreams() const {
return NamedStreams;
}
+
+BinarySubstreamRef InfoStream::getNamedStreamsBuffer() const {
+ return SubNamedStreams;
+}
diff --git a/test/DebugInfo/PDB/pdbdump-raw-bytes.test b/test/DebugInfo/PDB/pdbdump-raw-bytes.test
index 2c5c96c5a38..1087dfb6595 100644
--- a/test/DebugInfo/PDB/pdbdump-raw-bytes.test
+++ b/test/DebugInfo/PDB/pdbdump-raw-bytes.test
@@ -2,6 +2,8 @@
; RUN: not llvm-pdbutil bytes -byte-range=100-20 %p/Inputs/empty.pdb 2>&1 | FileCheck --check-prefix=INVALID %s
; RUN: not llvm-pdbutil bytes -byte-range=100000-200000 %p/Inputs/empty.pdb 2>&1 | FileCheck --check-prefix=INVALID-RANGE %s
+; RUN: llvm-pdbutil bytes -name-map %p/Inputs/empty.pdb | FileCheck --check-prefix=NAME-MAP %s
+
VALID: MSF Bytes
VALID-NEXT: ============================================================
@@ -13,3 +15,11 @@ VALID-NEXT: )
INVALID: llvm-pdbutil: Invalid byte range specified. Max < Min
INVALID-RANGE: llvm-pdbutil: Invalid byte range specified. Requested byte larger than file size
+
+NAME-MAP: Named Stream Map
+NAME-MAP-NEXT: ============================================================
+NAME-MAP-NEXT: Named Stream Map (
+NAME-MAP-NEXT: 1301C: 22000000 2F4C696E 6B496E66 6F002F6E 616D6573 002F7372 632F6865 61646572 |".../LinkInfo./names./src/header|
+NAME-MAP-NEXT: 1303C: 626C6F63 6B000300 00000600 00000100 00001A00 00000000 00001100 00000900 |block...........................|
+NAME-MAP-NEXT: 1305C: 00000A00 00000D00 00000000 00000500 0000 |..................|
+NAME-MAP-NEXT: )
diff --git a/tools/llvm-pdbutil/BytesOutputStyle.cpp b/tools/llvm-pdbutil/BytesOutputStyle.cpp
index 9761987f076..5cf15685fe3 100644
--- a/tools/llvm-pdbutil/BytesOutputStyle.cpp
+++ b/tools/llvm-pdbutil/BytesOutputStyle.cpp
@@ -13,6 +13,7 @@
#include "llvm-pdbutil.h"
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
+#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/RawError.h"
#include "llvm/Support/BinaryStreamReader.h"
@@ -116,9 +117,25 @@ Error BytesOutputStyle::dump() {
dumpStreamBytes();
P.NewLine();
}
+
+ if (opts::bytes::NameMap) {
+ dumpNameMap();
+ P.NewLine();
+ }
return Error::success();
}
+void BytesOutputStyle::dumpNameMap() {
+ printHeader(P, "Named Stream Map");
+
+ AutoIndent Indent(P);
+
+ auto &InfoS = Err(File.getPDBInfoStream());
+ BinarySubstreamRef NS = InfoS.getNamedStreamsBuffer();
+ auto Layout = File.getStreamLayout(StreamPDB);
+ P.formatMsfStreamData("Named Stream Map", File, Layout, NS);
+}
+
void BytesOutputStyle::dumpBlockRanges(uint32_t Min, uint32_t Max) {
printHeader(P, "MSF Blocks");
diff --git a/tools/llvm-pdbutil/BytesOutputStyle.h b/tools/llvm-pdbutil/BytesOutputStyle.h
index a2cefbbfb4c..4cf6937d99b 100644
--- a/tools/llvm-pdbutil/BytesOutputStyle.h
+++ b/tools/llvm-pdbutil/BytesOutputStyle.h
@@ -28,12 +28,14 @@ public:
Error dump() override;
private:
+ void dumpNameMap();
void dumpBlockRanges(uint32_t Min, uint32_t Max);
void dumpByteRanges(uint32_t Min, uint32_t Max);
void dumpStreamBytes();
PDBFile &File;
LinePrinter P;
+ ExitOnError Err;
SmallVector<std::string, 8> StreamPurposes;
};
} // namespace pdb
diff --git a/tools/llvm-pdbutil/LinePrinter.cpp b/tools/llvm-pdbutil/LinePrinter.cpp
index a5f48f05859..a9761b4337b 100644
--- a/tools/llvm-pdbutil/LinePrinter.cpp
+++ b/tools/llvm-pdbutil/LinePrinter.cpp
@@ -203,11 +203,12 @@ void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
StreamPurpose, Size, S->getLength());
AutoIndent Indent(*this);
BinaryStreamRef Slice(*S);
- Slice = Slice.keep_front(Offset + Size);
- BinaryStreamReader Reader(Slice);
- consumeError(Reader.skip(Offset));
+ BinarySubstreamRef Substream;
+ Substream.Offset = Offset;
+ Substream.StreamData = Slice.drop_front(Offset).keep_front(Size);
+
auto Layout = File.getStreamLayout(StreamIdx);
- formatMsfStreamData(Label, File, Layout, Reader);
+ formatMsfStreamData(Label, File, Layout, Substream);
}
void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
@@ -215,13 +216,6 @@ void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
BinarySubstreamRef Substream) {
BinaryStreamReader Reader(Substream.StreamData);
- consumeError(Reader.skip(Substream.Offset));
- formatMsfStreamData(Label, File, Stream, Reader);
-}
-
-void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
- const msf::MSFStreamLayout &Stream,
- BinaryStreamReader &Reader) {
auto Runs = computeBlockRuns(File.getBlockSize(), Stream);
NewLine();
@@ -231,7 +225,7 @@ void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
Run FoundRun;
uint32_t RunOffset;
- std::tie(FoundRun, RunOffset) = findRun(Reader.getOffset(), Runs);
+ std::tie(FoundRun, RunOffset) = findRun(Substream.Offset, Runs);
assert(FoundRun.ByteLen >= RunOffset);
uint32_t Len = FoundRun.ByteLen - RunOffset;
Len = std::min(Len, Reader.bytesRemaining());
@@ -245,6 +239,7 @@ void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
OS << formatv(" {0}",
fmt_align("<discontinuity>", AlignStyle::Center, 114, '-'));
}
+ Substream.Offset += Len;
}
NewLine();
OS << ")";
diff --git a/tools/llvm-pdbutil/LinePrinter.h b/tools/llvm-pdbutil/LinePrinter.h
index 7ce410d10c0..68ce321a27e 100644
--- a/tools/llvm-pdbutil/LinePrinter.h
+++ b/tools/llvm-pdbutil/LinePrinter.h
@@ -60,9 +60,6 @@ public:
void formatMsfStreamData(StringRef Label, PDBFile &File,
const msf::MSFStreamLayout &Stream,
BinarySubstreamRef Substream);
- void formatMsfStreamData(StringRef Label, PDBFile &File,
- const msf::MSFStreamLayout &Stream,
- BinaryStreamReader &Reader);
bool hasColor() const { return UseColor; }
raw_ostream &getStream() { return OS; }
diff --git a/tools/llvm-pdbutil/llvm-pdbutil.cpp b/tools/llvm-pdbutil/llvm-pdbutil.cpp
index bdd8dfa164f..6204594d8f6 100644
--- a/tools/llvm-pdbutil/llvm-pdbutil.cpp
+++ b/tools/llvm-pdbutil/llvm-pdbutil.cpp
@@ -286,6 +286,9 @@ cl::list<std::string>
"is SN[:Start][@Size]"),
cl::sub(BytesSubcommand));
+cl::opt<bool> NameMap("name-map", cl::desc("Dump bytes of PDB Name Map"),
+ cl::sub(BytesSubcommand));
+
cl::list<std::string> InputFilenames(cl::Positional,
cl::desc("<input PDB files>"),
cl::OneOrMore, cl::sub(BytesSubcommand));
diff --git a/tools/llvm-pdbutil/llvm-pdbutil.h b/tools/llvm-pdbutil/llvm-pdbutil.h
index 78cea8fba9c..dc1bbe9ef46 100644
--- a/tools/llvm-pdbutil/llvm-pdbutil.h
+++ b/tools/llvm-pdbutil/llvm-pdbutil.h
@@ -101,6 +101,7 @@ struct NumberRange {
extern llvm::Optional<NumberRange> DumpBlockRange;
extern llvm::Optional<NumberRange> DumpByteRange;
extern llvm::cl::list<std::string> DumpStreamData;
+extern llvm::cl::opt<bool> NameMap;
} // namespace bytes
namespace dump {