LLDB  mainline
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
lldb_private::Options Class Referenceabstract

A command line option parsing protocol class. More...

#include "lldb/Interpreter/Options.h"

Inherited by CommandObjectBreakpointClear::CommandOptions, CommandObjectBreakpointCommandAdd::CommandOptions, CommandObjectBreakpointCommandDelete::CommandOptions, CommandObjectBreakpointDelete::CommandOptions, CommandObjectBreakpointList::CommandOptions, CommandObjectBreakpointRead::CommandOptions, CommandObjectBreakpointWrite::CommandOptions, CommandObjectCommandsHistory::CommandOptions, CommandObjectCommandsScriptAdd::CommandOptions, CommandObjectCommandsScriptImport::CommandOptions, CommandObjectCommandsSource::CommandOptions, CommandObjectFrameDiagnose::CommandOptions, CommandObjectFrameSelect::CommandOptions, CommandObjectLogEnable::CommandOptions, CommandObjectObjC_ClassTable_Dump::CommandOptions, CommandObjectPlatformFRead::CommandOptions, CommandObjectPlatformFWrite::CommandOptions, CommandObjectPlatformProcessAttach::CommandOptions, CommandObjectPlatformProcessList::CommandOptions, CommandObjectPlatformShell::CommandOptions, CommandObjectProcessAttach::CommandOptions, CommandObjectProcessConnect::CommandOptions, CommandObjectProcessContinue::CommandOptions, CommandObjectProcessDetach::CommandOptions, CommandObjectProcessHandle::CommandOptions, CommandObjectProcessLoad::CommandOptions, CommandObjectRenderScriptRuntimeAllocationDump::CommandOptions, CommandObjectRenderScriptRuntimeAllocationList::CommandOptions, CommandObjectRenderScriptRuntimeKernelBreakpointSet::CommandOptions, CommandObjectRenderScriptRuntimeReductionBreakpointSet::CommandOptions, CommandObjectSettingsRead::CommandOptions, CommandObjectSettingsSet::CommandOptions, CommandObjectSettingsWrite::CommandOptions, CommandObjectTargetModulesDumpLineTable::CommandOptions, CommandObjectTargetModulesDumpSymtab::CommandOptions, CommandObjectTargetModulesList::CommandOptions, CommandObjectTargetModulesLookup::CommandOptions, CommandObjectTargetModulesShowUnwind::CommandOptions, CommandObjectTargetStopHookAdd::CommandOptions, CommandObjectThreadBacktrace::CommandOptions, CommandObjectThreadInfo::CommandOptions, CommandObjectThreadJump::CommandOptions, CommandObjectThreadPlanList::CommandOptions, CommandObjectThreadReturn::CommandOptions, CommandObjectThreadStepWithTypeAndScope::CommandOptions, CommandObjectThreadUntil::CommandOptions, CommandObjectTypeFormatterDelete::CommandOptions, CommandObjectWatchpointCommandAdd::CommandOptions, CommandObjectWatchpointIgnore::CommandOptions, CommandObjectWatchpointList::CommandOptions, CommandObjectWatchpointModify::CommandOptions, lldb_private::CommandObjectDisassemble::CommandOptions, lldb_private::CommandObjectHelp::CommandOptions, lldb_private::OptionGroupOptions, lldb_private::ProcessLaunchCommandOptions, and sddarwinlog_private::EnableOptions.

Collaboration diagram for lldb_private::Options:
Collaboration graph
[legend]

Public Member Functions

 Options ()
 
virtual ~Options ()
 
void BuildGetoptTable ()
 
void BuildValidOptionSets ()
 
uint32_t NumCommandOptions ()
 
OptionGetLongOptions ()
 Get the option definitions to use when parsing Args options. More...
 
void OptionSeen (int short_option)
 
bool VerifyOptions (CommandReturnObject &result)
 
bool VerifyPartialOptions (CommandReturnObject &result)
 
void OutputFormattedUsageText (Stream &strm, const OptionDefinition &option_def, uint32_t output_max_columns)
 
void GenerateOptionUsage (Stream &strm, CommandObject *cmd, uint32_t screen_width)
 
