llvm.org GIT mirror llvm / 554302a
[llvm-pdbutil] Dump raw bytes of module symbols and debug chunks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306179 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 2 years ago
7 changed file(s) with 245 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
4040 iterator_range
4141 symbols(bool *HadError) const;
4242
43 const codeview::CVSymbolArray &getSymbolArray() const {
44 return SymbolsSubstream;
45 }
43 const codeview::CVSymbolArray &getSymbolArray() const { return SymbolArray; }
44
45 BinarySubstreamRef getSymbolsSubstream() const;
46 BinarySubstreamRef getC11LinesSubstream() const;
47 BinarySubstreamRef getC13LinesSubstream() const;
48 BinarySubstreamRef getGlobalRefsSubstream() const;
4649
4750 ModuleDebugStreamRef &operator=(ModuleDebugStreamRef &&Other) = default;
4851
6265
6366 std::shared_ptr Stream;
6467
65 codeview::CVSymbolArray SymbolsSubstream;
66 BinaryStreamRef C11LinesSubstream;
67 BinaryStreamRef C13LinesSubstream;
68 BinaryStreamRef GlobalRefsSubstream;
68 codeview::CVSymbolArray SymbolArray;
69
70 BinarySubstreamRef SymbolsSubstream;
71 BinarySubstreamRef C11LinesSubstream;
72 BinarySubstreamRef C13LinesSubstream;
73 BinarySubstreamRef GlobalRefsSubstream;
6974
7075 codeview::DebugSubsectionArray Subsections;
7176 };
4646
4747 if (auto EC = Reader.readInteger(Signature))
4848 return EC;
49 if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4))
49 if (auto EC = Reader.readSubstream(SymbolsSubstream, SymbolSize - 4))
50 return EC;
51 if (auto EC = Reader.readSubstream(C11LinesSubstream, C11Size))
52 return EC;
53 if (auto EC = Reader.readSubstream(C13LinesSubstream, C13Size))
5054 return EC;
5155
52 if (auto EC = Reader.readStreamRef(C11LinesSubstream, C11Size))
53 return EC;
54 if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size))
56 BinaryStreamReader SymbolReader(SymbolsSubstream.StreamData);
57 if (auto EC =
58 SymbolReader.readArray(SymbolArray, SymbolReader.bytesRemaining()))
5559 return EC;
5660
57 BinaryStreamReader SubsectionsReader(C13LinesSubstream);
61 BinaryStreamReader SubsectionsReader(C13LinesSubstream.StreamData);
5862 if (auto EC = SubsectionsReader.readArray(Subsections,
5963 SubsectionsReader.bytesRemaining()))
6064 return EC;
6266 uint32_t GlobalRefsSize;
6367 if (auto EC = Reader.readInteger(GlobalRefsSize))
6468 return EC;
65 if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize))
69 if (auto EC = Reader.readSubstream(GlobalRefsSubstream, GlobalRefsSize))
6670 return EC;
6771 if (Reader.bytesRemaining() > 0)
6872 return make_error(raw_error_code::corrupt_file,
7175 return Error::success();
7276 }
7377
78 BinarySubstreamRef ModuleDebugStreamRef::getSymbolsSubstream() const {
79 return SymbolsSubstream;
80 }
81
82 BinarySubstreamRef ModuleDebugStreamRef::getC11LinesSubstream() const {
83 return C11LinesSubstream;
84 }
85
86 BinarySubstreamRef ModuleDebugStreamRef::getC13LinesSubstream() const {
87 return C13LinesSubstream;
88 }
89
90 BinarySubstreamRef ModuleDebugStreamRef::getGlobalRefsSubstream() const {
91 return GlobalRefsSubstream;
92 }
93
7494 iterator_range
7595 ModuleDebugStreamRef::symbols(bool *HadError) const {
76 return make_range(SymbolsSubstream.begin(HadError), SymbolsSubstream.end());
96 return make_range(SymbolArray.begin(HadError), SymbolArray.end());
7797 }
7898
7999 llvm::iterator_range
82102 }
83103
84104 bool ModuleDebugStreamRef::hasDebugSubsections() const {
85 return C13LinesSubstream.getLength() > 0;
105 return !C13LinesSubstream.empty();
86106 }
87107
88108 Error ModuleDebugStreamRef::commit() { return Error::success(); }
0 ; RUN: llvm-pdbutil bytes -chunks %p/Inputs/empty.pdb | FileCheck --check-prefix=CHUNKS %s
1 ; RUN: llvm-pdbutil bytes -chunks -mod=0 %p/Inputs/empty.pdb | FileCheck --check-prefix=FILTERED-CHUNKS %s
2
3 ; RUN: llvm-pdbutil bytes -syms %p/Inputs/empty.pdb | FileCheck --check-prefix=SYMS %s
4 ; RUN: llvm-pdbutil bytes -syms -mod=0 %p/Inputs/empty.pdb | FileCheck --check-prefix=FILTERED-SYMS %s
5
6 CHUNKS: Debug Chunks
7 CHUNKS-NEXT: ============================================================
8 CHUNKS-NEXT: Mod 0000 | `d:\src\llvm\test\DebugInfo\PDB\Inputs\empty.obj`:
9 CHUNKS-NEXT: Debug Chunks (
10 CHUNKS-NEXT: 60D0: F2000000 30000000 10000000 01000000 0A000000 00000000 03000000 24000000 |....0.......................$...|
11 CHUNKS-NEXT: 60F0: 00000000 05000080 03000000 06000080 08000000 07000080 F4000000 18000000 |................................|
12 CHUNKS-NEXT: 6110: 56000000 1001A0A5 BD0D3ECD 93FC29D1 9DE826FB F4BC0000 |V.........>...)...&.....|
13 CHUNKS-NEXT: )
14 CHUNKS-NEXT: Mod 0001 | `* Linker *`:
15 CHUNKS-NEXT: Debug Chunks (
16 CHUNKS-NEXT: )
17
18 FILTERED-CHUNKS: Debug Chunks
19 FILTERED-CHUNKS-NEXT: ============================================================
20 FILTERED-CHUNKS-NEXT: Mod 0000 | `d:\src\llvm\test\DebugInfo\PDB\Inputs\empty.obj`:
21 FILTERED-CHUNKS-NEXT: Debug Chunks (
22 FILTERED-CHUNKS-NEXT: 60D0: F2000000 30000000 10000000 01000000 0A000000 00000000 03000000 24000000 |....0.......................$...|
23 FILTERED-CHUNKS-NEXT: 60F0: 00000000 05000080 03000000 06000080 08000000 07000080 F4000000 18000000 |................................|
24 FILTERED-CHUNKS-NEXT: 6110: 56000000 1001A0A5 BD0D3ECD 93FC29D1 9DE826FB F4BC0000 |V.........>...)...&.....|
25 FILTERED-CHUNKS-NEXT: )
26 FILTERED-CHUNKS-NOT: Mod 0001
27
28 SYMS: Module Symbols
29 SYMS-NEXT: ============================================================
30 SYMS-NEXT: Mod 0000 | `d:\src\llvm\test\DebugInfo\PDB\Inputs\empty.obj`:
31 SYMS-NEXT: Symbols (
32 SYMS-NEXT: 6004: 36000111 00000000 643A5C73 72635C6C 6C766D5C 74657374 5C446562 7567496E |6.......d:\src\llvm\test\DebugIn|
33 SYMS-NEXT: 6024: 666F5C50 44425C49 6E707574 735C656D 7074792E 6F626A00 3A003C11 01200000 |fo\PDB\Inputs\empty.obj.:.<.. ..|
34 SYMS-NEXT: 6044: 07001200 00007D79 00001200 00007D79 00004D69 63726F73 6F667420 28522920 |......}y......}y..Microsoft (R) |
35 SYMS-NEXT: 6064: 4F707469 6D697A69 6E672043 6F6D7069 6C657200 2A001011 00000000 C4000000 |Optimizing Compiler.*...........|
36 SYMS-NEXT: 6084: 00000000 0A000000 03000000 08000000 01100000 10000000 0100016D 61696E00 |...........................main.|
37 SYMS-NEXT: 60A4: 1E001210 00000000 00000000 00000000 00000000 00000000 00000082 12000000 |................................|
38 SYMS-NEXT: 60C4: 02000600 06004C11 0E100000 |......L.....|
39 SYMS-NEXT: )
40 SYMS-NEXT: Mod 0001 | `* Linker *`:
41 SYMS-NEXT: Symbols (
42 SYMS-NEXT: 7004: 12000111 00000000 2A204C69 6E6B6572 202A0000 2E003C11 07000000 03000000 |........* Linker *....<.........|
43 SYMS-NEXT: 7024: 00000000 00000C00 00007D79 00004D69 63726F73 6F667420 28522920 4C494E4B |..........}y..Microsoft (R) LINK|
44 SYMS-NEXT: 7044: 00000000 AA003D11 00637764 00643A5C 7372635C 6C6C766D 5C746573 745C4465 |......=..cwd.d:\src\llvm\test\De|
45 SYMS-NEXT: 7064: 62756749 6E666F5C 5044425C 496E7075 74730065 78650043 3A5C5072 6F677261 |bugInfo\PDB\Inputs.exe.C:\Progra|
46 SYMS-NEXT: 7084: 6D204669 6C657320 28783836 295C4D69 63726F73 6F667420 56697375 616C2053 |m Files (x86)\Microsoft Visual S|
47 SYMS-NEXT: 70A4: 74756469 6F203132 2E305C56 435C4249 4E5C6C69 6E6B2E65 78650070 64620064 |tudio 12.0\VC\BIN\link.exe.pdb.d|
48 SYMS-NEXT: 70C4: 3A5C7372 635C6C6C 766D5C74 6573745C 44656275 67496E66 6F5C5044 425C496E |:\src\llvm\test\DebugInfo\PDB\In|
49 SYMS-NEXT: 70E4: 70757473 5C656D70 74792E70 64620000 12002C11 00000500 05000000 10000000 |puts\empty.pdb....,.............|
50 SYMS-NEXT: 7104: 01000100 1A003611 01000C00 00100000 1A100000 20000060 2E746578 74000000 |......6............. ..`.text...|
51 SYMS-NEXT: 7124: 1A003711 1A100000 20000060 00000000 01002E74 65787424 6D6E0000 1A003611 |..7..... ..`.......text$mn....6.|
52 SYMS-NEXT: 7144: 02000C00 00300000 B2020000 40000040 2E726461 74610000 1A003711 43010000 |.....0......@..@.rdata....7.C...|
53 SYMS-NEXT: 7164: 40000040 00000000 02002E72 64617461 00000000 1A003711 00000000 40000040 |@..@.......rdata......7.....@..@|
54 SYMS-NEXT: 7184: 43010000 02002E65 64617461 00000000 1E003711 6E010000 40000040 44010000 |C......edata......7.n...@..@D...|
55 SYMS-NEXT: 71A4: 02002E72 64617461 24646562 75670000 1A003611 03000C00 00400000 04000000 |...rdata$debug....6......@......|
56 SYMS-NEXT: 71C4: 400000C0 2E646174 61000000 16003711 04000000 800000C0 00000000 03002E62 |@....data.....7................b|
57 SYMS-NEXT: 71E4: 73730000 1A003611 04000C00 00500000 08000000 40000042 2E72656C 6F630000 |ss....6......P......@..B.reloc..|
58 SYMS-NEXT: )
59
60 FILTERED-SYMS: Module Symbols
61 FILTERED-SYMS-NEXT: ============================================================
62 FILTERED-SYMS-NEXT: Mod 0000 | `d:\src\llvm\test\DebugInfo\PDB\Inputs\empty.obj`:
63 FILTERED-SYMS-NEXT: Symbols (
64 FILTERED-SYMS-NEXT: 6004: 36000111 00000000 643A5C73 72635C6C 6C766D5C 74657374 5C446562 7567496E |6.......d:\src\llvm\test\DebugIn|
65 FILTERED-SYMS-NEXT: 6024: 666F5C50 44425C49 6E707574 735C656D 7074792E 6F626A00 3A003C11 01200000 |fo\PDB\Inputs\empty.obj.:.<.. ..|
66 FILTERED-SYMS-NEXT: 6044: 07001200 00007D79 00001200 00007D79 00004D69 63726F73 6F667420 28522920 |......}y......}y..Microsoft (R) |
67 FILTERED-SYMS-NEXT: 6064: 4F707469 6D697A69 6E672043 6F6D7069 6C657200 2A001011 00000000 C4000000 |Optimizing Compiler.*...........|
68 FILTERED-SYMS-NEXT: 6084: 00000000 0A000000 03000000 08000000 01100000 10000000 0100016D 61696E00 |...........................main.|
69 FILTERED-SYMS-NEXT: 60A4: 1E001210 00000000 00000000 00000000 00000000 00000000 00000082 12000000 |................................|
70 FILTERED-SYMS-NEXT: 60C4: 02000600 06004C11 0E100000 |......L.....|
71 FILTERED-SYMS-NEXT: )
72 FILTERED-SYMS-NOT: Mod 0001
88
99 #include "BytesOutputStyle.h"
1010
11 #include "FormatUtil.h"
1112 #include "StreamUtil.h"
1213 #include "llvm-pdbutil.h"
1314
1617 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
1718 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
1819 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
20 #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
1921 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
2022 #include "llvm/DebugInfo/PDB/Native/RawError.h"
2123 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
167169 P.NewLine();
168170 }
169171
172 if (opts::bytes::ModuleSyms) {
173 dumpModuleSyms();
174 P.NewLine();
175 }
176
177 if (opts::bytes::ModuleC11) {
178 dumpModuleC11();
179 P.NewLine();
180 }
181
182 if (opts::bytes::ModuleC13) {
183 dumpModuleC13();
184 P.NewLine();
185 }
186
170187 return Error::success();
171188 }
172189
296313 }
297314 }
298315
316 template
317 static void iterateOneModule(PDBFile &File, LinePrinter &P,
318 const DbiModuleList &Modules, uint32_t I,
319 uint32_t Digits, uint32_t IndentLevel,
320 CallbackT Callback) {
321 auto Modi = Modules.getModuleDescriptor(I);
322 P.formatLine("Mod {0:4} | `{1}`: ",
323 fmt_align(I, AlignStyle::Right, std::max(Digits, 4U)),
324 Modi.getModuleName());
325
326 uint16_t ModiStream = Modi.getModuleStreamIndex();
327
328 AutoIndent Indent2(P, IndentLevel);
329 auto ModStreamData = MappedBlockStream::createIndexedStream(
330 File.getMsfLayout(), File.getMsfBuffer(), ModiStream,
331 File.getAllocator());
332 ModuleDebugStreamRef ModStream(Modi, std::move(ModStreamData));
333 if (auto EC = ModStream.reload()) {
334 P.formatLine("Could not parse debug information.");
335 return;
336 }
337 auto Layout = File.getStreamLayout(ModiStream);
338 Callback(I, ModStream, Layout);
339 }
340
341 template
342 static void iterateModules(PDBFile &File, LinePrinter &P, uint32_t IndentLevel,
343 CallbackT Callback) {
344 AutoIndent Indent(P);
345 if (!File.hasPDBDbiStream()) {
346 P.formatLine("DBI Stream not present");
347 return;
348 }
349
350 ExitOnError Err("Unexpected error processing modules");
351
352 auto &Stream = Err(File.getPDBDbiStream());
353
354 const DbiModuleList &Modules = Stream.modules();
355
356 if (opts::bytes::ModuleIndex.getNumOccurrences() > 0) {
357 iterateOneModule(File, P, Modules, opts::bytes::ModuleIndex, 1, IndentLevel,
358 Callback);
359 } else {
360 uint32_t Count = Modules.getModuleCount();
361 uint32_t Digits = NumDigits(Count);
362 for (uint32_t I = 0; I < Count; ++I) {
363 iterateOneModule(File, P, Modules, I, Digits, IndentLevel, Callback);
364 }
365 }
366 }
367
368 void BytesOutputStyle::dumpModuleSyms() {
369 printHeader(P, "Module Symbols");
370
371 AutoIndent Indent(P);
372
373 iterateModules(File, P, 2,
374 [this](uint32_t Modi, const ModuleDebugStreamRef &Stream,
375 const MSFStreamLayout &Layout) {
376 auto Symbols = Stream.getSymbolsSubstream();
377 P.formatMsfStreamData("Symbols", File, Layout, Symbols);
378 });
379 }
380
381 void BytesOutputStyle::dumpModuleC11() {
382 printHeader(P, "C11 Debug Chunks");
383
384 AutoIndent Indent(P);
385
386 iterateModules(File, P, 2,
387 [this](uint32_t Modi, const ModuleDebugStreamRef &Stream,
388 const MSFStreamLayout &Layout) {
389 auto Chunks = Stream.getC11LinesSubstream();
390 P.formatMsfStreamData("C11 Debug Chunks", File, Layout,
391 Chunks);
392 });
393 }
394
395 void BytesOutputStyle::dumpModuleC13() {
396 printHeader(P, "Debug Chunks");
397
398 AutoIndent Indent(P);
399
400 iterateModules(File, P, 2,
401 [this](uint32_t Modi, const ModuleDebugStreamRef &Stream,
402 const MSFStreamLayout &Layout) {
403 auto Chunks = Stream.getC13LinesSubstream();
404 P.formatMsfStreamData("Debug Chunks", File, Layout, Chunks);
405 });
406 }
407
299408 void BytesOutputStyle::dumpByteRanges(uint32_t Min, uint32_t Max) {
300409 printHeader(P, "MSF Bytes");
301410
4343 void dumpTypeServerMap();
4444 void dumpECData();
4545
46 void dumpModuleSyms();
47 void dumpModuleC11();
48 void dumpModuleC13();
49
4650 void dumpTypeIndex(uint32_t StreamIdx, ArrayRef Indices);
4751
4852 Expected
270270 cl::OptionCategory DbiBytes("Dbi Stream Options");
271271 cl::OptionCategory PdbBytes("PDB Stream Options");
272272 cl::OptionCategory Types("Type Options");
273 cl::OptionCategory ModuleCategory("Module Options");
273274
274275 llvm::Optional DumpBlockRange;
275276 llvm::Optional DumpByteRange;
315316 IdIndex("id", cl::desc("Dump the id record with the given type index"),
316317 cl::ZeroOrMore, cl::CommaSeparated, cl::sub(BytesSubcommand),
317318 cl::cat(TypeCategory));
319
320 cl::opt ModuleIndex(
321 "mod",
322 cl::desc(
323 "Limit options in the Modules category to the specified module index"),
324 cl::Optional, cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
325 cl::opt ModuleSyms("syms", cl::desc("Dump symbol record substream"),
326 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
327 cl::opt ModuleC11("c11-chunks", cl::Hidden,
328 cl::desc("Dump C11 CodeView debug chunks"),
329 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
330 cl::opt ModuleC13("chunks", cl::desc("Dump C13 CodeView debug chunks"),
331 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
318332
319333 cl::list InputFilenames(cl::Positional,
320334 cl::desc(""),
112112 extern llvm::cl::list TypeIndex;
113113 extern llvm::cl::list IdIndex;
114114
115 extern llvm::cl::opt ModuleIndex;
116 extern llvm::cl::opt ModuleSyms;
117 extern llvm::cl::opt ModuleC11;
118 extern llvm::cl::opt ModuleC13;
119
115120 } // namespace bytes
116121
117122 namespace dump {