Home | History | Annotate | Line # | Download | only in CodeView
      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/CodeView.h"
     13 #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
     14 #include "llvm/Support/Error.h"
     15 
     16 namespace llvm {
     17 
     18 namespace codeview {
     19 
     20 class DebugChecksumsSubsectionRef;
     21 class DebugSubsectionRecord;
     22 class DebugInlineeLinesSubsectionRef;
     23 class DebugCrossModuleExportsSubsectionRef;
     24 class DebugCrossModuleImportsSubsectionRef;
     25 class DebugFrameDataSubsectionRef;
     26 class DebugLinesSubsectionRef;
     27 class DebugStringTableSubsectionRef;
     28 class DebugSymbolRVASubsectionRef;
     29 class DebugSymbolsSubsectionRef;
     30 class DebugUnknownSubsectionRef;
     31 
     32 class DebugSubsectionVisitor {
     33 public:
     34   virtual ~DebugSubsectionVisitor() = default;
     35 
     36   virtual Error visitUnknown(DebugUnknownSubsectionRef &Unknown) {
     37     return Error::success();
     38   }
     39   virtual Error visitLines(DebugLinesSubsectionRef &Lines,
     40                            const StringsAndChecksumsRef &State) = 0;
     41   virtual Error visitFileChecksums(DebugChecksumsSubsectionRef &Checksums,
     42                                    const StringsAndChecksumsRef &State) = 0;
     43   virtual Error visitInlineeLines(DebugInlineeLinesSubsectionRef &Inlinees,
     44                                   const StringsAndChecksumsRef &State) = 0;
     45   virtual Error
     46   visitCrossModuleExports(DebugCrossModuleExportsSubsectionRef &CSE,
     47                           const StringsAndChecksumsRef &State) = 0;
     48   virtual Error
     49   visitCrossModuleImports(DebugCrossModuleImportsSubsectionRef &CSE,
     50                           const StringsAndChecksumsRef &State) = 0;
     51 
     52   virtual Error visitStringTable(DebugStringTableSubsectionRef &ST,
     53                                  const StringsAndChecksumsRef &State) = 0;
     54 
     55   virtual Error visitSymbols(DebugSymbolsSubsectionRef &CSE,
     56                              const StringsAndChecksumsRef &State) = 0;
     57 
     58   virtual Error visitFrameData(DebugFrameDataSubsectionRef &FD,
     59                                const StringsAndChecksumsRef &State) = 0;
     60   virtual Error visitCOFFSymbolRVAs(DebugSymbolRVASubsectionRef &RVAs,
     61                                     const StringsAndChecksumsRef &State) = 0;
     62 };
     63 
     64 Error visitDebugSubsection(const DebugSubsectionRecord &R,
     65                            DebugSubsectionVisitor &V,
     66                            const StringsAndChecksumsRef &State);
     67 
     68 namespace detail {
     69 template <typename T>
     70 Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V,
     71                             StringsAndChecksumsRef &State) {
     72   State.initialize(std::forward<T>(FragmentRange));
     73 
     74   for (const DebugSubsectionRecord &L : FragmentRange) {
     75     if (auto EC = visitDebugSubsection(L, V, State))
     76       return EC;
     77   }
     78   return Error::success();
     79 }
     80 } // namespace detail
     81 
     82 template <typename T>
     83 Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V) {
     84   StringsAndChecksumsRef State;
     85   return detail::visitDebugSubsections(std::forward<T>(FragmentRange), V,
     86                                        State);
     87 }
     88 
     89 template <typename T>
     90 Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V,
     91                             const DebugStringTableSubsectionRef &Strings) {
     92   StringsAndChecksumsRef State(Strings);
     93   return detail::visitDebugSubsections(std::forward<T>(FragmentRange), V,
     94                                        State);
     95 }
     96 
     97 template <typename T>
     98 Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V,
     99                             const DebugStringTableSubsectionRef &Strings,
    100                             const DebugChecksumsSubsectionRef &Checksums) {
    101   StringsAndChecksumsRef State(Strings, Checksums);
    102   return detail::visitDebugSubsections(std::forward<T>(FragmentRange), V,
    103                                        State);
    104 }
    105 
    106 } // end namespace codeview
    107 
    108 } // end namespace llvm
    109 
    110 #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGSUBSECTIONVISITOR_H
    111