bool SupportsLongOption (const char *long_option)
 
virtual llvm::ArrayRef< OptionDefinition > GetDefinitions ()
 
void NotifyOptionParsingStarting (ExecutionContext *execution_context)
 
llvm::Expected< ArgsParse (const Args &args, ExecutionContext *execution_context, lldb::PlatformSP platform_sp, bool require_validation)
 Parse the provided arguments. More...
 
llvm::Expected< ArgsParseAlias (const Args &args, OptionArgVector *option_arg_vector, std::string &input_line)
 
OptionElementVector ParseForCompletion (const Args &args, uint32_t cursor_index)
 
Status NotifyOptionParsingFinished (ExecutionContext *execution_context)
 
virtual Status SetOptionValue (uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context)=0
 Set the value of an option. More...
 
bool HandleOptionCompletion (lldb_private::CompletionRequest &request, OptionElementVector &option_map, CommandInterpreter &interpreter)
 Handles the generic bits of figuring out whether we are in an option, and if so completing it. More...
 
virtual bool HandleOptionArgumentCompletion (lldb_private::CompletionRequest &request, OptionElementVector &opt_element_vector, int opt_element_index, CommandInterpreter &interpreter)
 Handles the generic bits of figuring out whether we are in an option, and if so completing it. More...
 

Protected Types

typedef std::set< int > OptionSet
 
typedef std::vector< OptionSetOptionSetVector
 

Protected Member Functions

OptionSetVectorGetRequiredOptions ()
 
OptionSetVectorGetOptionalOptions ()
 
bool IsASubset (const OptionSet &set_a, const OptionSet &set_b)
 
size_t OptionsSetDiff (const OptionSet &set_a, const OptionSet &set_b, OptionSet &diffs)
 
void OptionsSetUnion (const OptionSet &set_a, const OptionSet &set_b, OptionSet &union_set)
 
virtual void OptionParsingStarting (ExecutionContext *execution_context)=0
 
virtual Status OptionParsingFinished (ExecutionContext *execution_context)
 

Protected Attributes

std::vector< Optionm_getopt_table
 
OptionSet m_seen_options
 
OptionSetVector m_required_options
 
OptionSetVector m_optional_options
 

Detailed Description

A command line option parsing protocol class.

Options is designed to be subclassed to contain all needed options for a given command. The options can be parsed by calling the Parse function.

The options are specified using the format defined for the libc options parsing function getopt_long_only:

#include <getopt.h>
int getopt_long_only(int argc, char * const *argv, const char
*optstring, const struct option *longopts, int *longindex);

Definition at line 62 of file Options.h.

Member Typedef Documentation

◆ OptionSet

typedef std::set<int> lldb_private::Options::OptionSet
protected

Definition at line 206 of file Options.h.

◆ OptionSetVector

typedef std::vector<OptionSet> lldb_private::Options::OptionSetVector
protected

Definition at line 207 of file Options.h.

Constructor & Destructor Documentation

◆ Options()

Options::Options ( )

Definition at line 28 of file Options.cpp.

References BuildValidOptionSets().

◆ ~Options()

Options::~Options ( )
virtual

Definition at line 30 of file Options.cpp.

Member Function Documentation

◆ BuildGetoptTable()

void lldb_private::Options::BuildGetoptTable ( )

◆ BuildValidOptionSets()

void Options::BuildValidOptionSets ( )

◆ GenerateOptionUsage()

void Options::GenerateOptionUsage ( Stream strm,
CommandObject cmd,
uint32_t  screen_width 
)

◆ GetDefinitions()

virtual llvm::ArrayRef<OptionDefinition> lldb_private::Options::GetDefinitions ( )
inlinevirtual

