1*db17bf38SDimitry Andric //===- DebugSubsectionVisitor.cpp -------------------------------*- C++ -*-===// 289cb50c9SDimitry Andric // 389cb50c9SDimitry Andric // The LLVM Compiler Infrastructure 489cb50c9SDimitry Andric // 589cb50c9SDimitry Andric // This file is distributed under the University of Illinois Open Source 689cb50c9SDimitry Andric // License. See LICENSE.TXT for details. 789cb50c9SDimitry Andric // 889cb50c9SDimitry Andric //===----------------------------------------------------------------------===// 989cb50c9SDimitry Andric 1089cb50c9SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h" 1189cb50c9SDimitry Andric 1289cb50c9SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" 13*db17bf38SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h" 14*db17bf38SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugCrossImpSubsection.h" 15*db17bf38SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h" 1689cb50c9SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" 1789cb50c9SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h" 18*db17bf38SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h" 1989cb50c9SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h" 20*db17bf38SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugSymbolRVASubsection.h" 21*db17bf38SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h" 2289cb50c9SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugUnknownSubsection.h" 2389cb50c9SDimitry Andric #include "llvm/Support/BinaryStreamReader.h" 2489cb50c9SDimitry Andric #include "llvm/Support/BinaryStreamRef.h" 2589cb50c9SDimitry Andric 2689cb50c9SDimitry Andric using namespace llvm; 2789cb50c9SDimitry Andric using namespace llvm::codeview; 2889cb50c9SDimitry Andric 29*db17bf38SDimitry Andric DebugSubsectionState::DebugSubsectionState() {} 30*db17bf38SDimitry Andric 31*db17bf38SDimitry Andric DebugSubsectionState::DebugSubsectionState( 32*db17bf38SDimitry Andric const DebugStringTableSubsectionRef &Strings) 33*db17bf38SDimitry Andric : Strings(&Strings) {} 34*db17bf38SDimitry Andric 35*db17bf38SDimitry Andric DebugSubsectionState::DebugSubsectionState( 36*db17bf38SDimitry Andric const DebugStringTableSubsectionRef &Strings, 37*db17bf38SDimitry Andric const DebugChecksumsSubsectionRef &Checksums) 38*db17bf38SDimitry Andric : Strings(&Strings), Checksums(&Checksums) {} 39*db17bf38SDimitry Andric 40*db17bf38SDimitry Andric void DebugSubsectionState::initializeStrings(const DebugSubsectionRecord &SR) { 41*db17bf38SDimitry Andric assert(SR.kind() == DebugSubsectionKind::StringTable); 42*db17bf38SDimitry Andric assert(!Strings && "Found a string table even though we already have one!"); 43*db17bf38SDimitry Andric 44*db17bf38SDimitry Andric OwnedStrings = llvm::make_unique<DebugStringTableSubsectionRef>(); 45*db17bf38SDimitry Andric consumeError(OwnedStrings->initialize(SR.getRecordData())); 46*db17bf38SDimitry Andric Strings = OwnedStrings.get(); 47*db17bf38SDimitry Andric } 48*db17bf38SDimitry Andric 49*db17bf38SDimitry Andric void DebugSubsectionState::initializeChecksums( 50*db17bf38SDimitry Andric const DebugSubsectionRecord &FCR) { 51*db17bf38SDimitry Andric assert(FCR.kind() == DebugSubsectionKind::FileChecksums); 52*db17bf38SDimitry Andric if (Checksums) 53*db17bf38SDimitry Andric return; 54*db17bf38SDimitry Andric 55*db17bf38SDimitry Andric OwnedChecksums = llvm::make_unique<DebugChecksumsSubsectionRef>(); 56*db17bf38SDimitry Andric consumeError(OwnedChecksums->initialize(FCR.getRecordData())); 57*db17bf38SDimitry Andric Checksums = OwnedChecksums.get(); 58*db17bf38SDimitry Andric } 59*db17bf38SDimitry Andric 6089cb50c9SDimitry Andric Error llvm::codeview::visitDebugSubsection(const DebugSubsectionRecord &R, 61*db17bf38SDimitry Andric DebugSubsectionVisitor &V, 62*db17bf38SDimitry Andric const DebugSubsectionState &State) { 6389cb50c9SDimitry Andric BinaryStreamReader Reader(R.getRecordData()); 6489cb50c9SDimitry Andric switch (R.kind()) { 6589cb50c9SDimitry Andric case DebugSubsectionKind::Lines: { 6689cb50c9SDimitry Andric DebugLinesSubsectionRef Fragment; 6789cb50c9SDimitry Andric if (auto EC = Fragment.initialize(Reader)) 6889cb50c9SDimitry Andric return EC; 6989cb50c9SDimitry Andric 70*db17bf38SDimitry Andric return V.visitLines(Fragment, State); 7189cb50c9SDimitry Andric } 7289cb50c9SDimitry Andric case DebugSubsectionKind::FileChecksums: { 7389cb50c9SDimitry Andric DebugChecksumsSubsectionRef Fragment; 7489cb50c9SDimitry Andric if (auto EC = Fragment.initialize(Reader)) 7589cb50c9SDimitry Andric return EC; 7689cb50c9SDimitry Andric 77*db17bf38SDimitry Andric return V.visitFileChecksums(Fragment, State); 7889cb50c9SDimitry Andric } 7989cb50c9SDimitry Andric case DebugSubsectionKind::InlineeLines: { 8089cb50c9SDimitry Andric DebugInlineeLinesSubsectionRef Fragment; 8189cb50c9SDimitry Andric if (auto EC = Fragment.initialize(Reader)) 8289cb50c9SDimitry Andric return EC; 83*db17bf38SDimitry Andric return V.visitInlineeLines(Fragment, State); 84*db17bf38SDimitry Andric } 85*db17bf38SDimitry Andric case DebugSubsectionKind::CrossScopeExports: { 86*db17bf38SDimitry Andric DebugCrossModuleExportsSubsectionRef Section; 87*db17bf38SDimitry Andric if (auto EC = Section.initialize(Reader)) 88*db17bf38SDimitry Andric return EC; 89*db17bf38SDimitry Andric return V.visitCrossModuleExports(Section, State); 90*db17bf38SDimitry Andric } 91*db17bf38SDimitry Andric case DebugSubsectionKind::CrossScopeImports: { 92*db17bf38SDimitry Andric DebugCrossModuleImportsSubsectionRef Section; 93*db17bf38SDimitry Andric if (auto EC = Section.initialize(Reader)) 94*db17bf38SDimitry Andric return EC; 95*db17bf38SDimitry Andric return V.visitCrossModuleImports(Section, State); 96*db17bf38SDimitry Andric } 97*db17bf38SDimitry Andric case DebugSubsectionKind::Symbols: { 98*db17bf38SDimitry Andric DebugSymbolsSubsectionRef Section; 99*db17bf38SDimitry Andric if (auto EC = Section.initialize(Reader)) 100*db17bf38SDimitry Andric return EC; 101*db17bf38SDimitry Andric return V.visitSymbols(Section, State); 102*db17bf38SDimitry Andric } 103*db17bf38SDimitry Andric case DebugSubsectionKind::StringTable: { 104*db17bf38SDimitry Andric DebugStringTableSubsectionRef Section; 105*db17bf38SDimitry Andric if (auto EC = Section.initialize(Reader)) 106*db17bf38SDimitry Andric return EC; 107*db17bf38SDimitry Andric return V.visitStringTable(Section, State); 108*db17bf38SDimitry Andric } 109*db17bf38SDimitry Andric case DebugSubsectionKind::FrameData: { 110*db17bf38SDimitry Andric DebugFrameDataSubsectionRef Section; 111*db17bf38SDimitry Andric if (auto EC = Section.initialize(Reader)) 112*db17bf38SDimitry Andric return EC; 113*db17bf38SDimitry Andric return V.visitFrameData(Section, State); 114*db17bf38SDimitry Andric } 115*db17bf38SDimitry Andric case DebugSubsectionKind::CoffSymbolRVA: { 116*db17bf38SDimitry Andric DebugSymbolRVASubsectionRef Section; 117*db17bf38SDimitry Andric if (auto EC = Section.initialize(Reader)) 118*db17bf38SDimitry Andric return EC; 119*db17bf38SDimitry Andric return V.visitCOFFSymbolRVAs(Section, State); 12089cb50c9SDimitry Andric } 12189cb50c9SDimitry Andric default: { 12289cb50c9SDimitry Andric DebugUnknownSubsectionRef Fragment(R.kind(), R.getRecordData()); 12389cb50c9SDimitry Andric return V.visitUnknown(Fragment); 12489cb50c9SDimitry Andric } 12589cb50c9SDimitry Andric } 12689cb50c9SDimitry Andric } 127