1deb39130SZachary Turner //===- DebugSubsectionVisitor.cpp -------------------------------*- C++ -*-===//
28c099fe0SZachary Turner //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
68c099fe0SZachary Turner //
78c099fe0SZachary Turner //===----------------------------------------------------------------------===//
88c099fe0SZachary Turner 
98c099fe0SZachary Turner #include "llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h"
108c099fe0SZachary Turner 
11*81cde474Sserge-sans-paille #include "llvm/DebugInfo/CodeView/CodeView.h"
128c099fe0SZachary Turner #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
13349c18f8SZachary Turner #include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
14349c18f8SZachary Turner #include "llvm/DebugInfo/CodeView/DebugCrossImpSubsection.h"
15deb39130SZachary Turner #include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
168c099fe0SZachary Turner #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
178c099fe0SZachary Turner #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
181bf77620SZachary Turner #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
198c099fe0SZachary Turner #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
203226fe95SZachary Turner #include "llvm/DebugInfo/CodeView/DebugSymbolRVASubsection.h"
21deb39130SZachary Turner #include "llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h"
228c099fe0SZachary Turner #include "llvm/DebugInfo/CodeView/DebugUnknownSubsection.h"
238c099fe0SZachary Turner #include "llvm/Support/BinaryStreamReader.h"
24*81cde474Sserge-sans-paille #include "llvm/Support/SwapByteOrder.h"
258c099fe0SZachary Turner 
268c099fe0SZachary Turner using namespace llvm;
278c099fe0SZachary Turner using namespace llvm::codeview;
288c099fe0SZachary Turner 
visitDebugSubsection(const DebugSubsectionRecord & R,DebugSubsectionVisitor & V,const StringsAndChecksumsRef & State)29a8cfc29cSZachary Turner Error llvm::codeview::visitDebugSubsection(
30a8cfc29cSZachary Turner     const DebugSubsectionRecord &R, DebugSubsectionVisitor &V,
31a8cfc29cSZachary Turner     const StringsAndChecksumsRef &State) {
328c099fe0SZachary Turner   BinaryStreamReader Reader(R.getRecordData());
338c099fe0SZachary Turner   switch (R.kind()) {
348c099fe0SZachary Turner   case DebugSubsectionKind::Lines: {
358c099fe0SZachary Turner     DebugLinesSubsectionRef Fragment;
368c099fe0SZachary Turner     if (auto EC = Fragment.initialize(Reader))
378c099fe0SZachary Turner       return EC;
388c099fe0SZachary Turner 
391bf77620SZachary Turner     return V.visitLines(Fragment, State);
408c099fe0SZachary Turner   }
418c099fe0SZachary Turner   case DebugSubsectionKind::FileChecksums: {
428c099fe0SZachary Turner     DebugChecksumsSubsectionRef Fragment;
438c099fe0SZachary Turner     if (auto EC = Fragment.initialize(Reader))
448c099fe0SZachary Turner       return EC;
458c099fe0SZachary Turner 
461bf77620SZachary Turner     return V.visitFileChecksums(Fragment, State);
478c099fe0SZachary Turner   }
488c099fe0SZachary Turner   case DebugSubsectionKind::InlineeLines: {
498c099fe0SZachary Turner     DebugInlineeLinesSubsectionRef Fragment;
508c099fe0SZachary Turner     if (auto EC = Fragment.initialize(Reader))
518c099fe0SZachary Turner       return EC;
521bf77620SZachary Turner     return V.visitInlineeLines(Fragment, State);
538c099fe0SZachary Turner   }
54349c18f8SZachary Turner   case DebugSubsectionKind::CrossScopeExports: {
55349c18f8SZachary Turner     DebugCrossModuleExportsSubsectionRef Section;
56349c18f8SZachary Turner     if (auto EC = Section.initialize(Reader))
57349c18f8SZachary Turner       return EC;
581bf77620SZachary Turner     return V.visitCrossModuleExports(Section, State);
59349c18f8SZachary Turner   }
60349c18f8SZachary Turner   case DebugSubsectionKind::CrossScopeImports: {
61349c18f8SZachary Turner     DebugCrossModuleImportsSubsectionRef Section;
62349c18f8SZachary Turner     if (auto EC = Section.initialize(Reader))
63349c18f8SZachary Turner       return EC;
641bf77620SZachary Turner     return V.visitCrossModuleImports(Section, State);
65349c18f8SZachary Turner   }
66deb39130SZachary Turner   case DebugSubsectionKind::Symbols: {
67deb39130SZachary Turner     DebugSymbolsSubsectionRef Section;
68deb39130SZachary Turner     if (auto EC = Section.initialize(Reader))
69deb39130SZachary Turner       return EC;
70deb39130SZachary Turner     return V.visitSymbols(Section, State);
71deb39130SZachary Turner   }
72deb39130SZachary Turner   case DebugSubsectionKind::StringTable: {
73deb39130SZachary Turner     DebugStringTableSubsectionRef Section;
74deb39130SZachary Turner     if (auto EC = Section.initialize(Reader))
75deb39130SZachary Turner       return EC;
76deb39130SZachary Turner     return V.visitStringTable(Section, State);
77deb39130SZachary Turner   }
78deb39130SZachary Turner   case DebugSubsectionKind::FrameData: {
79deb39130SZachary Turner     DebugFrameDataSubsectionRef Section;
80deb39130SZachary Turner     if (auto EC = Section.initialize(Reader))
81deb39130SZachary Turner       return EC;
82deb39130SZachary Turner     return V.visitFrameData(Section, State);
83deb39130SZachary Turner   }
843226fe95SZachary Turner   case DebugSubsectionKind::CoffSymbolRVA: {
853226fe95SZachary Turner     DebugSymbolRVASubsectionRef Section;
863226fe95SZachary Turner     if (auto EC = Section.initialize(Reader))
873226fe95SZachary Turner       return EC;
883226fe95SZachary Turner     return V.visitCOFFSymbolRVAs(Section, State);
893226fe95SZachary Turner   }
908c099fe0SZachary Turner   default: {
918c099fe0SZachary Turner     DebugUnknownSubsectionRef Fragment(R.kind(), R.getRecordData());
928c099fe0SZachary Turner     return V.visitUnknown(Fragment);
938c099fe0SZachary Turner   }
948c099fe0SZachary Turner   }
958c099fe0SZachary Turner }
96