From: Zachary Turner Date: Fri, 9 Jun 2017 00:53:59 +0000 (+0000) Subject: [pdb] Don't crash on unknown debug subsections. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=680d997aa787c495d175da198467b0c0dee5b463;p=llvm [pdb] Don't crash on unknown debug subsections. More and more unknown debug subsection kinds are being discovered so we should make it possible to dump these and display the bytes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305041 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h b/include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h index 22615828fa7..419ce34922e 100644 --- a/include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h +++ b/include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h @@ -120,7 +120,7 @@ Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V, DebugSubsectionState &State) { State.initialize(std::forward(FragmentRange)); - for (const auto &L : FragmentRange) { + for (const DebugSubsectionRecord &L : FragmentRange) { if (auto EC = visitDebugSubsection(L, V, State)) return EC; } diff --git a/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp b/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp index eed8edac283..e9124e68fe8 100644 --- a/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp +++ b/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp @@ -34,19 +34,6 @@ Error DebugSubsectionRecord::initialize(BinaryStreamRef Stream, DebugSubsectionKind Kind = static_cast(uint32_t(Header->Kind)); - switch (Kind) { - case DebugSubsectionKind::FileChecksums: - case DebugSubsectionKind::Lines: - case DebugSubsectionKind::InlineeLines: - case DebugSubsectionKind::CrossScopeExports: - case DebugSubsectionKind::CrossScopeImports: - case DebugSubsectionKind::Symbols: - case DebugSubsectionKind::StringTable: - case DebugSubsectionKind::FrameData: - break; - default: - llvm_unreachable("Unexpected debug fragment kind!"); - } if (auto EC = Reader.readStreamRef(Info.Data, Header->Length)) return EC; Info.Container = Container; diff --git a/tools/llvm-pdbdump/LLVMOutputStyle.cpp b/tools/llvm-pdbdump/LLVMOutputStyle.cpp index 8d688d094ee..53036994970 100644 --- a/tools/llvm-pdbdump/LLVMOutputStyle.cpp +++ b/tools/llvm-pdbdump/LLVMOutputStyle.cpp @@ -91,6 +91,18 @@ public: LazyRandomTypeCollection &IPI) : P(P), TPI(TPI), IPI(IPI) {} + Error visitUnknown(DebugUnknownSubsectionRef &Unknown) override { + if (!opts::checkModuleSubsection(opts::ModuleSubsection::Unknown)) + return Error::success(); + DictScope DD(P, "Unknown"); + P.printHex("Kind", static_cast(Unknown.kind())); + ArrayRef Data; + BinaryStreamReader Reader(Unknown.getData()); + consumeError(Reader.readBytes(Data, Reader.bytesRemaining())); + P.printBinaryBlock("Data", Data); + return Error::success(); + } + Error visitLines(DebugLinesSubsectionRef &Lines, const DebugSubsectionState &State) override { if (!opts::checkModuleSubsection(opts::ModuleSubsection::Lines)) diff --git a/tools/llvm-pdbdump/llvm-pdbdump.cpp b/tools/llvm-pdbdump/llvm-pdbdump.cpp index 68b7abff539..c6e2b613f4d 100644 --- a/tools/llvm-pdbdump/llvm-pdbdump.cpp +++ b/tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -442,6 +442,8 @@ cl::list DumpModuleSubsections( clEnumValN(ModuleSubsection::Symbols, "symbols", "Symbols (DEBUG_S_SYMBOLS subsection) (not typically " "present in PDB file)"), + clEnumValN(ModuleSubsection::Unknown, "unknown", + "Any subsection not covered by another option"), clEnumValN(ModuleSubsection::All, "all", "All known subsections")), cl::cat(FileOptions), cl::sub(RawSubcommand), cl::sub(PdbToYamlSubcommand)); cl::opt DumpModuleSyms("module-syms", cl::desc("dump module symbols"),