Reimplemented in CommandObjectRenderScriptRuntimeAllocationList::CommandOptions, CommandObjectRenderScriptRuntimeAllocationDump::CommandOptions, CommandObjectTargetStopHookAdd::CommandOptions, CommandObjectRenderScriptRuntimeKernelBreakpointSet::CommandOptions, CommandObjectRenderScriptRuntimeReductionBreakpointSet::CommandOptions, CommandObjectTargetModulesLookup::CommandOptions, CommandObjectTargetModulesShowUnwind::CommandOptions, CommandObjectTargetModulesList::CommandOptions, CommandObjectTargetModulesDumpLineTable::CommandOptions, CommandObjectBreakpointWrite::CommandOptions, CommandObjectBreakpointRead::CommandOptions, CommandObjectTargetModulesDumpSymtab::CommandOptions, CommandObjectThreadPlanList::CommandOptions, CommandObjectThreadJump::CommandOptions, CommandObjectPlatformShell::CommandOptions, CommandObjectBreakpointDelete::CommandOptions, CommandObjectCommandsScriptAdd::CommandOptions, CommandObjectThreadReturn::CommandOptions, CommandObjectPlatformProcessAttach::CommandOptions, CommandObjectBreakpointClear::CommandOptions, CommandObjectThreadInfo::CommandOptions, CommandObjectCommandsScriptImport::CommandOptions, CommandObjectProcessHandle::CommandOptions, CommandObjectPlatformProcessList::CommandOptions, CommandObjectBreakpointList::CommandOptions, CommandObjectThreadUntil::CommandOptions, CommandObjectProcessLoad::CommandOptions, CommandObjectProcessConnect::CommandOptions, CommandObjectTypeFormatterDelete::CommandOptions, CommandObjectProcessDetach::CommandOptions, CommandObjectPlatformFWrite::CommandOptions, CommandObjectWatchpointModify::CommandOptions, CommandObjectPlatformFRead::CommandOptions, CommandObjectProcessContinue::CommandOptions, sddarwinlog_private::EnableOptions, CommandObjectWatchpointIgnore::CommandOptions, CommandObjectBreakpointCommandDelete::CommandOptions, CommandObjectObjC_ClassTable_Dump::CommandOptions, CommandObjectThreadStepWithTypeAndScope::CommandOptions, CommandObjectSettingsRead::CommandOptions, CommandObjectSettingsWrite::CommandOptions, CommandObjectWatchpointCommandAdd::CommandOptions, CommandObjectProcessAttach::CommandOptions, CommandObjectBreakpointCommandAdd::CommandOptions, lldb_private::OptionGroupOptions, CommandObjectThreadBacktrace::CommandOptions, CommandObjectCommandsSource::CommandOptions, CommandObjectFrameSelect::CommandOptions, lldb_private::ProcessLaunchCommandOptions, CommandObjectWatchpointList::CommandOptions, CommandObjectLogEnable::CommandOptions, CommandObjectSettingsSet::CommandOptions, CommandObjectFrameDiagnose::CommandOptions, CommandObjectCommandsHistory::CommandOptions, lldb_private::CommandObjectHelp::CommandOptions, and lldb_private::CommandObjectDisassemble::CommandOptions.

Definition at line 102 of file Options.h.

References lldb_private::postfix::Parse().

Referenced by BuildValidOptionSets(), GenerateOptionUsage(), GetLongOptions(), HandleOptionArgumentCompletion(), HandleOptionCompletion(), NumCommandOptions(), ParseForCompletion(), and SupportsLongOption().

◆ GetLongOptions()

Option * Options::GetLongOptions ( )

Get the option definitions to use when parsing Args options.

See also
Args::ParseOptions (Options&)
man getopt_long_only

Definition at line 202 of file Options.cpp.

References lldb_private::Host::eSystemLogError, GetDefinitions(), lldb_private::isprint8(), m_getopt_table, and lldb_private::Host::SystemLog().

Referenced by Parse(), ParseAlias(), and ParseForCompletion().

◆ GetOptionalOptions()

OptionSetVector& lldb_private::Options::GetOptionalOptions ( )
inlineprotected

Definition at line 219 of file Options.h.

Referenced by VerifyOptions(), and VerifyPartialOptions().

◆ GetRequiredOptions()

OptionSetVector& lldb_private::Options::GetRequiredOptions ( )
inlineprotected

Definition at line 214 of file Options.h.

Referenced by GenerateOptionUsage(), VerifyOptions(), and VerifyPartialOptions().

