1 //===- CVSymbolVisitor.cpp --------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h"
11 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
12 #include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
15 using namespace llvm::codeview
;
17 CVSymbolVisitor::CVSymbolVisitor(SymbolVisitorCallbacks
&Callbacks
)
18 : Callbacks(Callbacks
) {}
21 static Error
visitKnownRecord(CVSymbol
&Record
,
22 SymbolVisitorCallbacks
&Callbacks
) {
23 SymbolRecordKind RK
= static_cast<SymbolRecordKind
>(Record
.kind());
25 if (auto EC
= Callbacks
.visitKnownRecord(Record
, KnownRecord
))
27 return Error::success();
30 static Error
finishVisitation(CVSymbol
&Record
,
31 SymbolVisitorCallbacks
&Callbacks
) {
32 switch (Record
.kind()) {
34 if (auto EC
= Callbacks
.visitUnknownSymbol(Record
))
37 #define SYMBOL_RECORD(EnumName, EnumVal, Name) \
39 if (auto EC = visitKnownRecord<Name>(Record, Callbacks)) \
43 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) \
44 SYMBOL_RECORD(EnumVal, EnumVal, AliasName)
45 #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
48 if (auto EC
= Callbacks
.visitSymbolEnd(Record
))
51 return Error::success();
54 Error
CVSymbolVisitor::visitSymbolRecord(CVSymbol
&Record
) {
55 if (auto EC
= Callbacks
.visitSymbolBegin(Record
))
57 return finishVisitation(Record
, Callbacks
);
60 Error
CVSymbolVisitor::visitSymbolRecord(CVSymbol
&Record
, uint32_t Offset
) {
61 if (auto EC
= Callbacks
.visitSymbolBegin(Record
, Offset
))
63 return finishVisitation(Record
, Callbacks
);
66 Error
CVSymbolVisitor::visitSymbolStream(const CVSymbolArray
&Symbols
) {
67 for (auto I
: Symbols
) {
68 if (auto EC
= visitSymbolRecord(I
))
71 return Error::success();
74 Error
CVSymbolVisitor::visitSymbolStream(const CVSymbolArray
&Symbols
,
75 uint32_t InitialOffset
) {
76 for (auto I
: Symbols
) {
77 if (auto EC
= visitSymbolRecord(I
, InitialOffset
+ Symbols
.skew()))
79 InitialOffset
+= I
.length();
81 return Error::success();