LLVM: lib/DebugInfo/LogicalView/Core/LVOptions.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
16
17using namespace llvm;
19
20#define DEBUG_TYPE "Options"
21
22
23
24
28
30
31 auto StandardAttributes = [&]() {
32
33 setAttributeStandard();
34
35 setAttributeBase();
36 setAttributeCoverage();
37 setAttributeDirectories();
38 setAttributeDiscriminator();
39 setAttributeFilename();
40 setAttributeFiles();
41 setAttributeFormat();
42 setAttributeLevel();
43 setAttributeProducer();
44 setAttributePublics();
45 setAttributeRange();
46 setAttributeReference();
47 setAttributeZero();
48 };
49
50
51 auto ExtendedAttributes = [&]() {
52
53 setAttributeExtended();
54
55 setAttributeArgument();
56 setAttributeDiscarded();
57 setAttributeEncoded();
58 setAttributeGaps();
59 setAttributeGenerated();
60 setAttributeGlobal();
61 setAttributeInserted();
62 setAttributeLinkage();
63 setAttributeLocal();
64 setAttributeLocation();
65 setAttributeOffset();
66 setAttributePathname();
67 setAttributeQualified();
68 setAttributeQualifier();
69 setAttributeRegister();
70 setAttributeSubrange();
71 setAttributeSystem();
72 setAttributeTypename();
73 };
74
75
76 if (getAttributeStandard())
77 StandardAttributes();
78
79
80 if (getAttributeExtended())
81 ExtendedAttributes();
82
83
84 if (getAttributeAll()) {
85 StandardAttributes();
86 ExtendedAttributes();
87 }
88
89
90 if (getAttributePathname())
91 resetAttributeFilename();
92
93
94 if (!getOutputText() && !getOutputJson())
95 setOutputText();
96
97
98 if (getOutputAll()) {
99 setOutputJson();
100 setOutputSplit();
101 setOutputText();
102 }
103
104
105 if (getOutputFolder().length())
106 setOutputSplit();
107
108
109 if (getOutputSplit())
110 setAttributePathname();
111
112
113 if (getPrintElements()) {
114 setPrintInstructions();
115 setPrintLines();
116 setPrintScopes();
117 setPrintSymbols();
118 setPrintTypes();
119 }
120
121
122 if (getPrintAll()) {
123 setPrintInstructions();
124 setPrintLines();
125 setPrintScopes();
126 setPrintSizes();
127 setPrintSymbols();
128 setPrintSummary();
129 setPrintTypes();
130 setPrintWarnings();
131 }
132
133
134 if (getWarningAll()) {
135 setWarningCoverages();
136 setWarningLines();
137 setWarningLocations();
138 setWarningRanges();
139 }
140
141
142 if (getInternalAll()) {
143 setInternalCmdline();
144 setInternalID();
145 setInternalIntegrity();
146 setInternalNone();
147 setInternalTag();
148 }
149
150
151 if (getCompareAll()) {
152 setCompareLines();
153 setCompareScopes();
154 setCompareSymbols();
155 setCompareTypes();
156 }
157
158
159 if (getCompareLines() || getCompareSymbols() || getCompareTypes())
160 setCompareScopes();
161
162
163 if (getCompareScopes())
164 setCompareExecute();
165
166
167 if (getPrintInstructions() || getPrintLines())
168 setPrintAnyLine();
169
170
171 if (getPrintAnyLine() || getPrintScopes() || getPrintSymbols() ||
172 getPrintTypes())
173 setPrintAnyElement();
174
175
176 if (getPrintSizes() && getPrintSummary())
177 setPrintSizesSummary();
178
179
180 if (getPrintAll() || getPrintAnyElement() || getPrintSizesSummary() ||
181 getPrintWarnings())
182 setPrintExecute();
183
184
185 if (getReportAll()) {
186 setReportChildren();
187 setReportList();
188 setReportParents();
189 setReportView();
190 }
191
192
193 if (getReportView()) {
194 setReportChildren();
195 setReportParents();
196 }
197
198
199 if (getReportParents() || getReportChildren() || getReportView())
200 setReportAnyView();
201
202
203 if (getReportList() || getReportAnyView())
204 setReportExecute();
205
206
207
208
209
210
211
212
213
214 if (getCompareExecute()) {
215 resetPrintExecute();
216 setComparePrint();
218 setAttributeAdded();
219 setAttributeArgument();
220 setAttributeEncoded();
221 setAttributeInserted();
222 setAttributeMissing();
223 setAttributeQualified();
224 }
225
226
227 setPrintFormatting();
228
229
230 if (getAttributeCoverage() || getAttributeGaps() || getAttributeRegister())
231 setAttributeLocation();
232
233
234 if (!getPrintSymbols()) {
235 resetAttributeCoverage();
236 resetAttributeGaps();
237 resetAttributeLocation();
238 resetAttributeRegister();
239 }
240
241
242 if (getAttributeFilename() || getAttributePathname())
243 setAttributeAnySource();
244
245
246 if (getAttributeLocation() || getAttributeRange())
247 setAttributeAnyLocation();
248
249 if (getAttributeRange() || getPrintAnyLine())
250 setGeneralCollectRanges();
251
252 calculateIndentationSize();
253
254
256}
257
258void LVOptions::calculateIndentationSize() {
259#ifndef NDEBUG
260 if (getInternalID()) {
262 IndentationSize += String.length();
263 }
264#endif
265 if (getCompareExecute() && (getAttributeAdded() || getAttributeMissing()))
266 ++IndentationSize;
267 if (getAttributeOffset()) {
269 IndentationSize += String.length();
270 }
271 if (getAttributeLevel()) {
272 std::stringstream Stream;
273 Stream.str(std::string());
274 Stream << "[" << std::setfill('0') << std::setw(3) << 0 << "]";
275 IndentationSize += Stream.tellp();
276 }
277 if (getAttributeGlobal())
278 ++IndentationSize;
279}
280
281
282
284
285 OS << "** Attributes **\n"
286 << "All: " << getAttributeAll() << ", "
287 << "Argument: " << getAttributeArgument() << ", "
288 << "Base: " << getAttributeBase() << ", "
289 << "Coverage: " << getAttributeCoverage() << "\n"
290 << "Directories: " << getAttributeDirectories() << ", "
291 << "Discarded: " << getAttributeDiscarded() << ", "
292 << "Discriminator: " << getAttributeDiscriminator() << ", "
293 << "Encoded: " << getAttributeEncoded() << "\n"
294 << "Extended: " << getAttributeExtended() << ", "
295 << "Filename: " << getAttributeFilename() << ", "
296 << "Files: " << getAttributeFiles() << ", "
297 << "Format: " << getAttributeFormat() << "\n"
298 << "Gaps: " << getAttributeGaps() << ", "
299 << "Generated: " << getAttributeGenerated() << ", "
300 << "Global: " << getAttributeGlobal() << ", "
301 << "Inserted: " << getAttributeInserted() << "\n"
302 << "Level: " << getAttributeLevel() << ", "
303 << "Linkage: " << getAttributeLinkage() << ", "
304 << "Local: " << getAttributeLocal() << ", "
305 << "Location: " << getAttributeLocation() << "\n"
306 << "Offset: " << getAttributeOffset() << ", "
307 << "Pathname: " << getAttributePathname() << ", "
308 << "Producer: " << getAttributeProducer() << ", "
309 << "Publics: " << getAttributePublics() << "\n"
310 << "Qualified: " << getAttributeQualified() << ", "
311 << "Qualifier: " << getAttributeQualifier() << ", "
312 << "Range: " << getAttributeRange() << ", "
313 << "Reference: " << getAttributeReference() << "\n"
314 << "Register: " << getAttributeRegister() << ", "
315 << "Standard: " << getAttributeStandard() << ", "
316 << "Subrange: " << getAttributeSubrange() << ", "
317 << "System: " << getAttributeSystem() << "\n"
318 << "Typename: " << getAttributeTypename() << ", "
319 << "Underlying: " << getAttributeUnderlying() << ", "
320 << "Zero: " << getAttributeZero() << "\n";
321 OS << "Added: " << getAttributeAdded() << ", "
322 << "AnyLocation: " << getAttributeAnyLocation() << ", "
323 << "AnySource: " << getAttributeAnySource() << ", "
324 << "Missing: " << getAttributeMissing() << "\n"
325 << "\n";
326
327
328 OS << "** Compare **\n"
329 << "All: " << getCompareAll() << ", "
330 << "Lines: " << getCompareLines() << ", "
331 << "Scopes: " << getCompareScopes() << ", "
332 << "Symbols: " << getCompareSymbols() << ", "
333 << "Types: " << getCompareTypes() << "\n";
334 OS << "Context: " << getCompareContext() << ", "
335 << "Execute: " << getCompareExecute() << ", "
336 << "Print: " << getComparePrint() << "\n"
337 << "\n";
338
339
340 OS << "** Print **\n"
341 << "All: " << getPrintAll() << ", "
342 << "Elements: " << getPrintElements() << ", "
343 << "Instructions: " << getPrintInstructions() << ", "
344 << "Lines: " << getPrintLines() << "\n"
345 << "Scopes: " << getPrintScopes() << ", "
346 << "Sizes: " << getPrintSizes() << ", "
347 << "Summary: " << getPrintSummary() << ", "
348 << "Symbols: " << getPrintSymbols() << "\n"
349 << "Types: " << getPrintTypes() << ", "
350 << "Warnings: " << getPrintWarnings() << "\n";
351 OS << "AnyElemeny: " << getPrintAnyElement() << ", "
352 << "AnyLine: " << getPrintAnyLine() << ", "
353 << "Execute: " << getPrintExecute() << ", "
354 << "Formatting: " << getPrintFormatting() << "\n"
355 << "Offset: " << getPrintOffset() << ", "
356 << "SizesSummary: " << getPrintSizesSummary() << "\n"
357 << "\n";
358
359
360 OS << "** Report **\n"
361 << "All: " << getReportAll() << ", "
362 << "Children: " << getReportChildren() << ", "
363 << "List: " << getReportList() << ", "
364 << "Parents: " << getReportParents() << ", "
365 << "View: " << getReportView() << "\n";
366 OS << "AnyView: " << getReportAnyView() << ", "
367 << "Execute: " << getReportExecute() << "\n"
368 << "\n";
369
370
371 OS << "** Select **\n"
372 << "IgnoreCase: " << getSelectIgnoreCase() << ", "
373 << "UseRegex: " << getSelectUseRegex() << ", "
374 << "Execute: " << getSelectExecute() << ", "
375 << "GenericKind: " << getSelectGenericKind() << "\n"
376 << "GenericPattern: " << getSelectGenericPattern() << ", "
377 << "OffsetPattern: " << getSelectOffsetPattern() << "\n"
378 << "\n";
379
380
381 OS << "** Warning **\n"
382 << "All: " << getWarningAll() << ", "
383 << "Coverage: " << getWarningCoverages() << ", "
384 << "Lines: " << getWarningLines() << ", "
385 << "Locations: " << getWarningLocations() << ", "
386 << "Ranges: " << getWarningRanges() << "\n"
387 << "\n";
388
389
390 OS << "** Internal **\n"
391 << "All: " << Options.getInternalAll() << ", "
392 << "Cmdline: " << Options.getInternalCmdline() << ", "
393 << "ID: " << Options.getInternalID() << ", "
394 << "Integrity: " << Options.getInternalIntegrity() << ", "
395 << "None: " << Options.getInternalNone() << "\n"
396 << "Tag: " << Options.getInternalTag() << "\n"
397 << "\n";
398}
399
400
401
402
405 return &Patterns;
406}
407
409 bool IgnoreCase, bool UseRegex) {
411
412 if (UseRegex) {
417 std::string Error;
420 "Error in regular expression: %s",
422
423 Match.Mode = LVMatchMode::Regex;
424 Filters.push_back(Match);
426 }
427 }
428
429
431 if (Match.Pattern.size()) {
432 Match.Mode = IgnoreCase ? LVMatchMode::NoCase : LVMatchMode::Match;
433 Filters.push_back(Match);
434 }
435
437}
438
441 if (GenericMatchInfo.size()) {
442 options().setSelectGenericPattern();
443 options().setSelectExecute();
444 }
445}
446
448 for (const LVOffset &Entry : Patterns)
449 OffsetMatchInfo.push_back(Entry);
450 if (OffsetMatchInfo.size()) {
451 options().setSelectOffsetPattern();
452 options().setSelectExecute();
453 }
454}
455
457 bool IgnoreCase = options().getSelectIgnoreCase();
458 bool UseRegex = options().getSelectUseRegex();
461 if (Error Err = createMatchEntry(Filters, Pattern, IgnoreCase, UseRegex))
463 }
464
466 dbgs() << "\nPattern Information:\n";
467 for (LVMatch &Match : Filters)
468 dbgs() << "Mode: "
469 << (Match.Mode == LVMatchMode::Match ? "Match" : "Regex")
470 << " Pattern: '" << Match.Pattern << "'\n";
471 });
472}
473
474void LVPatterns::addElement(LVElement *Element) {
475
476 Element->setIsMatched();
477 options().setSelectExecute();
478 if (options().getReportList())
480 if (options().getReportAnyView()) {
482 ? static_cast<LVScope *>(Element)
484
485 if (!Element->getIsScope())
486 Element->setHasPattern();
487 }
488}
489
491 if (ElementRequest.size() || LineRequest.size() || ScopeRequest.size() ||
492 SymbolRequest.size() || TypeRequest.size()) {
493 options().setSelectGenericKind();
494 options().setSelectExecute();
495 }
496
497
498
499 if (options().getSelectExecute() && ().getReportExecute()) {
500 options().setReportExecute();
501 options().setReportList();
502 }
503}
504
505
507 bool Matched = false;
508
509 if (Input.empty())
510 return Matched;
511
512 for (const LVMatch &Match : MatchInfo) {
513 switch (Match.Mode) {
514 case LVMatchMode::Match:
515 Matched = Input == Match.Pattern;
516 break;
517 case LVMatchMode::NoCase:
519 break;
520 case LVMatchMode::Regex:
521 Matched = Match.RE->match(Input);
522 break;
523 default:
524 break;
525 }
526
527 if (Matched)
528 return true;
529 }
530 return Matched;
531}
532
534 return (options().getPrintLines() && Line->getIsLineDebug()) ||
535 (options().getPrintInstructions() && Line->getIsLineAssembler());
536}
537
539 if (options().getAttributeAll())
540 return true;
541 bool DoPrint = options().getAttributeAnyLocation();
542
544 DoPrint = options().getAttributeGaps();
545 return DoPrint;
546}
547
549
550
551
552
553
554 return options().getPrintScopes() ||
555 (options().getPrintSymbols() && Scope->getHasSymbols()) ||
556 (options().getPrintAnyLine() && Scope->getHasLines()) ||
557 (options().getPrintTypes() && Scope->getHasTypes()) ||
558 ((options().getPrintSizesSummary() || options().getPrintWarnings()) &&
559 (Scope->getIsRoot() || Scope->getIsCompileUnit()));
560}
561
563
564 if (Symbol->getIsArtificial())
565 return options().getAttributeGenerated() && options().getPrintSymbols();
566 return options().getPrintSymbols();
567}
568
570
571 if (Type->getIsSubrange())
572 return options().getAttributeSubrange() && options().getPrintTypes();
573 return options().getPrintTypes();
574}
575
577 OS << "LVPatterns\n";
579}
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
@ IgnoreCase
Compile for matching that ignores upper/lower case distinctions.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
StringSet - A wrapper for StringMap that provides set-like functionality.
The instances of the Type class are immutable: once they are created, they are never changed.
LVScope * getParentScope() const
static void setOptions(LVOptions *Options)
void resolveDependencies()
static LVOptions * getOptions()
void print(raw_ostream &OS) const
void setSortMode(LVSortMode SortMode)
void addGenericPatterns(StringSet<> &Patterns)
bool matchPattern(StringRef Input, const LVMatchInfo &MatchInfo)
bool printObject(const LVLocation *Location) const
void print(raw_ostream &OS) const
bool printElement(const LVLine *Line) const
void addPatterns(StringSet<> &Patterns, LVMatchInfo &Filters)
void updateReportOptions()
void addOffsetPatterns(const LVOffsetSet &Patterns)
static LVPatterns * getPatterns()
void addMatched(LVElement *Element)
This class implements an extremely fast bulk output stream that can only output to a stream.
std::set< uint64_t > LVOffsetSet
LVScopeCompileUnit * getReaderCompileUnit()
std::string hexSquareString(uint64_t Value)
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void consumeError(Error Err)
Consume a Error without doing anything.