◆ HandleOptionArgumentCompletion()

bool Options::HandleOptionArgumentCompletion ( lldb_private::CompletionRequest request,
OptionElementVector opt_element_vector,
int  opt_element_index,
CommandInterpreter interpreter 
)
virtual

◆ HandleOptionCompletion()

bool Options::HandleOptionCompletion ( lldb_private::CompletionRequest request,
OptionElementVector option_map,
CommandInterpreter interpreter 
)

◆ IsASubset()

bool Options::IsASubset ( const OptionSet set_a,
const OptionSet set_b 
)
protected

Definition at line 47 of file Options.cpp.

Referenced by VerifyOptions(), and VerifyPartialOptions().

◆ NotifyOptionParsingFinished()

Status Options::NotifyOptionParsingFinished ( ExecutionContext execution_context)

◆ NotifyOptionParsingStarting()

void Options::NotifyOptionParsingStarting ( ExecutionContext execution_context)

◆ NumCommandOptions()

uint32_t Options::NumCommandOptions ( )

◆ OptionParsingFinished()

virtual Status lldb_private::Options::OptionParsingFinished ( ExecutionContext execution_context)
inlineprotectedvirtual

◆ OptionParsingStarting()

virtual void lldb_private::Options::OptionParsingStarting ( ExecutionContext execution_context)
protectedpure virtual

Implemented in CommandObjectRenderScriptRuntimeAllocationList::CommandOptions, CommandObjectRenderScriptRuntimeAllocationDump::CommandOptions, CommandObjectTargetStopHookAdd::CommandOptions, CommandObjectRenderScriptRuntimeKernelBreakpointSet::CommandOptions, CommandObjectRenderScriptRuntimeReductionBreakpointSet::CommandOptions, CommandObjectTargetModulesLookup::CommandOptions, CommandObjectTargetModulesShowUnwind::CommandOptions, CommandObjectTargetModulesList::CommandOptions, CommandObjectTargetModulesDumpLineTable::CommandOptions, CommandObjectBreakpointWrite::CommandOptions, CommandObjectBreakpointRead::CommandOptions, CommandObjectTargetModulesDumpSymtab::CommandOptions, CommandObjectThreadPlanList::CommandOptions, CommandObjectThreadJump::CommandOptions, CommandObjectPlatformShell::CommandOptions, CommandObjectBreakpointDelete::CommandOptions, CommandObjectCommandsScriptAdd::CommandOptions, CommandObjectThreadReturn::CommandOptions, CommandObjectPlatformProcessAttach::CommandOptions, CommandObjectBreakpointClear::CommandOptions, CommandObjectCommandsScriptImport::CommandOptions, CommandObjectThreadInfo::CommandOptions, CommandObjectProcessHandle::CommandOptions, CommandObjectPlatformProcessList::CommandOptions, CommandObjectBreakpointList::CommandOptions, CommandObjectThreadUntil::CommandOptions, CommandObjectProcessLoad::CommandOptions, CommandObjectProcessConnect::CommandOptions, CommandObjectTypeFormatterDelete::CommandOptions, CommandObjectProcessDetach::CommandOptions, CommandObjectPlatformFWrite::CommandOptions, CommandObjectWatchpointModify::CommandOptions, CommandObjectPlatformFRead::CommandOptions, CommandObjectProcessContinue::CommandOptions, CommandObjectWatchpointIgnore::CommandOptions, CommandObjectBreakpointCommandDelete::CommandOptions, CommandObjectObjC_ClassTable_Dump::CommandOptions, CommandObjectThreadStepWithTypeAndScope::CommandOptions, sddarwinlog_private::EnableOptions, CommandObjectSettingsRead::CommandOptions, CommandObjectSettingsWrite::CommandOptions, CommandObjectProcessAttach::CommandOptions, CommandObjectWatchpointCommandAdd::CommandOptions, CommandObjectBreakpointCommandAdd::CommandOptions, lldb_private::OptionGroupOptions, CommandObjectThreadBacktrace::CommandOptions, CommandObjectFrameSelect::CommandOptions, CommandObjectCommandsSource::CommandOptions, lldb_private::ProcessLaunchCommandOptions, CommandObjectWatchpointList::CommandOptions, CommandObjectLogEnable::CommandOptions, CommandObjectSettingsSet::CommandOptions, CommandObjectFrameDiagnose::CommandOptions, CommandObjectCommandsHistory::CommandOptions, lldb_private::CommandObjectHelp::CommandOptions, and lldb_private::CommandObjectDisassemble::CommandOptions.

