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