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