llvm.org GIT mirror llvm / a77c3fd
[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 Zachary Turner 3 years ago
9 changed file(s) with 52 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
4646
4747 const NamedStreamMap &getNamedStreams() const;
4848
49 BinarySubstreamRef getNamedStreamsBuffer() const;
50
4951 uint32_t getNamedStreamIndex(llvm::StringRef Name) const;
5052 iterator_range> named_streams() const;
5153
7072 // universally unique.
7173 PDB_UniqueId Guid;
7274
75 BinarySubstreamRef SubNamedStreams;
76
7377 std::vector FeatureSignatures;
7478 PdbRaw_Features Features = PdbFeatureNone;
7579
5555 return EC;
5656 uint32_t NewOffset = Reader.getOffset();
5757 NamedStreamMapByteSize = NewOffset - Offset;
58
59 Reader.setOffset(Offset);
60 if (auto EC = Reader.readSubstream(SubNamedStreams, NamedStreamMapByteSize))
61 return EC;
5862
5963 bool Stop = false;
6064 while (!Stop && !Reader.empty()) {
128132 const NamedStreamMap &InfoStream::getNamedStreams() const {
129133 return NamedStreams;
130134 }
135
136 BinarySubstreamRef InfoStream::getNamedStreamsBuffer() const {
137 return SubNamedStreams;
138 }
0 ; RUN: llvm-pdbutil bytes -byte-range=20-60 %p/Inputs/empty.pdb | FileCheck --check-prefix=VALID %s
11 ; RUN: not llvm-pdbutil bytes -byte-range=100-20 %p/Inputs/empty.pdb 2>&1 | FileCheck --check-prefix=INVALID %s
22 ; RUN: not llvm-pdbutil bytes -byte-range=100000-200000 %p/Inputs/empty.pdb 2>&1 | FileCheck --check-prefix=INVALID-RANGE %s
3
4 ; RUN: llvm-pdbutil bytes -name-map %p/Inputs/empty.pdb | FileCheck --check-prefix=NAME-MAP %s
35
46
57 VALID: MSF Bytes
1214 INVALID: llvm-pdbutil: Invalid byte range specified. Max < Min
1315
1416 INVALID-RANGE: llvm-pdbutil: Invalid byte range specified. Requested byte larger than file size
17
18 NAME-MAP: Named Stream Map
19 NAME-MAP-NEXT: ============================================================
20 NAME-MAP-NEXT: Named Stream Map (
21 NAME-MAP-NEXT: 1301C: 22000000 2F4C696E 6B496E66 6F002F6E 616D6573 002F7372 632F6865 61646572 |".../LinkInfo./names./src/header|
22 NAME-MAP-NEXT: 1303C: 626C6F63 6B000300 00000600 00000100 00001A00 00000000 00001100 00000900 |block...........................|
23 NAME-MAP-NEXT: 1305C: 00000A00 00000D00 00000000 00000500 0000 |..................|
24 NAME-MAP-NEXT: )
1212 #include "llvm-pdbutil.h"
1313
1414 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
15 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
1516 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
1617 #include "llvm/DebugInfo/PDB/Native/RawError.h"
1718 #include "llvm/Support/BinaryStreamReader.h"
115116 dumpStreamBytes();
116117 P.NewLine();
117118 }
119
120 if (opts::bytes::NameMap) {
121 dumpNameMap();
122 P.NewLine();
123 }
118124 return Error::success();
125 }
126
127 void BytesOutputStyle::dumpNameMap() {
128 printHeader(P, "Named Stream Map");
129
130 AutoIndent Indent(P);
131
132 auto &InfoS = Err(File.getPDBInfoStream());
133 BinarySubstreamRef NS = InfoS.getNamedStreamsBuffer();
134 auto Layout = File.getStreamLayout(StreamPDB);
135 P.formatMsfStreamData("Named Stream Map", File, Layout, NS);
119136 }
120137
121138 void BytesOutputStyle::dumpBlockRanges(uint32_t Min, uint32_t Max) {
2727 Error dump() override;
2828
2929 private:
30 void dumpNameMap();
3031 void dumpBlockRanges(uint32_t Min, uint32_t Max);
3132 void dumpByteRanges(uint32_t Min, uint32_t Max);
3233 void dumpStreamBytes();
3334
3435 PDBFile &File;
3536 LinePrinter P;
37 ExitOnError Err;
3638 SmallVector StreamPurposes;
3739 };
3840 } // namespace pdb
202202 StreamPurpose, Size, S->getLength());
203203 AutoIndent Indent(*this);
204204 BinaryStreamRef Slice(*S);
205 Slice = Slice.keep_front(Offset + Size);
206 BinaryStreamReader Reader(Slice);
207 consumeError(Reader.skip(Offset));
205 BinarySubstreamRef Substream;
206 Substream.Offset = Offset;
207 Substream.StreamData = Slice.drop_front(Offset).keep_front(Size);
208
208209 auto Layout = File.getStreamLayout(StreamIdx);
209 formatMsfStreamData(Label, File, Layout, Reader);
210 formatMsfStreamData(Label, File, Layout, Substream);
210211 }
211212
212213 void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
214215 BinarySubstreamRef Substream) {
215216 BinaryStreamReader Reader(Substream.StreamData);
216217
217 consumeError(Reader.skip(Substream.Offset));
218 formatMsfStreamData(Label, File, Stream, Reader);
219 }
220
221 void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
222 const msf::MSFStreamLayout &Stream,
223 BinaryStreamReader &Reader) {
224218 auto Runs = computeBlockRuns(File.getBlockSize(), Stream);
225219
226220 NewLine();
230224
231225 Run FoundRun;
232226 uint32_t RunOffset;
233 std::tie(FoundRun, RunOffset) = findRun(Reader.getOffset(), Runs);
227 std::tie(FoundRun, RunOffset) = findRun(Substream.Offset, Runs);
234228 assert(FoundRun.ByteLen >= RunOffset);
235229 uint32_t Len = FoundRun.ByteLen - RunOffset;
236230 Len = std::min(Len, Reader.bytesRemaining());
244238 OS << formatv(" {0}",
245239 fmt_align("", AlignStyle::Center, 114, '-'));
246240 }
241 Substream.Offset += Len;
247242 }
248243 NewLine();
249244 OS << ")";
5959 void formatMsfStreamData(StringRef Label, PDBFile &File,
6060 const msf::MSFStreamLayout &Stream,
6161 BinarySubstreamRef Substream);
62 void formatMsfStreamData(StringRef Label, PDBFile &File,
63 const msf::MSFStreamLayout &Stream,
64 BinaryStreamReader &Reader);
6562
6663 bool hasColor() const { return UseColor; }
6764 raw_ostream &getStream() { return OS; }
285285 "is SN[:Start][@Size]"),
286286 cl::sub(BytesSubcommand));
287287
288 cl::opt NameMap("name-map", cl::desc("Dump bytes of PDB Name Map"),
289 cl::sub(BytesSubcommand));
290
288291 cl::list InputFilenames(cl::Positional,
289292 cl::desc(""),
290293 cl::OneOrMore, cl::sub(BytesSubcommand));
100100 extern llvm::Optional DumpBlockRange;
101101 extern llvm::Optional DumpByteRange;
102102 extern llvm::cl::list DumpStreamData;
103 extern llvm::cl::opt NameMap;
103104 } // namespace bytes
104105
105106 namespace dump {