LLVM 20.0.0git
LVObject.h
Go to the documentation of this file.
1//===-- LVObject.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// This file defines the LVObject class, which is used to describe a debug
10// information object.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVOBJECT_H
15#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVOBJECT_H
16
21#include <limits>
22#include <list>
23#include <string>
24
25namespace llvm {
26namespace dwarf {
27// Support for CodeView ModifierOptions::Unaligned.
29} // namespace dwarf
30} // namespace llvm
31
32namespace llvm {
33namespace logicalview {
34
40using LVSigned = int64_t;
42using LVSmall = uint8_t;
43
44class LVElement;
45class LVLine;
46class LVLocation;
48class LVObject;
49class LVOperation;
50class LVScope;
51class LVSymbol;
52class LVType;
53
54class LVOptions;
55class LVPatterns;
56
62
63using LVElementSetFunction = void (LVElement::*)();
64using LVElementGetFunction = bool (LVElement::*)() const;
65using LVLineSetFunction = void (LVLine::*)();
66using LVLineGetFunction = bool (LVLine::*)() const;
67using LVObjectSetFunction = void (LVObject::*)();
68using LVObjectGetFunction = bool (LVObject::*)() const;
69using LVScopeSetFunction = void (LVScope::*)();
70using LVScopeGetFunction = bool (LVScope::*)() const;
71using LVSymbolSetFunction = void (LVSymbol::*)();
72using LVSymbolGetFunction = bool (LVSymbol::*)() const;
73using LVTypeSetFunction = void (LVType::*)();
74using LVTypeGetFunction = bool (LVType::*)() const;
75
83
85
86const LVAddress MaxAddress = std::numeric_limits<uint64_t>::max();
87
88enum class LVBinaryType { NONE, ELF, COFF };
89enum class LVComparePass { Missing, Added };
90
91// Validate functions.
93
94// Keep counters of objects.
95struct LVCounter {
96 unsigned Lines = 0;
97 unsigned Scopes = 0;
98 unsigned Symbols = 0;
99 unsigned Types = 0;
100 void reset() {
101 Lines = 0;
102 Scopes = 0;
103 Symbols = 0;
104 Types = 0;
105 }
106};
107
108class LVObject {
109 enum class Property {
110 IsLocation, // Location.
111 IsGlobalReference, // This object is being referenced from another CU.
112 IsGeneratedName, // The Object name was generated.
113 IsResolved, // Object has been resolved.
114 IsResolvedName, // Object name has been resolved.
115 IsDiscarded, // Object has been stripped by the linker.
116 IsOptimized, // Object has been optimized by the compiler.
117 IsAdded, // Object has been 'added'.
118 IsMatched, // Object has been matched to a given pattern.
119 IsMissing, // Object is 'missing'.
120 IsMissingLink, // Object is indirectly 'missing'.
121 IsInCompare, // In 'compare' mode.
122 IsFileFromReference, // File ID from specification.
123 IsLineFromReference, // Line No from specification.
124 HasMoved, // The object was moved from 'target' to 'reference'.
125 HasPattern, // The object has a pattern.
126 IsFinalized, // CodeView object is finalized.
127 IsReferenced, // CodeView object being referenced.
128 HasCodeViewLocation, // CodeView object with debug location.
130 };
131 // Typed bitvector with properties for this object.
132 LVProperties<Property> Properties;
133
134 LVOffset Offset = 0;
135 uint32_t LineNumber = 0;
136 LVLevel ScopeLevel = 0;
137 union {
141 } TagAttrOpcode = {dwarf::DW_TAG_null};
142
143 // The parent of this object (nullptr if the root scope). For locations,
144 // the parent is a symbol object; otherwise it is a scope object.
145 union {
149 } Parent = {nullptr};
150
151 // We do not support any object duplication, as they are created by parsing
152 // the debug information. There is only the case where we need a very basic
153 // object, to manipulate its offset, line number and scope level. Allow the
154 // copy constructor to create that object; it is used to print a reference
155 // to another object and in the case of templates, to print its encoded args.
156 LVObject(const LVObject &Object) {
157#ifndef NDEBUG
158 incID();
159#endif
160 Properties = Object.Properties;
161 Offset = Object.Offset;
162 LineNumber = Object.LineNumber;
163 ScopeLevel = Object.ScopeLevel;
164 TagAttrOpcode = Object.TagAttrOpcode;
165 Parent = Object.Parent;
166 }
167
168#ifndef NDEBUG
169 // This is an internal ID used for debugging logical elements. It is used
170 // for cases where an unique offset within the binary input file is not
171 // available.
172 static uint64_t GID;
173 uint64_t ID = 0;
174
175 void incID() {
176 ++GID;
177 ID = GID;
178 }
179#endif
180
181protected:
182 // Get a string representation for the given number and discriminator.
183 std::string lineAsString(uint32_t LineNumber, LVHalf Discriminator,
184 bool ShowZero) const;
185
186 // Get a string representation for the given number.
187 std::string referenceAsString(uint32_t LineNumber, bool Spaces) const;
188
189 // Print the Filename or Pathname.
190 // Empty implementation for those objects that do not have any user
191 // source file references, such as debug locations.
192 virtual void printFileIndex(raw_ostream &OS, bool Full = true) const {}
193
194public:
196#ifndef NDEBUG
197 incID();
198#endif
199 };
200 LVObject &operator=(const LVObject &) = delete;
201 virtual ~LVObject() = default;
202
203 PROPERTY(Property, IsLocation);
204 PROPERTY(Property, IsGlobalReference);
205 PROPERTY(Property, IsGeneratedName);
206 PROPERTY(Property, IsResolved);
207 PROPERTY(Property, IsResolvedName);
208 PROPERTY(Property, IsDiscarded);
209 PROPERTY(Property, IsOptimized);
210 PROPERTY(Property, IsAdded);
211 PROPERTY(Property, IsMatched);
212 PROPERTY(Property, IsMissing);
213 PROPERTY(Property, IsMissingLink);
214 PROPERTY(Property, IsInCompare);
215 PROPERTY(Property, IsFileFromReference);
216 PROPERTY(Property, IsLineFromReference);
217 PROPERTY(Property, HasMoved);
218 PROPERTY(Property, HasPattern);
219 PROPERTY(Property, IsFinalized);
220 PROPERTY(Property, IsReferenced);
221 PROPERTY(Property, HasCodeViewLocation);
222
223 // True if the scope has been named or typed or with line number.
224 virtual bool isNamed() const { return false; }
225 virtual bool isTyped() const { return false; }
226 virtual bool isFiled() const { return false; }
227 bool isLined() const { return LineNumber != 0; }
228
229 // DWARF tag, attribute or expression opcode.
230 dwarf::Tag getTag() const { return TagAttrOpcode.Tag; }
231 void setTag(dwarf::Tag Tag) { TagAttrOpcode.Tag = Tag; }
232 dwarf::Attribute getAttr() const { return TagAttrOpcode.Attr; }
233 void setAttr(dwarf::Attribute Attr) { TagAttrOpcode.Attr = Attr; }
234 LVSmall getOpcode() const { return TagAttrOpcode.Opcode; }
235 void setOpcode(LVSmall Opcode) { TagAttrOpcode.Opcode = Opcode; }
236
237 // DIE offset.
238 LVOffset getOffset() const { return Offset; }
239 void setOffset(LVOffset DieOffset) { Offset = DieOffset; }
240
241 // Level where this object is located.
242 LVLevel getLevel() const { return ScopeLevel; }
243 void setLevel(LVLevel Level) { ScopeLevel = Level; }
244
245 virtual StringRef getName() const { return StringRef(); }
246 virtual void setName(StringRef ObjectName) {}
247
249 assert((!Parent.Element || static_cast<LVElement *>(Parent.Element)) &&
250 "Invalid element");
251 return Parent.Element;
252 }
254 assert((!Parent.Scope || static_cast<LVScope *>(Parent.Scope)) &&
255 "Invalid scope");
256 return Parent.Scope;
257 }
259 assert((!Parent.Symbol || static_cast<LVSymbol *>(Parent.Symbol)) &&
260 "Invalid symbol");
261 return Parent.Symbol;
262 }
263 void setParent(LVScope *Scope);
265 void resetParent() { Parent = {nullptr}; }
266
267 virtual LVAddress getLowerAddress() const { return 0; }
269 virtual LVAddress getUpperAddress() const { return 0; }
271
272 uint32_t getLineNumber() const { return LineNumber; }
273 void setLineNumber(uint32_t Number) { LineNumber = Number; }
274
275 virtual const char *kind() const { return nullptr; }
276
277 std::string indentAsString() const;
278 std::string indentAsString(LVLevel Level) const;
279
280 // String used as padding for printing objects with no line number.
281 virtual std::string noLineAsString(bool ShowZero) const;
282
283 // Line number for display; in the case of inlined functions, we use the
284 // DW_AT_call_line attribute; otherwise use DW_AT_decl_line attribute.
285 virtual std::string lineNumberAsString(bool ShowZero = false) const {
286 return lineAsString(getLineNumber(), 0, ShowZero);
287 }
288 std::string lineNumberAsStringStripped(bool ShowZero = false) const;
289
290 // This function prints the logical view to an output stream.
291 // Split: Prints the compilation unit view to a file.
292 // Match: Prints the object only if it satisfies the patterns collected
293 // from the command line. See the '--select' option.
294 // Print: Print the object only if satisfies the conditions specified by
295 // the different '--print' options.
296 // Full: Prints full information for objects representing debug locations,
297 // aggregated scopes, compile unit, functions and namespaces.
298 virtual Error doPrint(bool Split, bool Match, bool Print, raw_ostream &OS,
299 bool Full = true) const;
300 void printAttributes(raw_ostream &OS, bool Full = true) const;
302 LVObject *Parent, StringRef Value,
303 bool UseQuotes = false, bool PrintRef = false) const;
304
305 // Mark branch as missing (current element and parents).
306 void markBranchAsMissing();
307
308 // Prints the common information for an object (name, type, etc).
309 virtual void print(raw_ostream &OS, bool Full = true) const;
310 // Prints additional information for an object, depending on its kind
311 // (class attributes, debug ranges, files, directories, etc).
312 virtual void printExtra(raw_ostream &OS, bool Full = true) const {}
313
314#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
315 virtual void dump() const { print(dbgs()); }
316#endif
317
318 uint64_t getID() const {
319 return
320#ifndef NDEBUG
321 ID;
322#else
323 0;
324#endif
325 }
326};
327
328} // end namespace logicalview
329} // end namespace llvm
330
331#endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVOBJECT_H
static cl::opt< bool > PrintRef("print-ref", cl::ReallyHidden)
This file contains constants used for implementing Dwarf debug support.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
LLVM Value Representation.
Definition: Value.h:74
PROPERTY(Property, IsDiscarded)
virtual StringRef getName() const
Definition: LVObject.h:245
std::string referenceAsString(uint32_t LineNumber, bool Spaces) const
Definition: LVObject.cpp:79
virtual bool isFiled() const
Definition: LVObject.h:226
PROPERTY(Property, IsAdded)
virtual LVAddress getUpperAddress() const
Definition: LVObject.h:269
PROPERTY(Property, IsGeneratedName)
virtual Error doPrint(bool Split, bool Match, bool Print, raw_ostream &OS, bool Full=true) const
Definition: LVObject.cpp:110
virtual const char * kind() const
Definition: LVObject.h:275
LVObject & operator=(const LVObject &)=delete
LVScope * getParentScope() const
Definition: LVObject.h:253
dwarf::Tag getTag() const
Definition: LVObject.h:230
LVSmall getOpcode() const
Definition: LVObject.h:234
PROPERTY(Property, IsMissing)
std::string lineAsString(uint32_t LineNumber, LVHalf Discriminator, bool ShowZero) const
Definition: LVObject.cpp:52
virtual void setLowerAddress(LVAddress Address)
Definition: LVObject.h:268
std::string indentAsString() const
Definition: LVObject.cpp:40
virtual void print(raw_ostream &OS, bool Full=true) const
Definition: LVObject.cpp:160
dwarf::Attribute Attr
Definition: LVObject.h:139
virtual void dump() const
Definition: LVObject.h:315
void setLevel(LVLevel Level)
Definition: LVObject.h:243
void printAttributes(raw_ostream &OS, bool Full=true) const
Definition: LVObject.cpp:139
dwarf::Attribute getAttr() const
Definition: LVObject.h:232
virtual std::string lineNumberAsString(bool ShowZero=false) const
Definition: LVObject.h:285
virtual void setName(StringRef ObjectName)
Definition: LVObject.h:246
void setOpcode(LVSmall Opcode)
Definition: LVObject.h:235
PROPERTY(Property, IsLineFromReference)
virtual void printExtra(raw_ostream &OS, bool Full=true) const
Definition: LVObject.h:312
PROPERTY(Property, IsMissingLink)
virtual bool isNamed() const
Definition: LVObject.h:224
virtual bool isTyped() const
Definition: LVObject.h:225
LVLevel getLevel() const
Definition: LVObject.h:242
PROPERTY(Property, IsReferenced)
void setParent(LVScope *Scope)
Definition: LVObject.cpp:89
PROPERTY(Property, HasMoved)
PROPERTY(Property, IsResolvedName)
void setAttr(dwarf::Attribute Attr)
Definition: LVObject.h:233
PROPERTY(Property, IsLocation)
virtual ~LVObject()=default
virtual void printFileIndex(raw_ostream &OS, bool Full=true) const
Definition: LVObject.h:192
uint64_t getID() const
Definition: LVObject.h:318
PROPERTY(Property, IsMatched)
PROPERTY(Property, HasPattern)
LVSymbol * getParentSymbol() const
Definition: LVObject.h:258
uint32_t getLineNumber() const
Definition: LVObject.h:272
virtual std::string noLineAsString(bool ShowZero) const
Definition: LVObject.cpp:47
PROPERTY(Property, IsResolved)
void setOffset(LVOffset DieOffset)
Definition: LVObject.h:239
LVOffset getOffset() const
Definition: LVObject.h:238
PROPERTY(Property, IsFinalized)
PROPERTY(Property, HasCodeViewLocation)
void setLineNumber(uint32_t Number)
Definition: LVObject.h:273
LVElement * getParent() const
Definition: LVObject.h:248
void setTag(dwarf::Tag Tag)
Definition: LVObject.h:231
PROPERTY(Property, IsFileFromReference)
PROPERTY(Property, IsInCompare)
PROPERTY(Property, IsOptimized)
std::string lineNumberAsStringStripped(bool ShowZero=false) const
Definition: LVObject.cpp:75
virtual void setUpperAddress(LVAddress Address)
Definition: LVObject.h:270
virtual LVAddress getLowerAddress() const
Definition: LVObject.h:267
PROPERTY(Property, IsGlobalReference)
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
Attribute
Attributes.
Definition: Dwarf.h:123
@ DW_TAG_hi_user
Definition: Dwarf.h:107
constexpr Tag DW_TAG_unaligned
Definition: LVObject.h:28
bool(LVElement::*)() const LVElementGetFunction
Definition: LVObject.h:64
int64_t LVSigned
Definition: LVObject.h:40
bool(LVSymbol::*)() const LVSymbolGetFunction
Definition: LVObject.h:72
uint8_t LVSmall
Definition: LVObject.h:42
void(LVType::*)() LVTypeSetFunction
Definition: LVObject.h:73
StringRef typeUnknown()
Definition: LVObject.cpp:31
StringRef emptyString()
Definition: LVObject.cpp:32
bool(LVLine::*)() const LVLineGetFunction
Definition: LVObject.h:66
StringRef typeNone()
Definition: LVObject.cpp:28
const LVAddress MaxAddress
Definition: LVObject.h:86
bool(LVObject::*)() const LVObjectGetFunction
Definition: LVObject.h:68
bool(LVScope::*)() const LVScopeGetFunction
Definition: LVObject.h:70
bool(LVLocation::*)() LVValidLocation
Definition: LVObject.h:92
void(LVSymbol::*)() LVSymbolSetFunction
Definition: LVObject.h:71
uint16_t LVHalf
Definition: LVObject.h:37
void(LVObject::*)() LVObjectSetFunction
Definition: LVObject.h:67
StringRef typeInt()
Definition: LVObject.cpp:30
void(LVLine::*)() LVLineSetFunction
Definition: LVObject.h:65
bool(LVType::*)() const LVTypeGetFunction
Definition: LVObject.h:74
StringRef typeVoid()
Definition: LVObject.cpp:29
void(LVScope::*)() LVScopeSetFunction
Definition: LVObject.h:69
void(LVElement::*)() LVElementSetFunction
Definition: LVObject.h:63
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163