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