LLVM 22.0.0git
LVScope.h
Go to the documentation of this file.
1//===-- LVScope.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 LVScope class, which is used to describe a debug
10// information scope.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSCOPE_H
15#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSCOPE_H
16
17#include "llvm/ADT/STLExtras.h"
23#include <list>
24#include <map>
25#include <set>
26
27namespace llvm {
28namespace logicalview {
29
30// Name address, Code size.
31using LVNameInfo = std::pair<LVAddress, uint64_t>;
32using LVPublicNames = std::map<LVScope *, LVNameInfo>;
33using LVPublicAddresses = std::map<LVAddress, LVNameInfo>;
34
35class LVRange;
36
65using LVScopeKindSet = std::set<LVScopeKind>;
66using LVScopeDispatch = std::map<LVScopeKind, LVScopeGetFunction>;
67using LVScopeRequest = std::vector<LVScopeGetFunction>;
68
69using LVOffsetElementMap = std::map<LVOffset, LVElement *>;
70using LVOffsetLinesMap = std::map<LVOffset, LVLines>;
71using LVOffsetLocationsMap = std::map<LVOffset, LVLocations>;
72using LVOffsetSymbolMap = std::map<LVOffset, LVSymbol *>;
73using LVTagOffsetsMap = std::map<dwarf::Tag, LVOffsets>;
74
75// Class to represent a DWARF Scope.
76class LLVM_ABI LVScope : public LVElement {
77 enum class Property {
78 HasDiscriminator,
79 CanHaveRanges,
80 CanHaveLines,
81 HasGlobals,
82 HasLocals,
83 HasLines,
84 HasScopes,
85 HasSymbols,
86 HasTypes,
87 IsComdat,
88 HasComdatScopes, // Compile Unit has comdat functions.
89 HasRanges,
90 AddedMissing, // Added missing referenced symbols.
91 LastEntry
92 };
93
94 // Typed bitvector with kinds and properties for this scope.
96 LVProperties<Property> Properties;
97 static LVScopeDispatch Dispatch;
98 // Empty containers used in `getChildren()` in case there is no Types,
99 // Symbols, or Scopes.
100 static const LVTypes EmptyTypes;
101 static const LVSymbols EmptySymbols;
102 static const LVScopes EmptyScopes;
103
104 // Size in bits if this scope represents also a compound type.
105 uint32_t BitSize = 0;
106
107 // Coverage factor in units (bytes).
108 unsigned CoverageFactor = 0;
109
110 // Calculate coverage factor.
111 void calculateCoverage() {
112 float CoveragePercentage = 0;
113 LVLocation::calculateCoverage(Ranges.get(), CoverageFactor,
114 CoveragePercentage);
115 }
116
117 // Decide if the scope will be printed, using some conditions given by:
118 // only-globals, only-locals, a-pattern.
119 bool resolvePrinting() const;
120
121 // Find the current scope in the given 'Targets'.
122 LVScope *findIn(const LVScopes *Targets) const;
123
124 // Traverse the scope parent tree, executing the given callback function
125 // on each scope.
126 void traverseParents(LVScopeGetFunction GetFunction,
127 LVScopeSetFunction SetFunction);
128
129protected:
130 // Types, Symbols, Scopes, Lines, Locations in this scope.
131 std::unique_ptr<LVTypes> Types;
132 std::unique_ptr<LVSymbols> Symbols;
133 std::unique_ptr<LVScopes> Scopes;
134 std::unique_ptr<LVLines> Lines;
135 std::unique_ptr<LVLocations> Ranges;
136
137 // Resolve the template parameters/arguments relationship.
138 void resolveTemplate();
139 void printEncodedArgs(raw_ostream &OS, bool Full) const;
140
141 void printActiveRanges(raw_ostream &OS, bool Full = true) const;
142 virtual void printSizes(raw_ostream &OS) const {}
143 virtual void printSummary(raw_ostream &OS) const {}
144
145 // Encoded template arguments.
146 virtual StringRef getEncodedArgs() const { return StringRef(); }
147 virtual void setEncodedArgs(StringRef EncodedArgs) {}
148
149public:
151 setIsScope();
152 setIncludeInPrint();
153 }
154 LVScope(const LVScope &) = delete;
155 LVScope &operator=(const LVScope &) = delete;
156 virtual ~LVScope() = default;
157
158 static bool classof(const LVElement *Element) {
159 return Element->getSubclassID() == LVSubclassID::LV_SCOPE;
160 }
161
164 KIND_2(LVScopeKind, IsBlock, CanHaveRanges, CanHaveLines);
168 KIND_3(LVScopeKind, IsCompileUnit, CanHaveRanges, CanHaveLines,
169 TransformName);
172 KIND_2(LVScopeKind, IsFunction, CanHaveRanges, CanHaveLines);
179 KIND_1(LVScopeKind, IsRoot, TransformName);
187 KIND_2(LVScopeKind, IsModule, CanHaveRanges, CanHaveLines);
188
189 PROPERTY(Property, HasDiscriminator);
190 PROPERTY(Property, CanHaveRanges);
191 PROPERTY(Property, CanHaveLines);
192 PROPERTY(Property, HasGlobals);
193 PROPERTY(Property, HasLocals);
194 PROPERTY(Property, HasLines);
195 PROPERTY(Property, HasScopes);
196 PROPERTY(Property, HasSymbols);
197 PROPERTY(Property, HasTypes);
198 PROPERTY(Property, IsComdat);
199 PROPERTY(Property, HasComdatScopes);
200 PROPERTY(Property, HasRanges);
201 PROPERTY(Property, AddedMissing);
202
203 bool isCompileUnit() const override { return getIsCompileUnit(); }
204 bool isRoot() const override { return getIsRoot(); }
205
206 const char *kind() const override;
207
208 // Get the specific children.
209 const LVLines *getLines() const { return Lines.get(); }
210 const LVLocations *getRanges() const { return Ranges.get(); }
211 const LVScopes *getScopes() const { return Scopes.get(); }
212 const LVSymbols *getSymbols() const { return Symbols.get(); }
213 const LVTypes *getTypes() const { return Types.get(); }
214 // Return view over union of child Scopes, Types, and Symbols, in that order.
215 //
216 // Calling `LVScope::sort()` ensures that each of groups is sorted according
217 // to the given criteria (see also `LVOptions::setSortMode()`). Because
218 // `getChildren()` iterates over the concatenation, the result returned by
219 // this function is not necessarily sorted. If order is important, use
220 // `getSortedChildren()`.
222 return llvm::concat<LVElement *const>(Scopes ? *Scopes : EmptyScopes,
223 Types ? *Types : EmptyTypes,
224 Symbols ? *Symbols : EmptySymbols);
225 }
226 // Return vector of child Scopes, Types, and Symbols that is sorted using
227 // `SortFunction`. This requires copy + sort; if order is not important,
228 // use `getChildren()` instead.
229 LVElements getSortedChildren(
231
232 void addElement(LVElement *Element);
233 void addElement(LVLine *Line);
234 void addElement(LVScope *Scope);
235 void addElement(LVSymbol *Symbol);
236 void addElement(LVType *Type);
237 void addObject(LVLocation *Location);
238 void addObject(LVAddress LowerAddress, LVAddress UpperAddress);
239
240 // Add the missing elements from the given 'Reference', which is the
241 // scope associated with any DW_AT_specification, DW_AT_abstract_origin.
242 void addMissingElements(LVScope *Reference);
243
244 // Traverse the scope parent tree and the children, executing the given
245 // callback function on each element.
246 void traverseParentsAndChildren(LVObjectGetFunction GetFunction,
247 LVObjectSetFunction SetFunction);
248
249 // Get the size of specific children.
250 size_t lineCount() const { return Lines ? Lines->size() : 0; }
251 size_t rangeCount() const { return Ranges ? Ranges->size() : 0; }
252 size_t scopeCount() const { return Scopes ? Scopes->size() : 0; }
253 size_t symbolCount() const { return Symbols ? Symbols->size() : 0; }
254 size_t typeCount() const { return Types ? Types->size() : 0; }
255
256 // Find containing parent for the given address.
257 LVScope *outermostParent(LVAddress Address);
258
259 // Get all the locations associated with symbols.
260 void getLocations(LVLocations &LocationList, LVValidLocation ValidLocation,
261 bool RecordInvalid = false);
262 void getRanges(LVLocations &LocationList, LVValidLocation ValidLocation,
263 bool RecordInvalid = false);
264 void getRanges(LVRange &RangeList);
265
266 unsigned getCoverageFactor() const { return CoverageFactor; }
267
268 Error doPrint(bool Split, bool Match, bool Print, raw_ostream &OS,
269 bool Full = true) const override;
270 // Sort the logical elements using the criteria specified by the
271 // command line option '--output-sort'.
272 void sort();
273
274 // Get template parameter types.
275 bool getTemplateParameterTypes(LVTypes &Params);
276
277 // DW_AT_specification, DW_AT_abstract_origin, DW_AT_extension.
278 virtual LVScope *getReference() const { return nullptr; }
279
280 LVScope *getCompileUnitParent() const override {
282 }
283
284 // Follow a chain of references given by DW_AT_abstract_origin and/or
285 // DW_AT_specification and update the scope name.
286 StringRef resolveReferencesChain();
287
288 bool removeElement(LVElement *Element) override;
289 void updateLevel(LVScope *Parent, bool Moved) override;
290
291 uint32_t getBitSize() const override { return BitSize; }
292 void setBitSize(uint32_t Size) override { BitSize = Size; }
293
294 void resolve() override;
295 void resolveName() override;
296 void resolveReferences() override;
297
298 // Return the chain of parents as a string.
299 void getQualifiedName(std::string &QualifiedName) const;
300 // Encode the template arguments.
301 void encodeTemplateArguments(std::string &Name) const;
302 void encodeTemplateArguments(std::string &Name, const LVTypes *Types) const;
303
304 void resolveElements();
305
306 // Iterate through the 'References' set and check that all its elements
307 // are present in the 'Targets' set. For a missing element, mark its
308 // parents as missing.
309 static void markMissingParents(const LVScopes *References,
310 const LVScopes *Targets,
311 bool TraverseChildren);
312
313 // Checks if the current scope is contained within the target scope.
314 // Depending on the result, the callback may be performed.
315 virtual void markMissingParents(const LVScope *Target, bool TraverseChildren);
316
317 // Returns true if the current scope and the given 'Scope' have the
318 // same number of children.
319 virtual bool equalNumberOfChildren(const LVScope *Scope) const;
320
321 // Returns true if current scope is logically equal to the given 'Scope'.
322 virtual bool equals(const LVScope *Scope) const;
323
324 // Returns true if the given 'References' are logically equal to the
325 // given 'Targets'.
326 static bool equals(const LVScopes *References, const LVScopes *Targets);
327
328 // For the given 'Scopes' returns a scope that is logically equal
329 // to the current scope; otherwise 'nullptr'.
330 virtual LVScope *findEqualScope(const LVScopes *Scopes) const;
331
332 // Report the current scope as missing or added during comparison.
333 void report(LVComparePass Pass) override;
334
335 static LVScopeDispatch &getDispatch() { return Dispatch; }
336
337 void print(raw_ostream &OS, bool Full = true) const override;
338 void printExtra(raw_ostream &OS, bool Full = true) const override;
339 virtual void printWarnings(raw_ostream &OS, bool Full = true) const {}
340 virtual void printMatchedElements(raw_ostream &OS, bool UseMatchedElements) {}
341};
342
343// Class to represent a DWARF Union/Structure/Class.
344class LLVM_ABI LVScopeAggregate final : public LVScope {
345 LVScope *Reference = nullptr; // DW_AT_specification, DW_AT_abstract_origin.
346 size_t EncodedArgsIndex = 0; // Template encoded arguments.
347
348public:
352 ~LVScopeAggregate() = default;
353
354 // DW_AT_specification, DW_AT_abstract_origin.
355 LVScope *getReference() const override { return Reference; }
356 void setReference(LVScope *Scope) override {
357 Reference = Scope;
358 setHasReference();
359 }
361 setReference(static_cast<LVScope *>(Element));
362 }
363
364 StringRef getEncodedArgs() const override {
365 return getStringPool().getString(EncodedArgsIndex);
366 }
367 void setEncodedArgs(StringRef EncodedArgs) override {
368 EncodedArgsIndex = getStringPool().getIndex(EncodedArgs);
369 }
370
371 // Returns true if current scope is logically equal to the given 'Scope'.
372 bool equals(const LVScope *Scope) const override;
373
374 // For the given 'Scopes' returns a scope that is logically equal
375 // to the current scope; otherwise 'nullptr'.
376 LVScope *findEqualScope(const LVScopes *Scopes) const override;
377
378 void printExtra(raw_ostream &OS, bool Full = true) const override;
379};
380
381// Class to represent a DWARF Template alias.
382class LLVM_ABI LVScopeAlias final : public LVScope {
383public:
385 setIsTemplateAlias();
386 setIsTemplate();
387 }
388 LVScopeAlias(const LVScopeAlias &) = delete;
390 ~LVScopeAlias() = default;
391
392 // Returns true if current scope is logically equal to the given 'Scope'.
393 bool equals(const LVScope *Scope) const override;
394
395 void printExtra(raw_ostream &OS, bool Full = true) const override;
396};
397
398// Class to represent a DWARF array (DW_TAG_array_type).
399class LLVM_ABI LVScopeArray final : public LVScope {
400public:
401 LVScopeArray() : LVScope() { setIsArray(); }
402 LVScopeArray(const LVScopeArray &) = delete;
404 ~LVScopeArray() = default;
405
406 void resolveExtra() override;
407
408 // Returns true if current scope is logically equal to the given 'Scope'.
409 bool equals(const LVScope *Scope) const override;
410
411 void printExtra(raw_ostream &OS, bool Full = true) const override;
412};
413
414// Class to represent a DWARF Compilation Unit (CU).
415class LLVM_ABI LVScopeCompileUnit final : public LVScope {
416 // Names (files and directories) used by the Compile Unit.
417 std::vector<size_t> Filenames;
418
419 // As the .debug_pubnames section has been removed in DWARF5, we have a
420 // similar functionality, which is used by the decoded functions. We use
421 // the low-pc and high-pc for those scopes that are marked as public, in
422 // order to support DWARF and CodeView.
423 LVPublicNames PublicNames;
424
425 // Toolchain producer.
426 size_t ProducerIndex = 0;
427
428 // Compilation directory name.
429 size_t CompilationDirectoryIndex = 0;
430
431 // Source language.
432 LVSourceLanguage SourceLanguage{};
433
434 // Used by the CodeView Reader.
435 codeview::CPUType CompilationCPUType = codeview::CPUType::X64;
436
437 // Keep record of elements. They are needed at the compilation unit level
438 // to print the summary at the end of the printing.
439 LVCounter Allocated;
440 LVCounter Found;
441 LVCounter Printed;
442
443 // Elements that match a given command line pattern.
444 LVElements MatchedElements;
445 LVScopes MatchedScopes;
446
447 // It records the mapping between logical lines representing a debug line
448 // entry and its address in the text section. It is used to find a line
449 // giving its exact or closest address. To support comdat functions, all
450 // addresses for the same section are recorded in the same map.
451 using LVAddressToLine = std::map<LVAddress, LVLine *>;
453
454 // DWARF Tags (Tag, Element list).
455 LVTagOffsetsMap DebugTags;
456
457 // Offsets associated with objects being flagged as having invalid data
458 // (ranges, locations, lines zero or coverages).
459 LVOffsetElementMap WarningOffsets;
460
461 // Symbols with invalid locations. (Symbol, Location List).
462 LVOffsetLocationsMap InvalidLocations;
463
464 // Symbols with invalid coverage values.
465 LVOffsetSymbolMap InvalidCoverages;
466
467 // Scopes with invalid ranges (Scope, Range list).
468 LVOffsetLocationsMap InvalidRanges;
469
470 // Scopes with lines zero (Scope, Line list).
471 LVOffsetLinesMap LinesZero;
472
473 // Record scopes contribution in bytes to the debug information.
474 using LVSizesMap = std::map<const LVScope *, LVOffset>;
475 LVSizesMap Sizes;
476 LVOffset CUContributionSize = 0;
477
478 // Helper function to add an invalid location/range.
479 void addInvalidLocationOrRange(LVLocation *Location, LVElement *Element,
481 LVOffset Offset = Element->getOffset();
484 Location);
485 }
486
487 // Record scope sizes indexed by lexical level.
488 // Setting an initial size that will cover a very deep nested scopes.
489 static constexpr size_t TotalInitialSize = 8;
490 using LVTotalsEntry = std::pair<unsigned, float>;
492 // Maximum seen lexical level. It is used to control how many entries
493 // in the 'Totals' vector are valid values.
494 LVLevel MaxSeenLevel = 0;
495
496 // Get the line located at the given address.
497 LVLine *lineLowerBound(LVAddress Address, LVScope *Scope) const;
498 LVLine *lineUpperBound(LVAddress Address, LVScope *Scope) const;
499
500 void printScopeSize(const LVScope *Scope, raw_ostream &OS);
501 void printScopeSize(const LVScope *Scope, raw_ostream &OS) const {
502 (const_cast<LVScopeCompileUnit *>(this))->printScopeSize(Scope, OS);
503 }
504 void printTotals(raw_ostream &OS) const;
505
506protected:
507 void printSizes(raw_ostream &OS) const override;
508 void printSummary(raw_ostream &OS) const override;
509
510public:
511 LVScopeCompileUnit() : LVScope(), Totals(TotalInitialSize, {0, 0.0}) {
512 setIsCompileUnit();
513 }
517
518 LVScope *getCompileUnitParent() const override {
519 return static_cast<LVScope *>(const_cast<LVScopeCompileUnit *>(this));
520 }
521
522 // Add line to address mapping.
523 void addMapping(LVLine *Line, LVSectionIndex SectionIndex);
524 LVLineRange lineRange(LVLocation *Location) const;
525
526 static constexpr LVNameInfo NameNone = {UINT64_MAX, 0};
528 PublicNames.emplace(std::piecewise_construct, std::forward_as_tuple(Scope),
529 std::forward_as_tuple(LowPC, HighPC - LowPC));
530 }
532 LVPublicNames::iterator Iter = PublicNames.find(Scope);
533 return (Iter != PublicNames.end()) ? Iter->second : NameNone;
534 }
535 const LVPublicNames &getPublicNames() const { return PublicNames; }
536
537 // The base address of the scope for any of the debugging information
538 // entries listed, is given by either the DW_AT_low_pc attribute or the
539 // first address in the first range entry in the list of ranges given by
540 // the DW_AT_ranges attribute.
542 return Ranges ? Ranges->front()->getLowerAddress() : 0;
543 }
544
546 return getStringPool().getString(CompilationDirectoryIndex);
547 }
548 void setCompilationDirectory(StringRef CompilationDirectory) {
549 CompilationDirectoryIndex = getStringPool().getIndex(CompilationDirectory);
550 }
551
552 StringRef getFilename(size_t Index) const;
554 Filenames.push_back(getStringPool().getIndex(Name));
555 }
556
557 StringRef getProducer() const override {
558 return getStringPool().getString(ProducerIndex);
559 }
560 void setProducer(StringRef ProducerName) override {
561 ProducerIndex = getStringPool().getIndex(ProducerName);
562 }
563
564 LVSourceLanguage getSourceLanguage() const override { return SourceLanguage; }
565 void setSourceLanguage(LVSourceLanguage SL) override { SourceLanguage = SL; }
566
567 void setCPUType(codeview::CPUType Type) { CompilationCPUType = Type; }
568 codeview::CPUType getCPUType() { return CompilationCPUType; }
569
570 // Record DWARF tags.
571 void addDebugTag(dwarf::Tag Target, LVOffset Offset);
572 // Record elements with invalid offsets.
573 void addInvalidOffset(LVOffset Offset, LVElement *Element);
574 // Record symbols with invalid coverage values.
575 void addInvalidCoverage(LVSymbol *Symbol);
576 // Record symbols with invalid locations.
577 void addInvalidLocation(LVLocation *Location);
578 // Record scopes with invalid ranges.
579 void addInvalidRange(LVLocation *Location);
580 // Record line zero.
581 void addLineZero(LVLine *Line);
582
583 const LVTagOffsetsMap &getDebugTags() const { return DebugTags; }
584 const LVOffsetElementMap &getWarningOffsets() const { return WarningOffsets; }
586 return InvalidLocations;
587 }
589 return InvalidCoverages;
590 }
591 const LVOffsetLocationsMap &getInvalidRanges() const { return InvalidRanges; }
592 const LVOffsetLinesMap &getLinesZero() const { return LinesZero; }
593
594 // Process ranges, locations and calculate coverage.
595 void processRangeLocationCoverage(
597
598 // Add matched element.
599 void addMatched(LVElement *Element) { MatchedElements.push_back(Element); }
600 void addMatched(LVScope *Scope) { MatchedScopes.push_back(Scope); }
601 void propagatePatternMatch();
602
603 const LVElements &getMatchedElements() const { return MatchedElements; }
604 const LVScopes &getMatchedScopes() const { return MatchedScopes; }
605
606 void printLocalNames(raw_ostream &OS, bool Full = true) const;
607 void printSummary(raw_ostream &OS, const LVCounter &Counter,
608 const char *Header) const;
609
610 void incrementPrintedLines();
611 void incrementPrintedScopes();
612 void incrementPrintedSymbols();
613 void incrementPrintedTypes();
614
615 // Values are used by '--summary' option (allocated).
616 void increment(LVLine *Line);
617 void increment(LVScope *Scope);
618 void increment(LVSymbol *Symbol);
619 void increment(LVType *Type);
620
621 // A new element has been added to the scopes tree. Take the following steps:
622 // Increase the added element counters, for printing summary.
623 // During comparison notify the Reader of the new element.
624 void addedElement(LVLine *Line);
625 void addedElement(LVScope *Scope);
626 void addedElement(LVSymbol *Symbol);
627 void addedElement(LVType *Type);
628
629 void addSize(LVScope *Scope, LVOffset Lower, LVOffset Upper);
630
631 // Returns true if current scope is logically equal to the given 'Scope'.
632 bool equals(const LVScope *Scope) const override;
633
634 void print(raw_ostream &OS, bool Full = true) const override;
635 void printExtra(raw_ostream &OS, bool Full = true) const override;
636 void printWarnings(raw_ostream &OS, bool Full = true) const override;
637 void printMatchedElements(raw_ostream &OS, bool UseMatchedElements) override;
638};
639
640// Class to represent a DWARF enumerator (DW_TAG_enumeration_type).
641class LLVM_ABI LVScopeEnumeration final : public LVScope {
642public:
643 LVScopeEnumeration() : LVScope() { setIsEnumeration(); }
647
648 // Returns true if current scope is logically equal to the given 'Scope'.
649 bool equals(const LVScope *Scope) const override;
650
651 void printExtra(raw_ostream &OS, bool Full = true) const override;
652};
653
654// Class to represent a DWARF formal parameter pack
655// (DW_TAG_GNU_formal_parameter_pack).
656class LLVM_ABI LVScopeFormalPack final : public LVScope {
657public:
658 LVScopeFormalPack() : LVScope() { setIsTemplatePack(); }
662
663 // Returns true if current scope is logically equal to the given 'Scope'.
664 bool equals(const LVScope *Scope) const override;
665
666 void printExtra(raw_ostream &OS, bool Full = true) const override;
667};
668
669// Class to represent a DWARF Function.
671 LVScope *Reference = nullptr; // DW_AT_specification, DW_AT_abstract_origin.
672 size_t LinkageNameIndex = 0; // Function DW_AT_linkage_name attribute.
673 size_t EncodedArgsIndex = 0; // Template encoded arguments.
674
675public:
679 virtual ~LVScopeFunction() = default;
680
681 // DW_AT_specification, DW_AT_abstract_origin.
682 LVScope *getReference() const override { return Reference; }
683 void setReference(LVScope *Scope) override {
684 Reference = Scope;
685 setHasReference();
686 }
688 setReference(static_cast<LVScope *>(Element));
689 }
690
691 StringRef getEncodedArgs() const override {
692 return getStringPool().getString(EncodedArgsIndex);
693 }
694 void setEncodedArgs(StringRef EncodedArgs) override {
695 EncodedArgsIndex = getStringPool().getIndex(EncodedArgs);
696 }
697
699 LinkageNameIndex = getStringPool().getIndex(LinkageName);
700 }
701 StringRef getLinkageName() const override {
702 return getStringPool().getString(LinkageNameIndex);
703 }
704 size_t getLinkageNameIndex() const override { return LinkageNameIndex; }
705
706 void setName(StringRef ObjectName) override;
707
708 void resolveExtra() override;
709 void resolveReferences() override;
710
711 // Returns true if current scope is logically equal to the given 'Scope'.
712 bool equals(const LVScope *Scope) const override;
713
714 // For the given 'Scopes' returns a scope that is logically equal
715 // to the current scope; otherwise 'nullptr'.
716 LVScope *findEqualScope(const LVScopes *Scopes) const override;
717
718 void printExtra(raw_ostream &OS, bool Full = true) const override;
719};
720
721// Class to represent a DWARF inlined function.
723 size_t CallFilenameIndex = 0;
724 uint32_t CallLineNumber = 0;
725 uint32_t Discriminator = 0;
726
727public:
728 LVScopeFunctionInlined() : LVScopeFunction() { setIsInlinedFunction(); }
732
733 uint32_t getDiscriminator() const override { return Discriminator; }
735 Discriminator = Value;
736 setHasDiscriminator();
737 }
738
739 uint32_t getCallLineNumber() const override { return CallLineNumber; }
740 void setCallLineNumber(uint32_t Number) override { CallLineNumber = Number; }
741 size_t getCallFilenameIndex() const override { return CallFilenameIndex; }
742 void setCallFilenameIndex(size_t Index) override {
743 CallFilenameIndex = Index;
744 }
745
746 // Line number for display; in the case of Inlined Functions, we use the
747 // DW_AT_call_line attribute; otherwise use DW_AT_decl_line attribute.
748 std::string lineNumberAsString(bool ShowZero = false) const override {
749 return lineAsString(getCallLineNumber(), getDiscriminator(), ShowZero);
750 }
751
752 void resolveExtra() override;
753
754 // Returns true if current scope is logically equal to the given 'Scope'.
755 bool equals(const LVScope *Scope) const override;
756
757 // For the given 'Scopes' returns a scope that is logically equal
758 // to the current scope; otherwise 'nullptr'.
759 LVScope *findEqualScope(const LVScopes *Scopes) const override;
760
761 void printExtra(raw_ostream &OS, bool Full = true) const override;
762};
763
764// Class to represent a DWARF subroutine type.
766public:
767 LVScopeFunctionType() : LVScopeFunction() { setIsFunctionType(); }
771
772 void resolveExtra() override;
773};
774
775// Class to represent a DWARF Module.
776class LLVM_ABI LVScopeModule final : public LVScope {
777public:
779 setIsModule();
780 setIsLexicalBlock();
781 }
782 LVScopeModule(const LVScopeModule &) = delete;
784 ~LVScopeModule() = default;
785
786 // Returns true if current scope is logically equal to the given 'Scope'.
787 bool equals(const LVScope *Scope) const override;
788
789 void printExtra(raw_ostream &OS, bool Full = true) const override;
790};
791
792// Class to represent a DWARF Namespace.
793class LLVM_ABI LVScopeNamespace final : public LVScope {
794 LVScope *Reference = nullptr; // Reference to DW_AT_extension attribute.
795
796public:
797 LVScopeNamespace() : LVScope() { setIsNamespace(); }
800 ~LVScopeNamespace() = default;
801
802 // Access DW_AT_extension reference.
803 LVScope *getReference() const override { return Reference; }
804 void setReference(LVScope *Scope) override {
805 Reference = Scope;
806 setHasReference();
807 }
809 setReference(static_cast<LVScope *>(Element));
810 }
811
812 // Returns true if current scope is logically equal to the given 'Scope'.
813 bool equals(const LVScope *Scope) const override;
814
815 // For the given 'Scopes' returns a scope that is logically equal
816 // to the current scope; otherwise 'nullptr'.
817 LVScope *findEqualScope(const LVScopes *Scopes) const override;
818
819 void printExtra(raw_ostream &OS, bool Full = true) const override;
820};
821
822// Class to represent the binary file being analyzed.
823class LLVM_ABI LVScopeRoot final : public LVScope {
824 size_t FileFormatNameIndex = 0;
825
826public:
827 LVScopeRoot() : LVScope() { setIsRoot(); }
828 LVScopeRoot(const LVScopeRoot &) = delete;
830 ~LVScopeRoot() = default;
831
833 return getStringPool().getString(FileFormatNameIndex);
834 }
835 void setFileFormatName(StringRef FileFormatName) {
836 FileFormatNameIndex = getStringPool().getIndex(FileFormatName);
837 }
838
839 // The CodeView Reader uses scoped names. Recursively transform the
840 // element name to use just the most inner component.
841 void transformScopedName();
842
843 // Process the collected location, ranges and calculate coverage.
844 void processRangeInformation();
845
846 // Returns true if current scope is logically equal to the given 'Scope'.
847 bool equals(const LVScope *Scope) const override;
848
849 void print(raw_ostream &OS, bool Full = true) const override;
850 void printExtra(raw_ostream &OS, bool Full = true) const override;
851 Error doPrintMatches(bool Split, raw_ostream &OS,
852 bool UseMatchedElements) const;
853};
854
855// Class to represent a DWARF template parameter pack
856// (DW_TAG_GNU_template_parameter_pack).
858public:
859 LVScopeTemplatePack() : LVScope() { setIsTemplatePack(); }
863
864 // Returns true if current scope is logically equal to the given 'Scope'.
865 bool equals(const LVScope *Scope) const override;
866
867 void printExtra(raw_ostream &OS, bool Full = true) const override;
868};
869
870} // end namespace logicalview
871} // end namespace llvm
872
873#endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSCOPE_H
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
#define LLVM_ABI
Definition Compiler.h:213
static SmallString< 128 > getFilename(const DIScope *SP)
Extract a filename for a DIScope.
This file contains some templates that are useful if you are working with the STL at all.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Pass interface - Implemented by all 'passes'.
Definition Pass.h:99
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
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
LLVM Value Representation.
Definition Value.h:75
virtual LVScope * getCompileUnitParent() const
LVElement(LVSubclassID ID)
Definition LVElement.h:141
static bool calculateCoverage(LVLocations *Locations, unsigned &Factor, float &Percentage)
std::string lineAsString(uint32_t LineNumber, LVHalf Discriminator, bool ShowZero) const
Definition LVObject.cpp:50
LVScopeAggregate & operator=(const LVScopeAggregate &)=delete
void setEncodedArgs(StringRef EncodedArgs) override
Definition LVScope.h:367
StringRef getEncodedArgs() const override
Definition LVScope.h:364
void setReference(LVScope *Scope) override
Definition LVScope.h:356
LVScope * getReference() const override
Definition LVScope.h:355
LVScopeAggregate(const LVScopeAggregate &)=delete
void setReference(LVElement *Element) override
Definition LVScope.h:360
LVScopeAlias(const LVScopeAlias &)=delete
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1075
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1081
LVScopeAlias & operator=(const LVScopeAlias &)=delete
LVScopeArray(const LVScopeArray &)=delete
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1161
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1176
LVScopeArray & operator=(const LVScopeArray &)=delete
const LVScopes & getMatchedScopes() const
Definition LVScope.h:604
static constexpr LVNameInfo NameNone
Definition LVScope.h:526
void printSummary(raw_ostream &OS) const override
Definition LVScope.cpp:1601
const LVOffsetElementMap & getWarningOffsets() const
Definition LVScope.h:584
void addFilename(StringRef Name)
Definition LVScope.h:553
void setProducer(StringRef ProducerName) override
Definition LVScope.h:560
LVSourceLanguage getSourceLanguage() const override
Definition LVScope.h:564
void addMatched(LVElement *Element)
Definition LVScope.h:599
LVScopeCompileUnit & operator=(const LVScopeCompileUnit &)=delete
const LVOffsetLocationsMap & getInvalidRanges() const
Definition LVScope.h:591
const LVTagOffsetsMap & getDebugTags() const
Definition LVScope.h:583
LVScopeCompileUnit(const LVScopeCompileUnit &)=delete
void addMatched(LVScope *Scope)
Definition LVScope.h:600
const LVOffsetSymbolMap & getInvalidCoverages() const
Definition LVScope.h:588
const LVPublicNames & getPublicNames() const
Definition LVScope.h:535
void setCPUType(codeview::CPUType Type)
Definition LVScope.h:567
void addInvalidOffset(LVOffset Offset, LVElement *Element)
Definition LVScope.cpp:1356
void setCompilationDirectory(StringRef CompilationDirectory)
Definition LVScope.h:548
const LVElements & getMatchedElements() const
Definition LVScope.h:603
const LVOffsetLinesMap & getLinesZero() const
Definition LVScope.h:592
StringRef getCompilationDirectory() const
Definition LVScope.h:545
void addPublicName(LVScope *Scope, LVAddress LowPC, LVAddress HighPC)
Definition LVScope.h:527
const LVOffsetLocationsMap & getInvalidLocations() const
Definition LVScope.h:585
void printSizes(raw_ostream &OS) const override
Definition LVScope.cpp:1557
StringRef getProducer() const override
Definition LVScope.h:557
const LVNameInfo & findPublicName(LVScope *Scope)
Definition LVScope.h:531
void setSourceLanguage(LVSourceLanguage SL) override
Definition LVScope.h:565
LVScope * getCompileUnitParent() const override
Definition LVScope.h:518
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1747
LVScopeEnumeration(const LVScopeEnumeration &)=delete
LVScopeEnumeration & operator=(const LVScopeEnumeration &)=delete
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1741
LVScopeFormalPack(const LVScopeFormalPack &)=delete
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1766
LVScopeFormalPack & operator=(const LVScopeFormalPack &)=delete
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1760
LVScopeFunctionInlined(const LVScopeFunctionInlined &)=delete
void setDiscriminator(uint32_t Value) override
Definition LVScope.h:734
LVScopeFunctionInlined & operator=(const LVScopeFunctionInlined &)=delete
uint32_t getCallLineNumber() const override
Definition LVScope.h:739
void setCallLineNumber(uint32_t Number) override
Definition LVScope.h:740
uint32_t getDiscriminator() const override
Definition LVScope.h:733
std::string lineNumberAsString(bool ShowZero=false) const override
Definition LVScope.h:748
size_t getCallFilenameIndex() const override
Definition LVScope.h:741
void setCallFilenameIndex(size_t Index) override
Definition LVScope.h:742
LVScopeFunctionType(const LVScopeFunctionType &)=delete
LVScopeFunctionType & operator=(const LVScopeFunctionType &)=delete
void setLinkageName(StringRef LinkageName) override
Definition LVScope.h:698
LVScope * getReference() const override
Definition LVScope.h:682
void setEncodedArgs(StringRef EncodedArgs) override
Definition LVScope.h:694
size_t getLinkageNameIndex() const override
Definition LVScope.h:704
LVScopeFunction(const LVScopeFunction &)=delete
void setReference(LVScope *Scope) override
Definition LVScope.h:683
StringRef getEncodedArgs() const override
Definition LVScope.h:691
LVScopeFunction & operator=(const LVScopeFunction &)=delete
StringRef getLinkageName() const override
Definition LVScope.h:701
void setReference(LVElement *Element) override
Definition LVScope.h:687
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:1983
LVScopeModule & operator=(const LVScopeModule &)=delete
LVScopeModule(const LVScopeModule &)=delete
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:1978
LVScopeNamespace & operator=(const LVScopeNamespace &)=delete
LVScopeNamespace(const LVScopeNamespace &)=delete
LVScope * getReference() const override
Definition LVScope.h:803
void setReference(LVScope *Scope) override
Definition LVScope.h:804
void setReference(LVElement *Element) override
Definition LVScope.h:808
LVScopeRoot & operator=(const LVScopeRoot &)=delete
StringRef getFileFormatName() const
Definition LVScope.h:832
void setFileFormatName(StringRef FileFormatName)
Definition LVScope.h:835
LVScopeRoot(const LVScopeRoot &)=delete
void printExtra(raw_ostream &OS, bool Full=true) const override
Definition LVScope.cpp:2131
bool equals(const LVScope *Scope) const override
Definition LVScope.cpp:2125
LVScopeTemplatePack(const LVScopeTemplatePack &)=delete
LVScopeTemplatePack & operator=(const LVScopeTemplatePack &)=delete
virtual LVScope * getReference() const
Definition LVScope.h:278
LVScope & operator=(const LVScope &)=delete
static LVScopeDispatch & getDispatch()
Definition LVScope.h:335
const LVLines * getLines() const
Definition LVScope.h:209
virtual void printSummary(raw_ostream &OS) const
Definition LVScope.h:143
PROPERTY(Property, CanHaveLines)
KIND_2(LVScopeKind, IsBlock, CanHaveRanges, CanHaveLines)
KIND_1(LVScopeKind, IsLexicalBlock, IsBlock)
bool isCompileUnit() const override
Definition LVScope.h:203
KIND(LVScopeKind, IsEnumeration)
static bool classof(const LVElement *Element)
Definition LVScope.h:158
KIND(LVScopeKind, IsTemplatePack)
virtual ~LVScope()=default
PROPERTY(Property, HasLines)
PROPERTY(Property, HasTypes)
const LVScopes * getScopes() const
Definition LVScope.h:211
KIND_1(LVScopeKind, IsSubprogram, IsFunction)
LVElementsView getChildren() const
Definition LVScope.h:221
PROPERTY(Property, HasDiscriminator)
PROPERTY(Property, HasLocals)
PROPERTY(Property, HasGlobals)
void printActiveRanges(raw_ostream &OS, bool Full=true) const
Definition LVScope.cpp:986
size_t scopeCount() const
Definition LVScope.h:252
KIND_1(LVScopeKind, IsCallSite, IsFunction)
size_t lineCount() const
Definition LVScope.h:250
const LVSymbols * getSymbols() const
Definition LVScope.h:212
KIND(LVScopeKind, IsTemplate)
PROPERTY(Property, HasSymbols)
virtual void printMatchedElements(raw_ostream &OS, bool UseMatchedElements)
Definition LVScope.h:340
PROPERTY(Property, CanHaveRanges)
virtual void setEncodedArgs(StringRef EncodedArgs)
Definition LVScope.h:147
void printEncodedArgs(raw_ostream &OS, bool Full) const
Definition LVScope.cpp:994
PROPERTY(Property, IsComdat)
bool isRoot() const override
Definition LVScope.h:204
KIND(LVScopeKind, IsNamespace)
PROPERTY(Property, AddedMissing)
KIND(LVScopeKind, IsTemplateAlias)
PROPERTY(Property, HasScopes)
KIND_3(LVScopeKind, IsCompileUnit, CanHaveRanges, CanHaveLines, TransformName)
std::unique_ptr< LVLocations > Ranges
Definition LVScope.h:135
KIND_1(LVScopeKind, IsUnion, IsAggregate)
KIND(LVScopeKind, IsMember)
std::unique_ptr< LVSymbols > Symbols
Definition LVScope.h:132
const LVTypes * getTypes() const
Definition LVScope.h:213
KIND_1(LVScopeKind, IsCatchBlock, IsBlock)
LVScope * getCompileUnitParent() const override
Definition LVScope.h:280
KIND_1(LVScopeKind, IsTryBlock, IsBlock)
KIND_2(LVScopeKind, IsModule, CanHaveRanges, CanHaveLines)
virtual void printSizes(raw_ostream &OS) const
Definition LVScope.h:142
std::unique_ptr< LVTypes > Types
Definition LVScope.h:131
LVScope(const LVScope &)=delete
uint32_t getBitSize() const override
Definition LVScope.h:291
KIND_1(LVScopeKind, IsStructure, IsAggregate)
virtual StringRef getEncodedArgs() const
Definition LVScope.h:146
std::unique_ptr< LVLines > Lines
Definition LVScope.h:134
KIND(LVScopeKind, IsAggregate)
unsigned getCoverageFactor() const
Definition LVScope.h:266
KIND_1(LVScopeKind, IsLabel, IsFunction)
void setBitSize(uint32_t Size) override
Definition LVScope.h:292
virtual void printWarnings(raw_ostream &OS, bool Full=true) const
Definition LVScope.h:339
KIND_1(LVScopeKind, IsFunctionType, IsFunction)
std::unique_ptr< LVScopes > Scopes
Definition LVScope.h:133
const LVLocations * getRanges() const
Definition LVScope.h:210
size_t typeCount() const
Definition LVScope.h:254
PROPERTY(Property, HasComdatScopes)
KIND_1(LVScopeKind, IsRoot, TransformName)
KIND_1(LVScopeKind, IsClass, IsAggregate)
PROPERTY(Property, HasRanges)
KIND(LVScopeKind, IsArray)
size_t symbolCount() const
Definition LVScope.h:253
KIND_1(LVScopeKind, IsEntryPoint, IsFunction)
size_t rangeCount() const
Definition LVScope.h:251
KIND_2(LVScopeKind, IsFunction, CanHaveRanges, CanHaveLines)
KIND_2(LVScopeKind, IsInlinedFunction, IsFunction, IsInlined)
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define UINT64_MAX
Definition DataTypes.h:77
CPUType
These values correspond to the CV_CPU_TYPE_e enumeration, and are documented here: https://msdn....
Definition CodeView.h:77
std::pair< LVAddress, uint64_t > LVNameInfo
Definition LVScope.h:31
uint16_t LVLevel
Definition LVObject.h:39
uint64_t LVOffset
Definition LVObject.h:40
std::map< LVOffset, LVElement * > LVOffsetElementMap
Definition LVScope.h:69
LLVM_ABI LVStringPool & getStringPool()
Definition LVSupport.cpp:25
SmallVector< LVElement *, 8 > LVElements
Definition LVObject.h:77
bool(LVScope::*)() const LVScopeGetFunction
Definition LVObject.h:71
std::map< LVOffset, LVLines > LVOffsetLinesMap
Definition LVScope.h:70
std::map< LVOffset, LVLocations > LVOffsetLocationsMap
Definition LVScope.h:71
void addItem(MapType *Map, KeyType Key, ValueType Value)
Definition LVSupport.h:157
SmallVector< LVScope *, 8 > LVScopes
Definition LVObject.h:81
std::map< LVScopeKind, LVScopeGetFunction > LVScopeDispatch
Definition LVScope.h:66
bool(LVLocation::*)() LVValidLocation
Definition LVObject.h:103
LVSortValue(*)(const LVObject *LHS, const LVObject *RHS) LVSortFunction
Definition LVSort.h:35
void(LVScope::*)() LVScopeSetFunction
Definition LVObject.h:70
detail::concat_range< LVElement *const, const LVScopes &, const LVTypes &, const LVSymbols & > LVElementsView
Definition LVObject.h:85
SmallVector< LVSymbol *, 8 > LVSymbols
Definition LVObject.h:82
LLVM_ABI LVSortFunction getSortFunction()
Definition LVSort.cpp:105
std::set< LVScopeKind > LVScopeKindSet
Definition LVScope.h:65
std::map< LVScope *, LVNameInfo > LVPublicNames
Definition LVScope.h:32
std::map< dwarf::Tag, LVOffsets > LVTagOffsetsMap
Definition LVScope.h:73
std::pair< LVLine *, LVLine * > LVLineRange
Definition LVLocation.h:23
uint64_t LVSectionIndex
Definition LVObject.h:36
std::vector< LVScopeGetFunction > LVScopeRequest
Definition LVScope.h:67
SmallVector< LVLine *, 8 > LVLines
Definition LVObject.h:78
uint64_t LVAddress
Definition LVObject.h:37
bool(LVObject::*)() const LVObjectGetFunction
Definition LVObject.h:69
std::map< LVOffset, LVSymbol * > LVOffsetSymbolMap
Definition LVScope.h:72
SmallVector< LVType *, 8 > LVTypes
Definition LVObject.h:83
void(LVObject::*)() LVObjectSetFunction
Definition LVObject.h:68
SmallVector< LVLocation *, 8 > LVLocations
Definition LVObject.h:79
std::map< LVAddress, LVNameInfo > LVPublicAddresses
Definition LVScope.h:33
This is an optimization pass for GlobalISel generic memory operations.
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&...Ranges)
Returns a concatenated range across two or more ranges.
Definition STLExtras.h:1152
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1624
A source language supported by any of the debug info representations.