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