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