Referenced by NotifyOptionParsingStarting().

◆ OptionSeen()

void Options::OptionSeen ( int  short_option)

Definition at line 43 of file Options.cpp.

References m_seen_options.

Referenced by Parse(), ParseAlias(), and ParseForCompletion().

◆ OptionsSetDiff()

size_t Options::OptionsSetDiff ( const OptionSet set_a,
const OptionSet set_b,
OptionSet diffs 
)
protected

Definition at line 67 of file Options.cpp.

Referenced by VerifyOptions().

◆ OptionsSetUnion()

void Options::OptionsSetUnion ( const OptionSet set_a,
const OptionSet set_b,
OptionSet union_set 
)
protected

Definition at line 87 of file Options.cpp.

Referenced by VerifyPartialOptions().

◆ OutputFormattedUsageText()

void Options::OutputFormattedUsageText ( Stream strm,
const OptionDefinition &  option_def,
uint32_t  output_max_columns 
)

◆ Parse()

llvm::Expected< Args > Options::Parse ( const Args args,
ExecutionContext execution_context,
lldb::PlatformSP  platform_sp,
bool  require_validation 
)

Parse the provided arguments.

The parsed options are set via calls to SetOptionValue. In case of a successful parse, the function returns a copy of the input arguments with the parsed options removed. Otherwise, it returns an error.

param[in] platform_sp The platform used for option validation. This is necessary because an empty execution_context is not enough to get us to a reasonable platform. If the platform isn't given, we'll try to get it from the execution context. If we can't get it from the execution context, we'll skip validation.

param[in] require_validation When true, it will fail option parsing if validation could not occur due to not having a platform.

Definition at line 1327 of file Options.cpp.

References lldb_private::Option::definition, lldb_private::OptionParser::eNoArgument, lldb_private::OptionParser::eOptionalArgument, lldb_private::OptionParser::eRequiredArgument, lldb_private::Status::Fail(), lldb_private::Option::flag, GetArgvForParsing(), GetLongOptions(), lldb_private::OptionParser::GetOptionArgument(), lldb_private::OptionParser::GetOptionIndex(), lldb_private::StreamString::GetString(), lldb_private::ExecutionContext::GetTargetSP(), lldb_private::isprint8(), OptionSeen(), lldb_private::OptionParser::Parse(), lldb_private::OptionParser::Prepare(), ReconstituteArgsAfterParsing(), lldb_private::Status::SetErrorStringWithFormat(), SetOptionValue(), lldb_private::Status::ToError(), and lldb_private::Option::val.

Referenced by lldb_private::CommandObject::ParseOptions().

◆ ParseAlias()

llvm::Expected< Args > Options::ParseAlias ( const Args args,
OptionArgVector option_arg_vector,
std::string &  input_line 
)

◆ ParseForCompletion()

OptionElementVector Options::ParseForCompletion ( const Args args,
uint32_t  cursor_index 
)

◆ SetOptionValue()

virtual Status lldb_private::Options::SetOptionValue ( uint32_t  option_idx,
llvm::StringRef  option_arg,
ExecutionContext execution_context 
)
pure virtual

Set the value of an option.

Parameters
[in]option_idxThe index into the "struct option" array that was returned by Options::GetLongOptions().
[in]option_argThe argument value for the option that the user entered, or nullptr if there is no argument for the current option.
[in]execution_contextThe execution context to use for evaluating the option. May be nullptr if the option is to be evaluated outside any particular context.
See also
Args::ParseOptions (Options&)
man getopt_long_only

