Path: blob/main/contrib/llvm-project/llvm/tools/llvm-debuginfo-analyzer/Options.cpp
35231 views
//===-- options.cpp - Command line options for llvm-debuginfo-analyzer----===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This handles the command line options for llvm-debuginfo-analyzer.9//10//===----------------------------------------------------------------------===//1112#include "Options.h"13#include "llvm/DebugInfo/LogicalView/Core/LVOptions.h"14#include "llvm/DebugInfo/LogicalView/Core/LVSort.h"15#include "llvm/Support/CommandLine.h"1617using namespace llvm;18using namespace llvm::logicalview;19using namespace llvm::logicalview::cmdline;2021/// @}22/// Command line options.23/// @{2425OffsetParser::OffsetParser(cl::Option &O) : parser<unsigned long long>(O) {}26OffsetParser::~OffsetParser() = default;2728bool OffsetParser::parse(cl::Option &O, StringRef ArgName, StringRef Arg,29unsigned long long &Val) {30char *End;31std::string Argument(Arg);32Val = strtoull(Argument.c_str(), &End, 0);33if (*End)34// Print an error message if unrecognized character.35return O.error("'" + Arg + "' unrecognized character.");36return false;37}3839LVOptions cmdline::ReaderOptions;4041//===----------------------------------------------------------------------===//42// Specific options43//===----------------------------------------------------------------------===//44cl::list<std::string>45cmdline::InputFilenames(cl::desc("<input object files or .dSYM bundles>"),46cl::Positional, cl::ZeroOrMore);4748//===----------------------------------------------------------------------===//49// '--attribute' options50//===----------------------------------------------------------------------===//51cl::OptionCategory52cmdline::AttributeCategory("Attribute Options",53"These control extra attributes that are "54"added when the element is printed.");5556// --attribute=<value>[,<value>,...]57cl::list<LVAttributeKind> cmdline::AttributeOptions(58"attribute", cl::cat(AttributeCategory), cl::desc("Element attributes."),59cl::Hidden, cl::CommaSeparated,60values(clEnumValN(LVAttributeKind::All, "all", "Include all attributes."),61clEnumValN(LVAttributeKind::Argument, "argument",62"Template parameters replaced by its arguments."),63clEnumValN(LVAttributeKind::Base, "base",64"Base types (int, bool, etc.)."),65clEnumValN(LVAttributeKind::Coverage, "coverage",66"Symbol location coverage."),67clEnumValN(LVAttributeKind::Directories, "directories",68"Directories referenced in the debug information."),69clEnumValN(LVAttributeKind::Discarded, "discarded",70"Discarded elements by the linker."),71clEnumValN(LVAttributeKind::Discriminator, "discriminator",72"Discriminators for inlined function instances."),73clEnumValN(LVAttributeKind::Encoded, "encoded",74"Template arguments encoded in the template name."),75clEnumValN(LVAttributeKind::Extended, "extended",76"Advanced attributes alias."),77clEnumValN(LVAttributeKind::Filename, "filename",78"Filename where the element is defined."),79clEnumValN(LVAttributeKind::Files, "files",80"Files referenced in the debug information."),81clEnumValN(LVAttributeKind::Format, "format",82"Object file format name."),83clEnumValN(LVAttributeKind::Gaps, "gaps",84"Missing debug location (gaps)."),85clEnumValN(LVAttributeKind::Generated, "generated",86"Compiler generated elements."),87clEnumValN(LVAttributeKind::Global, "global",88"Element referenced across Compile Units."),89clEnumValN(LVAttributeKind::Inserted, "inserted",90"Generated inlined abstract references."),91clEnumValN(LVAttributeKind::Level, "level",92"Lexical scope level (File=0, Compile Unit=1)."),93clEnumValN(LVAttributeKind::Linkage, "linkage", "Linkage name."),94clEnumValN(LVAttributeKind::Local, "local",95"Element referenced only in the Compile Unit."),96clEnumValN(LVAttributeKind::Location, "location",97"Element debug location."),98clEnumValN(LVAttributeKind::Offset, "offset",99"Debug information offset."),100clEnumValN(LVAttributeKind::Pathname, "pathname",101"Pathname where the element is defined."),102clEnumValN(LVAttributeKind::Producer, "producer",103"Toolchain identification name."),104clEnumValN(LVAttributeKind::Publics, "publics",105"Function names that are public."),106clEnumValN(LVAttributeKind::Qualified, "qualified",107"The element type include parents in its name."),108clEnumValN(LVAttributeKind::Qualifier, "qualifier",109"Line qualifiers (Newstatement, BasicBlock, etc.)."),110clEnumValN(LVAttributeKind::Range, "range",111"Debug location ranges."),112clEnumValN(LVAttributeKind::Reference, "reference",113"Element declaration and definition references."),114clEnumValN(LVAttributeKind::Register, "register",115"Processor register names."),116clEnumValN(LVAttributeKind::Standard, "standard",117"Basic attributes alias."),118clEnumValN(LVAttributeKind::Subrange, "subrange",119"Subrange encoding information for arrays."),120clEnumValN(LVAttributeKind::System, "system",121"Display PDB's MS system elements."),122clEnumValN(LVAttributeKind::Typename, "typename",123"Include Parameters in templates."),124clEnumValN(LVAttributeKind::Underlying, "underlying",125"Underlying type for type definitions."),126clEnumValN(LVAttributeKind::Zero, "zero", "Zero line numbers.")));127128//===----------------------------------------------------------------------===//129// '--compare' options130//===----------------------------------------------------------------------===//131cl::OptionCategory132cmdline::CompareCategory("Compare Options",133"These control the view comparison.");134135// --compare-context136static cl::opt<bool, true>137CompareContext("compare-context", cl::cat(CompareCategory),138cl::desc("Add the view as compare context."), cl::Hidden,139cl::ZeroOrMore, cl::location(ReaderOptions.Compare.Context),140cl::init(false));141142// --compare=<value>[,<value>,...]143cl::list<LVCompareKind> cmdline::CompareElements(144"compare", cl::cat(CompareCategory), cl::desc("Elements to compare."),145cl::Hidden, cl::CommaSeparated,146values(clEnumValN(LVCompareKind::All, "all", "Compare all elements."),147clEnumValN(LVCompareKind::Lines, "lines", "Lines."),148clEnumValN(LVCompareKind::Scopes, "scopes", "Scopes."),149clEnumValN(LVCompareKind::Symbols, "symbols", "Symbols."),150clEnumValN(LVCompareKind::Types, "types", "Types.")));151152//===----------------------------------------------------------------------===//153// '--output' options154//===----------------------------------------------------------------------===//155cl::OptionCategory156cmdline::OutputCategory("Output Options",157"These control the output generated.");158159// --output-file=<filename>160cl::opt<std::string>161cmdline::OutputFilename("output-file", cl::cat(OutputCategory),162cl::desc("Redirect output to the specified file."),163cl::Hidden, cl::value_desc("filename"),164cl::init("-"));165166// --output-folder=<path>167static cl::opt<std::string, true>168OutputFolder("output-folder", cl::cat(OutputCategory),169cl::desc("Folder name for view splitting."),170cl::value_desc("pathname"), cl::Hidden, cl::ZeroOrMore,171cl::location(ReaderOptions.Output.Folder));172173// --output-level=<level>174static cl::opt<unsigned, true>175OutputLevel("output-level", cl::cat(OutputCategory),176cl::desc("Only print to a depth of N elements."),177cl::value_desc("N"), cl::Hidden, cl::ZeroOrMore,178cl::location(ReaderOptions.Output.Level), cl::init(-1U));179180// --ouput=<value>[,<value>,...]181cl::list<LVOutputKind> cmdline::OutputOptions(182"output", cl::cat(OutputCategory), cl::desc("Outputs for view."),183cl::Hidden, cl::CommaSeparated,184values(clEnumValN(LVOutputKind::All, "all", "All outputs."),185clEnumValN(LVOutputKind::Split, "split",186"Split the output by Compile Units."),187clEnumValN(LVOutputKind::Text, "text",188"Use a free form text output."),189clEnumValN(LVOutputKind::Json, "json",190"Use JSON as the output format.")));191192// --output-sort193static cl::opt<LVSortMode, true> OutputSort(194"output-sort", cl::cat(OutputCategory),195cl::desc("Primary key when ordering logical view (default: line)."),196cl::Hidden, cl::ZeroOrMore,197values(clEnumValN(LVSortMode::Kind, "kind", "Sort by element kind."),198clEnumValN(LVSortMode::Line, "line", "Sort by element line number."),199clEnumValN(LVSortMode::Name, "name", "Sort by element name."),200clEnumValN(LVSortMode::Offset, "offset", "Sort by element offset.")),201cl::location(ReaderOptions.Output.SortMode), cl::init(LVSortMode::Line));202203//===----------------------------------------------------------------------===//204// '--print' options205//===----------------------------------------------------------------------===//206cl::OptionCategory207cmdline::PrintCategory("Print Options",208"These control which elements are printed.");209210// --print=<value>[,<value>,...]211cl::list<LVPrintKind> cmdline::PrintOptions(212"print", cl::cat(PrintCategory), cl::desc("Element to print."),213cl::CommaSeparated,214values(clEnumValN(LVPrintKind::All, "all", "All elements."),215clEnumValN(LVPrintKind::Elements, "elements",216"Instructions, lines, scopes, symbols and types."),217clEnumValN(LVPrintKind::Instructions, "instructions",218"Assembler instructions."),219clEnumValN(LVPrintKind::Lines, "lines",220"Lines referenced in the debug information."),221clEnumValN(LVPrintKind::Scopes, "scopes",222"A lexical block (Function, Class, etc.)."),223clEnumValN(LVPrintKind::Sizes, "sizes",224"Scope contributions to the debug information."),225clEnumValN(LVPrintKind::Summary, "summary",226"Summary of elements missing/added/matched/printed."),227clEnumValN(LVPrintKind::Symbols, "symbols",228"Symbols (Variable, Members, etc.)."),229clEnumValN(LVPrintKind::Types, "types",230"Types (Pointer, Reference, etc.)."),231clEnumValN(LVPrintKind::Warnings, "warnings",232"Warnings detected.")));233234//===----------------------------------------------------------------------===//235// '--report' options236//===----------------------------------------------------------------------===//237cl::OptionCategory238cmdline::ReportCategory("Report Options",239"These control how the elements are printed.");240241// --report=<value>[,<value>,...]242cl::list<LVReportKind> cmdline::ReportOptions(243"report", cl::cat(ReportCategory),244cl::desc("Reports layout used for print, compare and select."), cl::Hidden,245cl::CommaSeparated,246values(clEnumValN(LVReportKind::All, "all", "Generate all reports."),247clEnumValN(LVReportKind::Children, "children",248"Selected elements are displayed in a tree view "249"(Include children)"),250clEnumValN(LVReportKind::List, "list",251"Selected elements are displayed in a tabular format."),252clEnumValN(LVReportKind::Parents, "parents",253"Selected elements are displayed in a tree view. "254"(Include parents)"),255clEnumValN(LVReportKind::View, "view",256"Selected elements are displayed in a tree view "257"(Include parents and children.")));258259//===----------------------------------------------------------------------===//260// '--select' options261//===----------------------------------------------------------------------===//262cl::OptionCategory263cmdline::SelectCategory("Select Options",264"These control which elements are selected.");265266// --select-nocase267static cl::opt<bool, true>268SelectIgnoreCase("select-nocase", cl::cat(SelectCategory),269cl::desc("Ignore case distinctions when searching."),270cl::Hidden, cl::ZeroOrMore,271cl::location(ReaderOptions.Select.IgnoreCase),272cl::init(false));273274// --select-regex275static cl::opt<bool, true> SelectUseRegex(276"select-regex", cl::cat(SelectCategory),277cl::desc("Treat any <pattern> strings as regular expressions when "278"selecting instead of just as an exact string match."),279cl::Hidden, cl::ZeroOrMore, cl::location(ReaderOptions.Select.UseRegex),280cl::init(false));281282// --select=<pattern>283cl::list<std::string> cmdline::SelectPatterns(284"select", cl::cat(SelectCategory),285cl::desc("Search elements matching the given pattern."), cl::Hidden,286cl::value_desc("pattern"), cl::CommaSeparated);287288// --select-offsets=<value>[,<value>,...]289OffsetOptionList cmdline::SelectOffsets("select-offsets",290cl::cat(SelectCategory),291cl::desc("Offset element to print."),292cl::Hidden, cl::value_desc("offset"),293cl::CommaSeparated, cl::ZeroOrMore);294295// --select-elements=<value>[,<value>,...]296cl::list<LVElementKind> cmdline::SelectElements(297"select-elements", cl::cat(SelectCategory),298cl::desc("Conditions to use when printing elements."), cl::Hidden,299cl::CommaSeparated,300values(clEnumValN(LVElementKind::Discarded, "Discarded",301"Discarded elements by the linker."),302clEnumValN(LVElementKind::Global, "Global",303"Element referenced across Compile Units."),304clEnumValN(LVElementKind::Optimized, "Optimized",305"Generated inlined abstract references.")));306307// --select-lines=<value>[,<value>,...]308cl::list<LVLineKind> cmdline::SelectLines(309"select-lines", cl::cat(SelectCategory),310cl::desc("Line kind to use when printing lines."), cl::Hidden,311cl::CommaSeparated,312values(313clEnumValN(LVLineKind::IsAlwaysStepInto, "AlwaysStepInto",314"Always Step Into."),315clEnumValN(LVLineKind::IsBasicBlock, "BasicBlock", "Basic block."),316clEnumValN(LVLineKind::IsDiscriminator, "Discriminator",317"Discriminator."),318clEnumValN(LVLineKind::IsEndSequence, "EndSequence", "End sequence."),319clEnumValN(LVLineKind::IsEpilogueBegin, "EpilogueBegin.",320"Epilogue begin."),321clEnumValN(LVLineKind::IsLineDebug, "LineDebug", "Debug line."),322clEnumValN(LVLineKind::IsLineAssembler, "LineAssembler",323"Assembler line."),324clEnumValN(LVLineKind::IsNeverStepInto, "NeverStepInto",325"Never Step Into."),326clEnumValN(LVLineKind::IsNewStatement, "NewStatement",327"New statement."),328clEnumValN(LVLineKind::IsPrologueEnd, "PrologueEnd", "Prologue end.")));329330// --select-scopes=<value>[,<value>,...]331cl::list<LVScopeKind> cmdline::SelectScopes(332"select-scopes", cl::cat(SelectCategory),333cl::desc("Scope kind to use when printing scopes."), cl::Hidden,334cl::CommaSeparated,335values(336clEnumValN(LVScopeKind::IsAggregate, "Aggregate",337"Class, Structure or Union."),338clEnumValN(LVScopeKind::IsArray, "Array", "Array."),339clEnumValN(LVScopeKind::IsBlock, "Block", "Lexical block."),340clEnumValN(LVScopeKind::IsCallSite, "CallSite", "Call site block."),341clEnumValN(LVScopeKind::IsCatchBlock, "CatchBlock",342"Exception catch block."),343clEnumValN(LVScopeKind::IsClass, "Class", "Class."),344clEnumValN(LVScopeKind::IsCompileUnit, "CompileUnit", "Compile unit."),345clEnumValN(LVScopeKind::IsEntryPoint, "EntryPoint",346"Function entry point."),347clEnumValN(LVScopeKind::IsEnumeration, "Enumeration", "Enumeration."),348clEnumValN(LVScopeKind::IsFunction, "Function", "Function."),349clEnumValN(LVScopeKind::IsFunctionType, "FunctionType",350"Function type."),351clEnumValN(LVScopeKind::IsInlinedFunction, "InlinedFunction",352"Inlined function."),353clEnumValN(LVScopeKind::IsLabel, "Label", "Label."),354clEnumValN(LVScopeKind::IsLexicalBlock, "LexicalBlock",355"Lexical block."),356clEnumValN(LVScopeKind::IsNamespace, "Namespace", "Namespace."),357clEnumValN(LVScopeKind::IsRoot, "Root", "Root."),358clEnumValN(LVScopeKind::IsStructure, "Structure", "Structure."),359clEnumValN(LVScopeKind::IsSubprogram, "Subprogram", "Subprogram."),360clEnumValN(LVScopeKind::IsTemplate, "Template", "Template."),361clEnumValN(LVScopeKind::IsTemplateAlias, "TemplateAlias",362"Template alias."),363clEnumValN(LVScopeKind::IsTemplatePack, "TemplatePack",364"Template pack."),365clEnumValN(LVScopeKind::IsTryBlock, "TryBlock", "Exception try block."),366clEnumValN(LVScopeKind::IsUnion, "Union", "Union.")));367368// --select-symbols=<value>[,<value>,...]369cl::list<LVSymbolKind> cmdline::SelectSymbols(370"select-symbols", cl::cat(SelectCategory),371cl::desc("Symbol kind to use when printing symbols."), cl::Hidden,372cl::CommaSeparated,373values(clEnumValN(LVSymbolKind::IsCallSiteParameter, "CallSiteParameter",374"Call site parameter."),375clEnumValN(LVSymbolKind::IsConstant, "Constant", "Constant."),376clEnumValN(LVSymbolKind::IsInheritance, "Inheritance",377"Inheritance."),378clEnumValN(LVSymbolKind::IsMember, "Member", "Member."),379clEnumValN(LVSymbolKind::IsParameter, "Parameter", "Parameter."),380clEnumValN(LVSymbolKind::IsUnspecified, "Unspecified",381"Unspecified parameter."),382clEnumValN(LVSymbolKind::IsVariable, "Variable", "Variable.")));383384// --select-types=<value>[,<value>,...]385cl::list<LVTypeKind> cmdline::SelectTypes(386"select-types", cl::cat(SelectCategory),387cl::desc("Type kind to use when printing types."), cl::Hidden,388cl::CommaSeparated,389values(390clEnumValN(LVTypeKind::IsBase, "Base", "Base Type (int, bool, etc.)."),391clEnumValN(LVTypeKind::IsConst, "Const", "Constant specifier."),392clEnumValN(LVTypeKind::IsEnumerator, "Enumerator", "Enumerator."),393clEnumValN(LVTypeKind::IsImport, "Import", "Import."),394clEnumValN(LVTypeKind::IsImportDeclaration, "ImportDeclaration",395"Import declaration."),396clEnumValN(LVTypeKind::IsImportModule, "ImportModule",397"Import module."),398clEnumValN(LVTypeKind::IsPointer, "Pointer", "Pointer."),399clEnumValN(LVTypeKind::IsPointerMember, "PointerMember",400"Pointer to member."),401clEnumValN(LVTypeKind::IsReference, "Reference", "Reference type."),402clEnumValN(LVTypeKind::IsRestrict, "Restrict", "Restrict specifier."),403clEnumValN(LVTypeKind::IsRvalueReference, "RvalueReference",404"Rvalue reference."),405clEnumValN(LVTypeKind::IsSubrange, "Subrange", "Array subrange."),406clEnumValN(LVTypeKind::IsTemplateParam, "TemplateParam",407"Template Parameter."),408clEnumValN(LVTypeKind::IsTemplateTemplateParam, "TemplateTemplateParam",409"Template template parameter."),410clEnumValN(LVTypeKind::IsTemplateTypeParam, "TemplateTypeParam",411"Template type parameter."),412clEnumValN(LVTypeKind::IsTemplateValueParam, "TemplateValueParam",413"Template value parameter."),414clEnumValN(LVTypeKind::IsTypedef, "Typedef", "Type definition."),415clEnumValN(LVTypeKind::IsUnspecified, "Unspecified",416"Unspecified type."),417clEnumValN(LVTypeKind::IsVolatile, "Volatile", "Volatile specifier.")));418419//===----------------------------------------------------------------------===//420// '--warning' options421//===----------------------------------------------------------------------===//422cl::OptionCategory423cmdline::WarningCategory("Warning Options",424"These control the generated warnings.");425426// --warning=<value>[,<value>,...]427cl::list<LVWarningKind> cmdline::WarningOptions(428"warning", cl::cat(WarningCategory), cl::desc("Warnings to generate."),429cl::Hidden, cl::CommaSeparated,430values(431clEnumValN(LVWarningKind::All, "all", "All warnings."),432clEnumValN(LVWarningKind::Coverages, "coverages",433"Invalid symbol coverages values."),434clEnumValN(LVWarningKind::Lines, "lines", "Debug lines that are zero."),435clEnumValN(LVWarningKind::Locations, "locations",436"Invalid symbol locations."),437clEnumValN(LVWarningKind::Ranges, "ranges", "Invalid code ranges.")));438439//===----------------------------------------------------------------------===//440// '--internal' options441//===----------------------------------------------------------------------===//442cl::OptionCategory443cmdline::InternalCategory("Internal Options",444"Internal traces and extra debugging code.");445446// --internal=<value>[,<value>,...]447cl::list<LVInternalKind> cmdline::InternalOptions(448"internal", cl::cat(InternalCategory), cl::desc("Traces to enable."),449cl::Hidden, cl::CommaSeparated,450values(451clEnumValN(LVInternalKind::All, "all", "Enable all traces."),452clEnumValN(LVInternalKind::Cmdline, "cmdline", "Print command line."),453clEnumValN(LVInternalKind::ID, "id", "Print unique element ID"),454clEnumValN(LVInternalKind::Integrity, "integrity",455"Check elements integrity."),456clEnumValN(LVInternalKind::None, "none", "Ignore element line number."),457clEnumValN(LVInternalKind::Tag, "tag", "Debug information tags.")));458459/// @}460461// Copy local options into a globally accessible data structure.462void llvm::logicalview::cmdline::propagateOptions() {463// Traverse list of options and update the given set (Using case and Regex).464auto UpdatePattern = [&](auto &List, auto &Set, bool IgnoreCase,465bool UseRegex) {466if (!List.empty())467for (std::string &Pattern : List)468Set.insert((IgnoreCase && !UseRegex) ? StringRef(Pattern).lower()469: Pattern);470};471472// Handle --select.473UpdatePattern(SelectPatterns, ReaderOptions.Select.Generic,474ReaderOptions.Select.IgnoreCase, ReaderOptions.Select.UseRegex);475476// Traverse list of options and update the given set.477auto UpdateSet = [&](auto &List, auto &Set) {478std::copy(List.begin(), List.end(), std::inserter(Set, Set.begin()));479};480481// Handle options sets.482UpdateSet(AttributeOptions, ReaderOptions.Attribute.Kinds);483UpdateSet(PrintOptions, ReaderOptions.Print.Kinds);484UpdateSet(OutputOptions, ReaderOptions.Output.Kinds);485UpdateSet(ReportOptions, ReaderOptions.Report.Kinds);486UpdateSet(WarningOptions, ReaderOptions.Warning.Kinds);487UpdateSet(InternalOptions, ReaderOptions.Internal.Kinds);488489UpdateSet(SelectElements, ReaderOptions.Select.Elements);490UpdateSet(SelectLines, ReaderOptions.Select.Lines);491UpdateSet(SelectScopes, ReaderOptions.Select.Scopes);492UpdateSet(SelectSymbols, ReaderOptions.Select.Symbols);493UpdateSet(SelectTypes, ReaderOptions.Select.Types);494UpdateSet(SelectOffsets, ReaderOptions.Select.Offsets);495UpdateSet(CompareElements, ReaderOptions.Compare.Elements);496497// Resolve any options dependencies (ie. --print=all should set other498// print options, etc.).499ReaderOptions.resolveDependencies();500}501502503