1 //===- DebugSubsectionVisitor.h -----------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGSUBSECTIONVISITOR_H 10 #define LLVM_DEBUGINFO_CODEVIEW_DEBUGSUBSECTIONVISITOR_H 11 12 #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h" 13 #include "llvm/Support/Error.h" 14 15 namespace llvm { 16 17 namespace codeview { 18 19 class DebugChecksumsSubsectionRef; 20 class DebugSubsectionRecord; 21 class DebugInlineeLinesSubsectionRef; 22 class DebugCrossModuleExportsSubsectionRef; 23 class DebugCrossModuleImportsSubsectionRef; 24 class DebugFrameDataSubsectionRef; 25 class DebugLinesSubsectionRef; 26 class DebugStringTableSubsectionRef; 27 class DebugSymbolRVASubsectionRef; 28 class DebugSymbolsSubsectionRef; 29 class DebugUnknownSubsectionRef; 30 31 class DebugSubsectionVisitor { 32 public: 33 virtual ~DebugSubsectionVisitor() = default; 34 35 virtual Error visitUnknown(DebugUnknownSubsectionRef &Unknown) { 36 return Error::success(); 37 } 38 virtual Error visitLines(DebugLinesSubsectionRef &Lines, 39 const StringsAndChecksumsRef &State) = 0; 40 virtual Error visitFileChecksums(DebugChecksumsSubsectionRef &Checksums, 41 const StringsAndChecksumsRef &State) = 0; 42 virtual Error visitInlineeLines(DebugInlineeLinesSubsectionRef &Inlinees, 43 const StringsAndChecksumsRef &State) = 0; 44 virtual Error 45 visitCrossModuleExports(DebugCrossModuleExportsSubsectionRef &CSE, 46 const StringsAndChecksumsRef &State) = 0; 47 virtual Error 48 visitCrossModuleImports(DebugCrossModuleImportsSubsectionRef &CSE, 49 const StringsAndChecksumsRef &State) = 0; 50 51 virtual Error visitStringTable(DebugStringTableSubsectionRef &ST, 52 const StringsAndChecksumsRef &State) = 0; 53 54 virtual Error visitSymbols(DebugSymbolsSubsectionRef &CSE, 55 const StringsAndChecksumsRef &State) = 0; 56 57 virtual Error visitFrameData(DebugFrameDataSubsectionRef &FD, 58 const StringsAndChecksumsRef &State) = 0; 59 virtual Error visitCOFFSymbolRVAs(DebugSymbolRVASubsectionRef &RVAs, 60 const StringsAndChecksumsRef &State) = 0; 61 }; 62 63 Error visitDebugSubsection(const DebugSubsectionRecord &R, 64 DebugSubsectionVisitor &V, 65 const StringsAndChecksumsRef &State); 66 67 namespace detail { 68 template <typename T> 69 Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V, 70 StringsAndChecksumsRef &State) { 71 State.initialize(std::forward<T>(FragmentRange)); 72 73 for (const DebugSubsectionRecord &L : FragmentRange) { 74 if (auto EC = visitDebugSubsection(L, V, State)) 75 return EC; 76 } 77 return Error::success(); 78 } 79 } // namespace detail 80 81 template <typename T> 82 Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V) { 83 StringsAndChecksumsRef State; 84 return detail::visitDebugSubsections(std::forward<T>(FragmentRange), V, 85 State); 86 } 87 88 template <typename T> 89 Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V, 90 const DebugStringTableSubsectionRef &Strings) { 91 StringsAndChecksumsRef State(Strings); 92 return detail::visitDebugSubsections(std::forward<T>(FragmentRange), V, 93 State); 94 } 95 96 template <typename T> 97 Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V, 98 const DebugStringTableSubsectionRef &Strings, 99 const DebugChecksumsSubsectionRef &Checksums) { 100 StringsAndChecksumsRef State(Strings, Checksums); 101 return detail::visitDebugSubsections(std::forward<T>(FragmentRange), V, 102 State); 103 } 104 105 } // end namespace codeview 106 107 } // end namespace llvm 108 109 #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGSUBSECTIONVISITOR_H 110