1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
#pragma once
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
//===-- LVSymbol.h ----------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the LVSymbol class, which is used to describe a debug
// information symbol.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSYMBOL_H
#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSYMBOL_H
#include "llvm/DebugInfo/LogicalView/Core/LVElement.h"
namespace llvm {
namespace logicalview {
enum class LVSymbolKind {
IsCallSiteParameter,
IsConstant,
IsInheritance,
IsMember,
IsParameter,
IsUnspecified,
IsVariable,
LastEntry
};
using LVSymbolKindSet = std::set<LVSymbolKind>;
using LVSymbolDispatch = std::map<LVSymbolKind, LVSymbolGetFunction>;
using LVSymbolRequest = std::vector<LVSymbolGetFunction>;
class LVSymbol final : public LVElement {
enum class Property { HasLocation, FillGaps, LastEntry };
// Typed bitvector with kinds and properties for this symbol.
LVProperties<LVSymbolKind> Kinds;
LVProperties<Property> Properties;
static LVSymbolDispatch Dispatch;
// CodeView symbol Linkage name.
size_t LinkageNameIndex = 0;
// Reference to DW_AT_specification, DW_AT_abstract_origin attribute.
LVSymbol *Reference = nullptr;
LVAutoLocations *Locations = nullptr;
LVLocation *CurrentLocation = nullptr;
// Bitfields length.
uint32_t BitSize = 0;
// Index in the String pool representing any initial value.
size_t ValueIndex = 0;
// Coverage factor in units (bytes).
unsigned CoverageFactor = 0;
float CoveragePercentage = 0;
// Add a location gap into the location list.
LVAutoLocations::iterator addLocationGap(LVAutoLocations::iterator Pos,
LVAddress LowPC, LVAddress HighPC);
// Find the current symbol in the given 'Targets'.
LVSymbol *findIn(const LVSymbols *Targets) const;
public:
LVSymbol() : LVElement(LVSubclassID::LV_SYMBOL) {
setIsSymbol();
setIncludeInPrint();
}
LVSymbol(const LVSymbol &) = delete;
LVSymbol &operator=(const LVSymbol &) = delete;
~LVSymbol() { delete Locations; }
static bool classof(const LVElement *Element) {
return Element->getSubclassID() == LVSubclassID::LV_SYMBOL;
}
KIND(LVSymbolKind, IsCallSiteParameter);
KIND(LVSymbolKind, IsConstant);
KIND(LVSymbolKind, IsInheritance);
KIND(LVSymbolKind, IsMember);
KIND(LVSymbolKind, IsParameter);
KIND(LVSymbolKind, IsUnspecified);
KIND(LVSymbolKind, IsVariable);
PROPERTY(Property, HasLocation);
PROPERTY(Property, FillGaps);
const char *kind() const override;
// Access DW_AT_specification, DW_AT_abstract_origin reference.
LVSymbol *getReference() const { return Reference; }
void setReference(LVSymbol *Symbol) override {
Reference = Symbol;
setHasReference();
}
void setReference(LVElement *Element) override {
assert((!Element || isa<LVSymbol>(Element)) && "Invalid element");
setReference(static_cast<LVSymbol *>(Element));
}
void setLinkageName(StringRef LinkageName) override {
LinkageNameIndex = getStringPool().getIndex(LinkageName);
}
StringRef getLinkageName() const override {
return getStringPool().getString(LinkageNameIndex);
}
size_t getLinkageNameIndex() const override { return LinkageNameIndex; }
uint32_t getBitSize() const override { return BitSize; }
void setBitSize(uint32_t Size) override { BitSize = Size; }
// Process the values for a DW_AT_const_value.
std::string getValue() const override {
return std::string(getStringPool().getString(ValueIndex));
}
void setValue(StringRef Value) override {
ValueIndex = getStringPool().getIndex(Value);
}
size_t getValueIndex() const override { return ValueIndex; }
// Add a Location Entry.
void addLocationConstant(dwarf::Attribute Attr, LVUnsigned Constant,
uint64_t LocDescOffset);
void addLocationOperands(LVSmall Opcode, uint64_t Operand1,
uint64_t Operand2);
void addLocation(dwarf::Attribute Attr, LVAddress LowPC, LVAddress HighPC,
LVUnsigned SectionOffset, uint64_t LocDescOffset,
bool CallSiteLocation = false);
// Fill gaps in the location list.
void fillLocationGaps();
// Get all the locations associated with symbols.
void getLocations(LVLocations &LocationList, LVValidLocation ValidLocation,
bool RecordInvalid = false);
void getLocations(LVLocations &LocationList) const;
// Calculate coverage factor.
void calculateCoverage();
unsigned getCoverageFactor() const { return CoverageFactor; }
void setCoverageFactor(unsigned Value) { CoverageFactor = Value; }
float getCoveragePercentage() const { return CoveragePercentage; }
void setCoveragePercentage(float Value) { CoveragePercentage = Value; }
// Print location in raw format.
void printLocations(raw_ostream &OS, bool Full = true) const;
// Follow a chain of references given by DW_AT_abstract_origin and/or
// DW_AT_specification and update the symbol name.
StringRef resolveReferencesChain();
void resolveName() override;
void resolveReferences() override;
static LVSymbolDispatch &getDispatch() { return Dispatch; }
static bool parametersMatch(const LVSymbols *References,
const LVSymbols *Targets);
static void getParameters(const LVSymbols *Symbols, LVSymbols *Parameters);
// Iterate through the 'References' set and check that all its elements
// are present in the 'Targets' set. For a missing element, mark its
// parents as missing.
static void markMissingParents(const LVSymbols *References,
const LVSymbols *Targets);
// Returns true if current type is logically equal to the given 'Symbol'.
bool equals(const LVSymbol *Symbol) const;
// Returns true if the given 'References' are logically equal to the
// given 'Targets'.
static bool equals(const LVSymbols *References, const LVSymbols *Targets);
// Report the current symbol as missing or added during comparison.
void report(LVComparePass Pass) override;
void print(raw_ostream &OS, bool Full = true) const override;
void printExtra(raw_ostream &OS, bool Full = true) const override;
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void dump() const override { print(dbgs()); }
#endif
};
} // end namespace logicalview
} // end namespace llvm
#endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSYMBOL_H
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
|