blob: 48b9b0496ffea0953fb51f952eb16d4241746d85 [file] [log] [blame]
Zachary Turner0d840742016-10-07 21:34:46 +00001//===- CVSymbolVisitor.cpp --------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Zachary Turner0d840742016-10-07 21:34:46 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h"
10
11#include "llvm/DebugInfo/CodeView/CodeViewError.h"
12#include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
Zachary Turner0d840742016-10-07 21:34:46 +000013
14using namespace llvm;
15using namespace llvm::codeview;
16
Zachary Turner0d840742016-10-07 21:34:46 +000017CVSymbolVisitor::CVSymbolVisitor(SymbolVisitorCallbacks &Callbacks)
18 : Callbacks(Callbacks) {}
19
20template <typename T>
21static Error visitKnownRecord(CVSymbol &Record,
22 SymbolVisitorCallbacks &Callbacks) {
Reid Klecknere10d0042019-04-04 00:28:48 +000023 SymbolRecordKind RK = static_cast<SymbolRecordKind>(Record.kind());
Zachary Turner0d840742016-10-07 21:34:46 +000024 T KnownRecord(RK);
25 if (auto EC = Callbacks.visitKnownRecord(Record, KnownRecord))
26 return EC;
27 return Error::success();
28}
29
Zachary Turneraf8c75a2017-06-30 21:35:00 +000030static Error finishVisitation(CVSymbol &Record,
31 SymbolVisitorCallbacks &Callbacks) {
Reid Klecknere10d0042019-04-04 00:28:48 +000032 switch (Record.kind()) {
Zachary Turner0d840742016-10-07 21:34:46 +000033 default:
34 if (auto EC = Callbacks.visitUnknownSymbol(Record))
35 return EC;
36 break;
37#define SYMBOL_RECORD(EnumName, EnumVal, Name) \
38 case EnumName: { \
39 if (auto EC = visitKnownRecord<Name>(Record, Callbacks)) \
40 return EC; \
41 break; \
42 }
43#define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) \
44 SYMBOL_RECORD(EnumVal, EnumVal, AliasName)
Zachary Turnerd4273832017-05-30 21:53:05 +000045#include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
Zachary Turner0d840742016-10-07 21:34:46 +000046 }
47
48 if (auto EC = Callbacks.visitSymbolEnd(Record))
49 return EC;
50
51 return Error::success();
52}
53
Zachary Turneraf8c75a2017-06-30 21:35:00 +000054Error CVSymbolVisitor::visitSymbolRecord(CVSymbol &Record) {
55 if (auto EC = Callbacks.visitSymbolBegin(Record))
56 return EC;
57 return finishVisitation(Record, Callbacks);
58}
59
60Error CVSymbolVisitor::visitSymbolRecord(CVSymbol &Record, uint32_t Offset) {
61 if (auto EC = Callbacks.visitSymbolBegin(Record, Offset))
62 return EC;
63 return finishVisitation(Record, Callbacks);
64}
65
Zachary Turner0d840742016-10-07 21:34:46 +000066Error CVSymbolVisitor::visitSymbolStream(const CVSymbolArray &Symbols) {
67 for (auto I : Symbols) {
68 if (auto EC = visitSymbolRecord(I))
69 return EC;
70 }
71 return Error::success();
72}
Zachary Turneraf8c75a2017-06-30 21:35:00 +000073
74Error CVSymbolVisitor::visitSymbolStream(const CVSymbolArray &Symbols,
75 uint32_t InitialOffset) {
76 for (auto I : Symbols) {
Zachary Turner579264b2018-12-06 16:55:00 +000077 if (auto EC = visitSymbolRecord(I, InitialOffset + Symbols.skew()))
Zachary Turneraf8c75a2017-06-30 21:35:00 +000078 return EC;
79 InitialOffset += I.length();
80 }
81 return Error::success();
82}