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