Implemented in CommandObjectRenderScriptRuntimeAllocationList::CommandOptions, CommandObjectRenderScriptRuntimeAllocationDump::CommandOptions, CommandObjectTargetStopHookAdd::CommandOptions, CommandObjectRenderScriptRuntimeKernelBreakpointSet::CommandOptions, CommandObjectRenderScriptRuntimeReductionBreakpointSet::CommandOptions, CommandObjectTargetModulesLookup::CommandOptions, CommandObjectTargetModulesShowUnwind::CommandOptions, CommandObjectTargetModulesList::CommandOptions, CommandObjectTargetModulesDumpLineTable::CommandOptions, CommandObjectBreakpointWrite::CommandOptions, CommandObjectBreakpointRead::CommandOptions, CommandObjectTargetModulesDumpSymtab::CommandOptions, CommandObjectThreadPlanList::CommandOptions, CommandObjectThreadJump::CommandOptions, CommandObjectPlatformShell::CommandOptions, CommandObjectBreakpointDelete::CommandOptions, CommandObjectThreadReturn::CommandOptions, CommandObjectCommandsScriptAdd::CommandOptions, CommandObjectPlatformProcessAttach::CommandOptions, CommandObjectBreakpointClear::CommandOptions, CommandObjectThreadInfo::CommandOptions, CommandObjectCommandsScriptImport::CommandOptions, CommandObjectProcessHandle::CommandOptions, CommandObjectBreakpointList::CommandOptions, CommandObjectPlatformProcessList::CommandOptions, CommandObjectThreadUntil::CommandOptions, CommandObjectProcessLoad::CommandOptions, CommandObjectProcessConnect::CommandOptions, CommandObjectTypeFormatterDelete::CommandOptions, CommandObjectPlatformFWrite::CommandOptions, CommandObjectProcessDetach::CommandOptions, CommandObjectWatchpointModify::CommandOptions, CommandObjectPlatformFRead::CommandOptions, CommandObjectProcessContinue::CommandOptions, CommandObjectWatchpointIgnore::CommandOptions, sddarwinlog_private::EnableOptions, CommandObjectBreakpointCommandDelete::CommandOptions, CommandObjectObjC_ClassTable_Dump::CommandOptions, CommandObjectSettingsRead::CommandOptions, CommandObjectThreadStepWithTypeAndScope::CommandOptions, CommandObjectSettingsWrite::CommandOptions, CommandObjectProcessAttach::CommandOptions, CommandObjectWatchpointCommandAdd::CommandOptions, lldb_private::OptionGroupOptions, CommandObjectBreakpointCommandAdd::CommandOptions, CommandObjectThreadBacktrace::CommandOptions, CommandObjectFrameSelect::CommandOptions, CommandObjectCommandsSource::CommandOptions, lldb_private::ProcessLaunchCommandOptions, CommandObjectWatchpointList::CommandOptions, CommandObjectSettingsSet::CommandOptions, CommandObjectLogEnable::CommandOptions, CommandObjectFrameDiagnose::CommandOptions, CommandObjectCommandsHistory::CommandOptions, lldb_private::CommandObjectHelp::CommandOptions, and lldb_private::CommandObjectDisassemble::CommandOptions.

Referenced by Parse().

◆ SupportsLongOption()

bool Options::SupportsLongOption ( const char *  long_option)

Definition at line 326 of file Options.cpp.

References GetDefinitions().

Referenced by lldb_private::CommandInterpreter::RunCommandInterpreter().

◆ VerifyOptions()

bool Options::VerifyOptions ( CommandReturnObject result)

◆ VerifyPartialOptions()

bool Options::VerifyPartialOptions ( CommandReturnObject result)

Member Data Documentation

◆ m_getopt_table

std::vector<Option> lldb_private::Options::m_getopt_table
protected

◆ m_optional_options

OptionSetVector lldb_private::Options::m_optional_options
protected

Definition at line 212 of file Options.h.

Referenced by BuildValidOptionSets().

◆ m_required_options

OptionSetVector lldb_private::Options::m_required_options
protected

Definition at line 211 of file Options.h.

Referenced by BuildValidOptionSets().

◆ m_seen_options

OptionSet lldb_private::Options::m_seen_options
protected

The documentation for this class was generated from the following files: