File indexing completed on 2026-05-10 08:43:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVOPTIONS_H
0015 #define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVOPTIONS_H
0016
0017 #include "llvm/ADT/StringSet.h"
0018 #include "llvm/DebugInfo/LogicalView/Core/LVLine.h"
0019 #include "llvm/DebugInfo/LogicalView/Core/LVScope.h"
0020 #include "llvm/DebugInfo/LogicalView/Core/LVSymbol.h"
0021 #include "llvm/DebugInfo/LogicalView/Core/LVType.h"
0022 #include "llvm/Support/Regex.h"
0023 #include <set>
0024 #include <string>
0025
0026 namespace llvm {
0027 namespace logicalview {
0028
0029
0030 #define BOOL_FUNCTION(FAMILY, FIELD) \
0031 bool get##FAMILY##FIELD() const { return FAMILY.FIELD; } \
0032 void set##FAMILY##FIELD() { FAMILY.FIELD = true; } \
0033 void reset##FAMILY##FIELD() { FAMILY.FIELD = false; }
0034
0035
0036 #define UNSIGNED_FUNCTION(FAMILY, FIELD) \
0037 unsigned get##FAMILY##FIELD() const { return FAMILY.FIELD; } \
0038 void set##FAMILY##FIELD(unsigned Value) { FAMILY.FIELD = Value; } \
0039 void reset##FAMILY##FIELD() { FAMILY.FIELD = -1U; }
0040
0041
0042 #define STD_STRING_FUNCTION(FAMILY, FIELD) \
0043 std::string get##FAMILY##FIELD() const { return FAMILY.FIELD; } \
0044 void set##FAMILY##FIELD(std::string FIELD) { FAMILY.FIELD = FIELD; } \
0045 void reset##FAMILY##FIELD() { FAMILY.FIELD = ""; }
0046
0047
0048 #define STDSET_FUNCTION_4(FAMILY, FIELD, TYPE, SET) \
0049 bool get##FAMILY##FIELD() const { \
0050 return FAMILY.SET.find(TYPE::FIELD) != FAMILY.SET.end(); \
0051 } \
0052 void set##FAMILY##FIELD() { FAMILY.SET.insert(TYPE::FIELD); } \
0053 void reset##FAMILY##FIELD() { \
0054 std::set<TYPE>::iterator Iter = FAMILY.SET.find(TYPE::FIELD); \
0055 if (Iter != FAMILY.SET.end()) \
0056 FAMILY.SET.erase(Iter); \
0057 }
0058
0059 #define STDSET_FUNCTION_5(FAMILY, FIELD, ENTRY, TYPE, SET) \
0060 bool get##FAMILY##FIELD##ENTRY() const { \
0061 return FAMILY.SET.find(TYPE::ENTRY) != FAMILY.SET.end(); \
0062 } \
0063 void set##FAMILY##FIELD##ENTRY() { FAMILY.SET.insert(TYPE::ENTRY); }
0064
0065
0066 #define ATTRIBUTE_OPTION(FIELD) \
0067 STDSET_FUNCTION_4(Attribute, FIELD, LVAttributeKind, Kinds)
0068
0069
0070 #define OUTPUT_OPTION(FIELD) \
0071 STDSET_FUNCTION_4(Output, FIELD, LVOutputKind, Kinds)
0072
0073
0074 #define PRINT_OPTION(FIELD) STDSET_FUNCTION_4(Print, FIELD, LVPrintKind, Kinds)
0075
0076
0077 #define WARNING_OPTION(FIELD) \
0078 STDSET_FUNCTION_4(Warning, FIELD, LVWarningKind, Kinds)
0079
0080
0081 #define COMPARE_OPTION(FIELD) \
0082 STDSET_FUNCTION_4(Compare, FIELD, LVCompareKind, Elements)
0083
0084
0085 #define REPORT_OPTION(FIELD) \
0086 STDSET_FUNCTION_4(Report, FIELD, LVReportKind, Kinds)
0087
0088
0089 #define INTERNAL_OPTION(FIELD) \
0090 STDSET_FUNCTION_4(Internal, FIELD, LVInternalKind, Kinds)
0091
0092 using LVOffsetSet = std::set<uint64_t>;
0093
0094 enum class LVAttributeKind {
0095 All,
0096 Argument,
0097 Base,
0098 Coverage,
0099 Directories,
0100 Discarded,
0101 Discriminator,
0102 Encoded,
0103 Extended,
0104 Filename,
0105 Files,
0106 Format,
0107 Gaps,
0108 Generated,
0109 Global,
0110 Inserted,
0111 Level,
0112 Linkage,
0113 Local,
0114 Location,
0115 Offset,
0116 Pathname,
0117 Producer,
0118 Publics,
0119 Qualified,
0120 Qualifier,
0121 Range,
0122 Reference,
0123 Register,
0124 Standard,
0125 Subrange,
0126 System,
0127 Typename,
0128 Underlying,
0129 Zero
0130 };
0131 using LVAttributeKindSet = std::set<LVAttributeKind>;
0132
0133 enum class LVCompareKind {
0134 All,
0135 Lines,
0136 Scopes,
0137 Symbols,
0138 Types
0139 };
0140 using LVCompareKindSet = std::set<LVCompareKind>;
0141
0142 enum class LVOutputKind {
0143 All,
0144 Split,
0145 Json,
0146 Text
0147 };
0148 using LVOutputKindSet = std::set<LVOutputKind>;
0149
0150 enum class LVPrintKind {
0151 All,
0152 Elements,
0153 Instructions,
0154 Lines,
0155 Scopes,
0156 Sizes,
0157 Symbols,
0158 Summary,
0159 Types,
0160 Warnings
0161 };
0162 using LVPrintKindSet = std::set<LVPrintKind>;
0163
0164 enum class LVReportKind {
0165 All,
0166 Children,
0167 List,
0168 Parents,
0169 View
0170 };
0171 using LVReportKindSet = std::set<LVReportKind>;
0172
0173 enum class LVWarningKind {
0174 All,
0175 Coverages,
0176 Lines,
0177 Locations,
0178 Ranges
0179 };
0180 using LVWarningKindSet = std::set<LVWarningKind>;
0181
0182 enum class LVInternalKind {
0183 All,
0184 Cmdline,
0185 ID,
0186 Integrity,
0187 None,
0188 Tag
0189 };
0190 using LVInternalKindSet = std::set<LVInternalKind>;
0191
0192
0193
0194
0195
0196
0197 class LVOptions {
0198 class LVAttribute {
0199 public:
0200 LVAttributeKindSet Kinds;
0201 bool Added = false;
0202 bool AnyLocation = false;
0203 bool AnySource = false;
0204 bool Missing = false;
0205 };
0206
0207 class LVCompare {
0208 public:
0209 LVCompareKindSet Elements;
0210 bool Context = false;
0211 bool Execute = false;
0212 bool Print = false;
0213 };
0214
0215 class LVPrint {
0216 public:
0217 LVPrintKindSet Kinds;
0218 bool AnyElement = false;
0219 bool AnyLine = false;
0220 bool Execute = false;
0221 bool Formatting = true;
0222 bool Offset = false;
0223 bool SizesSummary = false;
0224 };
0225
0226 class LVReport {
0227 public:
0228 LVReportKindSet Kinds;
0229 bool AnyView = false;
0230 bool Execute = false;
0231 };
0232
0233 class LVSelect {
0234 public:
0235 bool IgnoreCase = false;
0236 bool UseRegex = false;
0237 bool Execute = false;
0238 bool GenericKind = false;
0239 bool GenericPattern = false;
0240 bool OffsetPattern = false;
0241 StringSet<> Generic;
0242 LVOffsetSet Offsets;
0243 LVElementKindSet Elements;
0244 LVLineKindSet Lines;
0245 LVScopeKindSet Scopes;
0246 LVSymbolKindSet Symbols;
0247 LVTypeKindSelection Types;
0248 };
0249
0250 class LVOutput {
0251 public:
0252 LVOutputKindSet Kinds;
0253 LVSortMode SortMode = LVSortMode::None;
0254 std::string Folder;
0255 unsigned Level = -1U;
0256 };
0257
0258 class LVWarning {
0259 public:
0260 LVWarningKindSet Kinds;
0261 };
0262
0263 class LVInternal {
0264 public:
0265 LVInternalKindSet Kinds;
0266 };
0267
0268 class LVGeneral {
0269 public:
0270 bool CollectRanges = false;
0271 };
0272
0273
0274
0275
0276
0277 size_t LastFilenameIndex = 0;
0278
0279
0280
0281 size_t IndentationSize = 0;
0282
0283
0284
0285 void calculateIndentationSize();
0286
0287 public:
0288 void resetFilenameIndex() { LastFilenameIndex = 0; }
0289 bool changeFilenameIndex(size_t Index) {
0290 bool IndexChanged = (Index != LastFilenameIndex);
0291 if (IndexChanged)
0292 LastFilenameIndex = Index;
0293 return IndexChanged;
0294 }
0295
0296
0297 static LVOptions *getOptions();
0298 static void setOptions(LVOptions *Options);
0299
0300 LVOptions() = default;
0301 LVOptions(const LVOptions &) = default;
0302 LVOptions &operator=(const LVOptions &) = default;
0303 ~LVOptions() = default;
0304
0305
0306
0307
0308
0309
0310
0311 void resolveDependencies();
0312 size_t indentationSize() const { return IndentationSize; }
0313
0314 LVAttribute Attribute;
0315 LVCompare Compare;
0316 LVOutput Output;
0317 LVPrint Print;
0318 LVReport Report;
0319 LVSelect Select;
0320 LVWarning Warning;
0321 LVInternal Internal;
0322 LVGeneral General;
0323
0324
0325 ATTRIBUTE_OPTION(All);
0326 ATTRIBUTE_OPTION(Argument);
0327 ATTRIBUTE_OPTION(Base);
0328 ATTRIBUTE_OPTION(Coverage);
0329 ATTRIBUTE_OPTION(Directories);
0330 ATTRIBUTE_OPTION(Discarded);
0331 ATTRIBUTE_OPTION(Discriminator);
0332 ATTRIBUTE_OPTION(Encoded);
0333 ATTRIBUTE_OPTION(Extended);
0334 ATTRIBUTE_OPTION(Filename);
0335 ATTRIBUTE_OPTION(Files);
0336 ATTRIBUTE_OPTION(Format);
0337 ATTRIBUTE_OPTION(Gaps);
0338 ATTRIBUTE_OPTION(Generated);
0339 ATTRIBUTE_OPTION(Global);
0340 ATTRIBUTE_OPTION(Inserted);
0341 ATTRIBUTE_OPTION(Level);
0342 ATTRIBUTE_OPTION(Linkage);
0343 ATTRIBUTE_OPTION(Location);
0344 ATTRIBUTE_OPTION(Local);
0345 ATTRIBUTE_OPTION(Offset);
0346 ATTRIBUTE_OPTION(Pathname);
0347 ATTRIBUTE_OPTION(Producer);
0348 ATTRIBUTE_OPTION(Publics);
0349 ATTRIBUTE_OPTION(Qualified);
0350 ATTRIBUTE_OPTION(Qualifier);
0351 ATTRIBUTE_OPTION(Range);
0352 ATTRIBUTE_OPTION(Reference);
0353 ATTRIBUTE_OPTION(Register);
0354 ATTRIBUTE_OPTION(Standard);
0355 ATTRIBUTE_OPTION(Subrange);
0356 ATTRIBUTE_OPTION(System);
0357 ATTRIBUTE_OPTION(Typename);
0358 ATTRIBUTE_OPTION(Underlying);
0359 ATTRIBUTE_OPTION(Zero);
0360 BOOL_FUNCTION(Attribute, Added);
0361 BOOL_FUNCTION(Attribute, AnyLocation);
0362 BOOL_FUNCTION(Attribute, AnySource);
0363 BOOL_FUNCTION(Attribute, Missing);
0364
0365
0366 COMPARE_OPTION(All);
0367 COMPARE_OPTION(Lines);
0368 COMPARE_OPTION(Scopes);
0369 COMPARE_OPTION(Symbols);
0370 COMPARE_OPTION(Types);
0371 BOOL_FUNCTION(Compare, Context);
0372 BOOL_FUNCTION(Compare, Execute);
0373 BOOL_FUNCTION(Compare, Print);
0374
0375
0376 OUTPUT_OPTION(All);
0377 OUTPUT_OPTION(Split);
0378 OUTPUT_OPTION(Text);
0379 OUTPUT_OPTION(Json);
0380 STD_STRING_FUNCTION(Output, Folder);
0381 UNSIGNED_FUNCTION(Output, Level);
0382 LVSortMode getSortMode() const { return Output.SortMode; }
0383 void setSortMode(LVSortMode SortMode) { Output.SortMode = SortMode; }
0384
0385
0386 PRINT_OPTION(All);
0387 PRINT_OPTION(Elements);
0388 PRINT_OPTION(Instructions);
0389 PRINT_OPTION(Lines);
0390 PRINT_OPTION(Scopes);
0391 PRINT_OPTION(Sizes);
0392 PRINT_OPTION(Symbols);
0393 PRINT_OPTION(Summary);
0394 PRINT_OPTION(Types);
0395 PRINT_OPTION(Warnings);
0396 BOOL_FUNCTION(Print, AnyElement);
0397 BOOL_FUNCTION(Print, AnyLine);
0398 BOOL_FUNCTION(Print, Execute);
0399 BOOL_FUNCTION(Print, Formatting);
0400 BOOL_FUNCTION(Print, Offset);
0401 BOOL_FUNCTION(Print, SizesSummary);
0402
0403
0404 REPORT_OPTION(All);
0405 REPORT_OPTION(Children);
0406 REPORT_OPTION(List);
0407 REPORT_OPTION(Parents);
0408 REPORT_OPTION(View);
0409 BOOL_FUNCTION(Report, AnyView);
0410 BOOL_FUNCTION(Report, Execute);
0411
0412
0413 BOOL_FUNCTION(Select, IgnoreCase);
0414 BOOL_FUNCTION(Select, UseRegex);
0415 BOOL_FUNCTION(Select, Execute);
0416 BOOL_FUNCTION(Select, GenericKind);
0417 BOOL_FUNCTION(Select, GenericPattern);
0418 BOOL_FUNCTION(Select, OffsetPattern);
0419
0420
0421 WARNING_OPTION(All);
0422 WARNING_OPTION(Coverages);
0423 WARNING_OPTION(Lines);
0424 WARNING_OPTION(Locations);
0425 WARNING_OPTION(Ranges);
0426
0427
0428 INTERNAL_OPTION(All);
0429 INTERNAL_OPTION(Cmdline);
0430 INTERNAL_OPTION(ID);
0431 INTERNAL_OPTION(Integrity);
0432 INTERNAL_OPTION(None);
0433 INTERNAL_OPTION(Tag);
0434
0435
0436 BOOL_FUNCTION(General, CollectRanges);
0437
0438 void print(raw_ostream &OS) const;
0439
0440 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0441 void dump() const { print(dbgs()); }
0442 #endif
0443 };
0444
0445 inline LVOptions &options() { return (*LVOptions::getOptions()); }
0446 inline void setOptions(LVOptions *Options) { LVOptions::setOptions(Options); }
0447
0448 class LVPatterns final {
0449
0450 enum class LVMatchMode {
0451 None = 0,
0452 Match,
0453 NoCase,
0454 Regex
0455 };
0456
0457
0458 struct LVMatch {
0459 std::string Pattern;
0460 std::shared_ptr<Regex> RE;
0461 LVMatchMode Mode = LVMatchMode::None;
0462 };
0463
0464 using LVMatchInfo = std::vector<LVMatch>;
0465 LVMatchInfo GenericMatchInfo;
0466 using LVMatchOffsets = std::vector<uint64_t>;
0467 LVMatchOffsets OffsetMatchInfo;
0468
0469
0470 LVElementDispatch ElementDispatch;
0471 LVLineDispatch LineDispatch;
0472 LVScopeDispatch ScopeDispatch;
0473 LVSymbolDispatch SymbolDispatch;
0474 LVTypeDispatch TypeDispatch;
0475
0476
0477 LVElementRequest ElementRequest;
0478 LVLineRequest LineRequest;
0479 LVScopeRequest ScopeRequest;
0480 LVSymbolRequest SymbolRequest;
0481 LVTypeRequest TypeRequest;
0482
0483
0484 template <typename T, typename U>
0485 bool checkElementRequest(const T *Element, const U &Requests) const {
0486 assert(Element && "Element must not be nullptr");
0487 for (const auto &Request : Requests)
0488 if ((Element->*Request)())
0489 return true;
0490
0491 for (const LVElementGetFunction &Request : ElementRequest)
0492 if ((Element->*Request)())
0493 return true;
0494 return false;
0495 }
0496
0497
0498 template <typename T, typename U, typename V>
0499 void addRequest(const T &Selection, const U &Dispatch, V &Request) const {
0500 for (const auto &Entry : Selection) {
0501
0502 typename U::const_iterator Iter = Dispatch.find(Entry);
0503 if (Iter != Dispatch.end())
0504 Request.push_back(Iter->second);
0505 }
0506 }
0507
0508 void addElement(LVElement *Element);
0509
0510 template <typename T, typename U>
0511 void resolveGenericPatternMatch(T *Element, const U &Requests) {
0512 assert(Element && "Element must not be nullptr");
0513 auto CheckPattern = [this, Element]() -> bool {
0514 return (Element->isNamed() &&
0515 (matchGenericPattern(Element->getName()) ||
0516 matchGenericPattern(Element->getLinkageName()))) ||
0517 (Element->isTyped() &&
0518 matchGenericPattern(Element->getTypeName()));
0519 };
0520 auto CheckOffset = [this, Element]() -> bool {
0521 return matchOffsetPattern(Element->getOffset());
0522 };
0523 if ((options().getSelectGenericPattern() && CheckPattern()) ||
0524 (options().getSelectOffsetPattern() && CheckOffset()) ||
0525 ((Requests.size() || ElementRequest.size()) &&
0526 checkElementRequest(Element, Requests)))
0527 addElement(Element);
0528 }
0529
0530 template <typename U>
0531 void resolveGenericPatternMatch(LVLine *Line, const U &Requests) {
0532 assert(Line && "Line must not be nullptr");
0533 auto CheckPattern = [this, Line]() -> bool {
0534 return matchGenericPattern(Line->lineNumberAsStringStripped()) ||
0535 matchGenericPattern(Line->getName()) ||
0536 matchGenericPattern(Line->getPathname());
0537 };
0538 auto CheckOffset = [this, Line]() -> bool {
0539 return matchOffsetPattern(Line->getAddress());
0540 };
0541 if ((options().getSelectGenericPattern() && CheckPattern()) ||
0542 (options().getSelectOffsetPattern() && CheckOffset()) ||
0543 (Requests.size() && checkElementRequest(Line, Requests)))
0544 addElement(Line);
0545 }
0546
0547 Error createMatchEntry(LVMatchInfo &Filters, StringRef Pattern,
0548 bool IgnoreCase, bool UseRegex);
0549
0550 public:
0551 static LVPatterns *getPatterns();
0552
0553 LVPatterns() {
0554 ElementDispatch = LVElement::getDispatch();
0555 LineDispatch = LVLine::getDispatch();
0556 ScopeDispatch = LVScope::getDispatch();
0557 SymbolDispatch = LVSymbol::getDispatch();
0558 TypeDispatch = LVType::getDispatch();
0559 }
0560 LVPatterns(const LVPatterns &) = delete;
0561 LVPatterns &operator=(const LVPatterns &) = delete;
0562 ~LVPatterns() = default;
0563
0564
0565 void clear() {
0566 GenericMatchInfo.clear();
0567 OffsetMatchInfo.clear();
0568 ElementRequest.clear();
0569 LineRequest.clear();
0570 ScopeRequest.clear();
0571 SymbolRequest.clear();
0572 TypeRequest.clear();
0573
0574 options().resetSelectGenericKind();
0575 options().resetSelectGenericPattern();
0576 options().resetSelectOffsetPattern();
0577 }
0578
0579 void addRequest(LVElementKindSet &Selection) {
0580 addRequest(Selection, ElementDispatch, ElementRequest);
0581 }
0582 void addRequest(LVLineKindSet &Selection) {
0583 addRequest(Selection, LineDispatch, LineRequest);
0584 }
0585 void addRequest(LVScopeKindSet &Selection) {
0586 addRequest(Selection, ScopeDispatch, ScopeRequest);
0587 }
0588 void addRequest(LVSymbolKindSet &Selection) {
0589 addRequest(Selection, SymbolDispatch, SymbolRequest);
0590 }
0591 void addRequest(LVTypeKindSelection &Selection) {
0592 addRequest(Selection, TypeDispatch, TypeRequest);
0593 }
0594
0595 void updateReportOptions();
0596
0597 bool matchPattern(StringRef Input, const LVMatchInfo &MatchInfo);
0598
0599 bool matchGenericPattern(StringRef Input) {
0600 return matchPattern(Input, GenericMatchInfo);
0601 }
0602 bool matchOffsetPattern(LVOffset Offset) {
0603 return llvm::is_contained(OffsetMatchInfo, Offset);
0604 }
0605
0606 void resolvePatternMatch(LVLine *Line) {
0607 resolveGenericPatternMatch(Line, LineRequest);
0608 }
0609
0610 void resolvePatternMatch(LVScope *Scope) {
0611 resolveGenericPatternMatch(Scope, ScopeRequest);
0612 }
0613
0614 void resolvePatternMatch(LVSymbol *Symbol) {
0615 resolveGenericPatternMatch(Symbol, SymbolRequest);
0616 }
0617
0618 void resolvePatternMatch(LVType *Type) {
0619 resolveGenericPatternMatch(Type, TypeRequest);
0620 }
0621
0622 void addPatterns(StringSet<> &Patterns, LVMatchInfo &Filters);
0623
0624
0625 void addGenericPatterns(StringSet<> &Patterns);
0626 void addOffsetPatterns(const LVOffsetSet &Patterns);
0627
0628
0629 bool printElement(const LVLine *Line) const;
0630 bool printObject(const LVLocation *Location) const;
0631 bool printElement(const LVScope *Scope) const;
0632 bool printElement(const LVSymbol *Symbol) const;
0633 bool printElement(const LVType *Type) const;
0634
0635 void print(raw_ostream &OS) const;
0636
0637 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0638 void dump() const { print(dbgs()); }
0639 #endif
0640 };
0641
0642 inline LVPatterns &patterns() { return *LVPatterns::getPatterns(); }
0643
0644 }
0645 }
0646
0647 #endif