llvm.org GIT mirror llvm / 7226719
[llvm-pdbutil] Add a mode to `bytes` for dumping split debug chunks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306309 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 3 years ago
5 changed file(s) with 113 addition(s) and 44 deletion(s). Raw diff Collapse all Expand all
173173 BinaryStreamRef SubSub = StreamData.slice(Off, Size);
174174 return {Off + Offset, SubSub};
175175 }
176 BinarySubstreamRef drop_front(uint32_t N) const {
177 return slice(N, size() - N);
178 }
179 BinarySubstreamRef keep_front(uint32_t N) const { return slice(0, N); }
180
181 std::pair
182 split(uint32_t Offset) const {
183 return std::make_pair(keep_front(Offset), drop_front(Offset));
184 }
185
176186 uint32_t size() const { return StreamData.getLength(); }
177187 bool empty() const { return size() == 0; }
178188 };
0 ; RUN: llvm-pdbutil bytes -chunks %p/Inputs/empty.pdb | FileCheck --check-prefix=CHUNKS %s
11 ; RUN: llvm-pdbutil bytes -chunks -mod=0 %p/Inputs/empty.pdb | FileCheck --check-prefix=FILTERED-CHUNKS %s
2 ; RUN: llvm-pdbutil bytes -chunks -split-chunks -mod=0 %p/Inputs/empty.pdb | FileCheck --check-prefix=SPLIT-CHUNKS %s
23
34 ; RUN: llvm-pdbutil bytes -syms %p/Inputs/empty.pdb | FileCheck --check-prefix=SYMS %s
45 ; RUN: llvm-pdbutil bytes -syms -mod=0 %p/Inputs/empty.pdb | FileCheck --check-prefix=FILTERED-SYMS %s
2425 FILTERED-CHUNKS-NEXT: 6110: 56000000 1001A0A5 BD0D3ECD 93FC29D1 9DE826FB F4BC0000 |V.........>...)...&.....|
2526 FILTERED-CHUNKS-NEXT: )
2627 FILTERED-CHUNKS-NOT: Mod 0001
28
29 SPLIT-CHUNKS: Debug Chunks
30 SPLIT-CHUNKS-NEXT: ============================================================
31 SPLIT-CHUNKS-NEXT: Mod 0000 | `d:\src\llvm\test\DebugInfo\PDB\Inputs\empty.obj`:
32 SPLIT-CHUNKS-NEXT: lines (
33 SPLIT-CHUNKS-NEXT: 60D0: F2000000 30000000 10000000 01000000 0A000000 00000000 03000000 24000000 |....0.......................$...|
34 SPLIT-CHUNKS-NEXT: 60F0: 00000000 05000080 03000000 06000080 08000000 07000080 |........................|
35 SPLIT-CHUNKS-NEXT: )
36 SPLIT-CHUNKS-NEXT: checksums (
37 SPLIT-CHUNKS-NEXT: 6108: F4000000 18000000 56000000 1001A0A5 BD0D3ECD 93FC29D1 9DE826FB F4BC0000 |........V.........>...)...&.....|
38 SPLIT-CHUNKS-NEXT: )
2739
2840 SYMS: Module Symbols
2941 SYMS-NEXT: ============================================================
318318 const DbiModuleList &Modules, uint32_t I,
319319 uint32_t Digits, uint32_t IndentLevel,
320320 CallbackT Callback) {
321 if (I >= Modules.getModuleCount()) {
322 P.formatLine("Mod {0:4} | Invalid module index ",
323 fmt_align(I, AlignStyle::Right, std::max(Digits, 4U)));
324 return;
325 }
326
321327 auto Modi = Modules.getModuleDescriptor(I);
322328 P.formatLine("Mod {0:4} | `{1}`: ",
323329 fmt_align(I, AlignStyle::Right, std::max(Digits, 4U)),
324330 Modi.getModuleName());
325331
326332 uint16_t ModiStream = Modi.getModuleStreamIndex();
327
328333 AutoIndent Indent2(P, IndentLevel);
334 if (ModiStream == kInvalidStreamIndex)
335 return;
336
329337 auto ModStreamData = MappedBlockStream::createIndexedStream(
330338 File.getMsfLayout(), File.getMsfBuffer(), ModiStream,
331339 File.getAllocator());
392400 });
393401 }
394402
403 static std::string formatChunkKind(DebugSubsectionKind Kind) {
404 switch (Kind) {
405 RETURN_CASE(DebugSubsectionKind, None, "none");
406 RETURN_CASE(DebugSubsectionKind, Symbols, "symbols");
407 RETURN_CASE(DebugSubsectionKind, Lines, "lines");
408 RETURN_CASE(DebugSubsectionKind, StringTable, "strings");
409 RETURN_CASE(DebugSubsectionKind, FileChecksums, "checksums");
410 RETURN_CASE(DebugSubsectionKind, FrameData, "frames");
411 RETURN_CASE(DebugSubsectionKind, InlineeLines, "inlinee lines");
412 RETURN_CASE(DebugSubsectionKind, CrossScopeImports, "xmi");
413 RETURN_CASE(DebugSubsectionKind, CrossScopeExports, "xme");
414 RETURN_CASE(DebugSubsectionKind, ILLines, "il lines");
415 RETURN_CASE(DebugSubsectionKind, FuncMDTokenMap, "func md token map");
416 RETURN_CASE(DebugSubsectionKind, TypeMDTokenMap, "type md token map");
417 RETURN_CASE(DebugSubsectionKind, MergedAssemblyInput,
418 "merged assembly input");
419 RETURN_CASE(DebugSubsectionKind, CoffSymbolRVA, "coff symbol rva");
420 }
421 return formatUnknownEnum(Kind);
422 }
423
395424 void BytesOutputStyle::dumpModuleC13() {
396425 printHeader(P, "Debug Chunks");
397426
398427 AutoIndent Indent(P);
399428
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 });
429 iterateModules(
430 File, P, 2,
431 [this](uint32_t Modi, const ModuleDebugStreamRef &Stream,
432 const MSFStreamLayout &Layout) {
433 auto Chunks = Stream.getC13LinesSubstream();
434 if (opts::bytes::SplitChunks) {
435 for (const auto &SS : Stream.subsections()) {
436 BinarySubstreamRef ThisChunk;
437 std::tie(ThisChunk, Chunks) = Chunks.split(SS.getRecordLength());
438 P.formatMsfStreamData(formatChunkKind(SS.kind()), File, Layout,
439 ThisChunk);
440 }
441 } else {
442 P.formatMsfStreamData("Debug Chunks", File, Layout, Chunks);
443 }
444 });
406445 }
407446
408447 void BytesOutputStyle::dumpByteRanges(uint32_t Min, uint32_t Max) {
113113 cl::OptionCategory FilterCategory("Filtering and Sorting Options");
114114 cl::OptionCategory OtherOptions("Other Options");
115115
116 cl::ValuesClass ChunkValues = cl::values(
117 clEnumValN(ModuleSubsection::CrossScopeExports, "cme",
118 "Cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"),
119 clEnumValN(ModuleSubsection::CrossScopeImports, "cmi",
120 "Cross module imports (DEBUG_S_CROSSSCOPEIMPORTS subsection)"),
121 clEnumValN(ModuleSubsection::FileChecksums, "fc",
122 "File checksums (DEBUG_S_CHECKSUMS subsection)"),
123 clEnumValN(ModuleSubsection::InlineeLines, "ilines",
124 "Inlinee lines (DEBUG_S_INLINEELINES subsection)"),
125 clEnumValN(ModuleSubsection::Lines, "lines",
126 "Lines (DEBUG_S_LINES subsection)"),
127 clEnumValN(ModuleSubsection::StringTable, "strings",
128 "String Table (DEBUG_S_STRINGTABLE subsection) (not "
129 "typically present in PDB file)"),
130 clEnumValN(ModuleSubsection::FrameData, "frames",
131 "Frame Data (DEBUG_S_FRAMEDATA subsection)"),
132 clEnumValN(ModuleSubsection::Symbols, "symbols",
133 "Symbols (DEBUG_S_SYMBOLS subsection) (not typically "
134 "present in PDB file)"),
135 clEnumValN(ModuleSubsection::CoffSymbolRVAs, "rvas",
136 "COFF Symbol RVAs (DEBUG_S_COFF_SYMBOL_RVA subsection)"),
137 clEnumValN(ModuleSubsection::Unknown, "unknown",
138 "Any subsection not covered by another option"),
139 clEnumValN(ModuleSubsection::All, "all", "All known subsections"));
140
116141 namespace pretty {
117142 cl::list InputFilenames(cl::Positional,
118143 cl::desc(""),
327352 cl::opt ModuleC11("c11-chunks", cl::Hidden,
328353 cl::desc("Dump C11 CodeView debug chunks"),
329354 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
330 cl::opt ModuleC13("chunks", cl::desc("Dump C13 CodeView debug chunks"),
355 cl::opt ModuleC13("chunks",
356 cl::desc("Dump C13 CodeView debug chunk subsection"),
331357 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
332
358 cl::opt SplitChunks(
359 "split-chunks",
360 cl::desc(
361 "When dumping debug chunks, show a different section for each chunk"),
362 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
333363 cl::list InputFilenames(cl::Positional,
334364 cl::desc(""),
335365 cl::OneOrMore, cl::sub(BytesSubcommand));
500530 cl::sub(PdbToYamlSubcommand));
501531 cl::list DumpModuleSubsections(
502532 "subsections", cl::ZeroOrMore, cl::CommaSeparated,
503 cl::desc("dump subsections from each module's debug stream"),
504 cl::values(
505 clEnumValN(
506 ModuleSubsection::CrossScopeExports, "cme",
507 "Cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"),
508 clEnumValN(
509 ModuleSubsection::CrossScopeImports, "cmi",
510 "Cross module imports (DEBUG_S_CROSSSCOPEIMPORTS subsection)"),
511 clEnumValN(ModuleSubsection::FileChecksums, "fc",
512 "File checksums (DEBUG_S_CHECKSUMS subsection)"),
513 clEnumValN(ModuleSubsection::InlineeLines, "ilines",
514 "Inlinee lines (DEBUG_S_INLINEELINES subsection)"),
515 clEnumValN(ModuleSubsection::Lines, "lines",
516 "Lines (DEBUG_S_LINES subsection)"),
517 clEnumValN(ModuleSubsection::StringTable, "strings",
518 "String Table (DEBUG_S_STRINGTABLE subsection) (not "
519 "typically present in PDB file)"),
520 clEnumValN(ModuleSubsection::FrameData, "frames",
521 "Frame Data (DEBUG_S_FRAMEDATA subsection)"),
522 clEnumValN(ModuleSubsection::Symbols, "symbols",
523 "Symbols (DEBUG_S_SYMBOLS subsection) (not typically "
524 "present in PDB file)"),
525 clEnumValN(ModuleSubsection::CoffSymbolRVAs, "rvas",
526 "COFF Symbol RVAs (DEBUG_S_COFF_SYMBOL_RVA subsection)"),
527 clEnumValN(ModuleSubsection::Unknown, "unknown",
528 "Any subsection not covered by another option"),
529 clEnumValN(ModuleSubsection::All, "all", "All known subsections")),
533 cl::desc("dump subsections from each module's debug stream"), ChunkValues,
530534 cl::cat(FileOptions), cl::sub(PdbToYamlSubcommand));
531535 cl::opt DumpModuleSyms("module-syms", cl::desc("dump module symbols"),
532536 cl::cat(FileOptions),
979983 return true;
980984 }
981985
986 static void simplifyChunkList(llvm::cl::list &Chunks) {
987 // If this list contains "All" plus some other stuff, remove the other stuff
988 // and just keep "All" in the list.
989 if (!llvm::is_contained(Chunks, opts::ModuleSubsection::All))
990 return;
991 Chunks.reset();
992 Chunks.push_back(opts::ModuleSubsection::All);
993 }
994
982995 int main(int argc_, const char *argv_[]) {
983996 // Print a stack trace if we signal out.
984997 sys::PrintStackTraceOnErrorSignal(argv_[0]);
10491062 opts::pdb2yaml::DumpModuleSyms = true;
10501063 opts::pdb2yaml::DumpModuleSubsections.push_back(
10511064 opts::ModuleSubsection::All);
1052 if (llvm::is_contained(opts::pdb2yaml::DumpModuleSubsections,
1053 opts::ModuleSubsection::All)) {
1054 opts::pdb2yaml::DumpModuleSubsections.reset();
1055 opts::pdb2yaml::DumpModuleSubsections.push_back(
1056 opts::ModuleSubsection::All);
1057 }
1058 }
1065 }
1066 simplifyChunkList(opts::pdb2yaml::DumpModuleSubsections);
10591067
10601068 if (opts::pdb2yaml::DumpModuleSyms || opts::pdb2yaml::DumpModuleFiles)
10611069 opts::pdb2yaml::DumpModules = true;
116116 extern llvm::cl::opt ModuleSyms;
117117 extern llvm::cl::opt ModuleC11;
118118 extern llvm::cl::opt ModuleC13;
119
119 extern llvm::cl::opt SplitChunks;
120120 } // namespace bytes
121121
122122 namespace dump {