22#include "llvm/ADT/ScopeExit.h"
44 llvm::StringRef name, llvm::StringRef help,
45 llvm::StringRef syntax, uint32_t flags)
46 : m_interpreter(interpreter), m_cmd_name(std::string(name)),
47 m_flags(flags), m_deprecated_command_override_callback(nullptr),
48 m_command_override_callback(nullptr), m_command_override_baton(nullptr) {
109 if (options !=
nullptr) {
115 const bool require_validation =
true;
116 llvm::Expected<Args> args_or = options->
Parse(
121 args = std::move(*args_or);
124 error = args_or.takeError();
126 if (
error.Success()) {
130 const char *error_cstr =
error.AsCString();
164 if (flags & (eCommandRequiresTarget | eCommandRequiresProcess |
165 eCommandRequiresThread | eCommandRequiresFrame |
166 eCommandTryTargetAPILock)) {
203 if ((flags & eCommandRequiresRegContext) &&
209 if (flags & eCommandTryTargetAPILock) {
213 std::unique_lock<std::recursive_mutex>(target->
GetAPIMutex());
217 if (
GetFlags().AnySet(eCommandProcessMustBeLaunched |
218 eCommandProcessMustBePaused)) {
220 if (process ==
nullptr) {
222 if (
GetFlags().Test(eCommandProcessMustBeLaunched)) {
241 if (
GetFlags().Test(eCommandProcessMustBeLaunched)) {
249 if (
GetFlags().Test(eCommandProcessMustBePaused)) {
250 result.
AppendError(
"Process is running. Use 'process interrupt' to "
258 if (
GetFlags().Test(eCommandProcessMustBeTraced)) {
260 if (target && !target->
GetTrace()) {
261 result.
AppendError(
"Process is not being traced.");
278 auto reset_ctx = llvm::make_scope_exit([
this]() {
Cleanup(); });
293 if (cur_options !=
nullptr) {
299 if (handled_by_options)
309 bool search_short_help,
310 bool search_long_help,
312 bool search_options) {
313 std::string options_usage_help;
315 bool found_word =
false;
317 llvm::StringRef short_help =
GetHelp();
319 llvm::StringRef syntax_help =
GetSyntax();
321 if (search_short_help && short_help.contains_insensitive(search_word))
323 else if (search_long_help && long_help.contains_insensitive(search_word))
325 else if (search_syntax && syntax_help.contains_insensitive(search_word))
328 if (!found_word && search_options &&
GetOptions() !=
nullptr) {
333 if (!usage_help.
Empty()) {
334 llvm::StringRef usage_text = usage_help.
GetString();
335 if (usage_text.contains_insensitive(search_word))
397 help_text, name_str.
GetSize());
408 if (!enum_values.empty()) {
413 std::max(longest, llvm::StringRef(element.string_value).size());
418 element.usage, longest);
454 for (
unsigned i = 0; i < cmd_arg_entry.size(); ++i)
455 if (opt_set_mask & cmd_arg_entry[i].arg_opt_set_association)
456 ret_val.push_back(cmd_arg_entry[i]);
465 uint32_t opt_set_mask) {
467 for (
int i = 0; i < num_args; ++i) {
475 if (arg_entry.empty())
477 int num_alternatives = arg_entry.size();
479 if ((num_alternatives == 2) &&
IsPairType(arg_entry[0].arg_repetition)) {
482 switch (arg_entry[0].arg_repetition) {
484 str.
Printf(
"<%s> <%s>", first_name, second_name);
487 str.
Printf(
"[<%s> <%s>]", first_name, second_name);
490 str.
Printf(
"<%s> <%s> [<%s> <%s> [...]]", first_name, second_name,
491 first_name, second_name);
494 str.
Printf(
"[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name,
495 first_name, second_name);
498 str.
Printf(
"<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name,
499 first_name, second_name);
502 str.
Printf(
"[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name,
503 first_name, second_name);
518 for (
int j = 0; j < num_alternatives; ++j) {
524 std::string name_str = std::string(names.
GetString());
525 switch (arg_entry[0].arg_repetition) {
527 str.
Printf(
"<%s>", name_str.c_str());
530 str.
Printf(
"<%s> [<%s> [...]]", name_str.c_str(), name_str.c_str());
533 str.
Printf(
"[<%s> [<%s> [...]]]", name_str.c_str(), name_str.c_str());
536 str.
Printf(
"[<%s>]", name_str.c_str());
539 str.
Printf(
"<%s_1> .. <%s_n>", name_str.c_str(), name_str.c_str());
562 arg_name = arg_name.ltrim(
'<').rtrim(
'>');
572 llvm::StringRef long_help) {
574 std::stringstream lineStream{std::string(long_help)};
576 while (std::getline(lineStream, line)) {
581 size_t result = line.find_first_not_of(
" \t");
582 if (result == std::string::npos) {
585 std::string whitespace_prefix = line.substr(0, result);
586 std::string remainder = line.substr(result);
600 std::string help_text(
GetHelp());
602 help_text.append(
" Expects 'raw' input (see 'help raw-input'.)");
605 output_strm <<
"\nSyntax: " <<
GetSyntax() <<
"\n";
607 if (options !=
nullptr) {
613 if (!long_help.empty()) {
623 "\nImportant Note: Because this command takes 'raw' input, if you "
624 "use any command options"
625 " you must use ' -- ' between the end of the command options and the "
626 "beginning of the raw input.",
633 "\nThis command takes options and free-form arguments. If your "
635 " option specifiers (i.e., they start with a - or --), you must use "
637 " the end of the command options and the beginning of the arguments.",
662 arg.push_back(id_arg);
663 arg.push_back(id_range_arg);
669 "Invalid argument type passed to GetArgumentTypeAsCString");
676 "Invalid argument type passed to GetArgumentDescriptionAsCString");
689 assert(
m_flags.
AnySet(eCommandRequiresTarget | eCommandProcessMustBePaused |
690 eCommandProcessMustBeLaunched | eCommandRequiresFrame |
691 eCommandRequiresThread | eCommandRequiresProcess |
692 eCommandRequiresRegContext) &&
693 "GetSelectedTarget called from object that may have no target");
700 return thread_to_use;
720 bool handled =
false;
721 Args cmd_args(args_string);
729 for (
auto entry : llvm::enumerate(cmd_args.
entries())) {
733 std::string opt_string = value.
c_str();
762 bool handled =
false;
766 full_command += args_string;
767 const char *argv[2] = {
nullptr,
nullptr};
768 argv[0] = full_command.c_str();
773 handled =
DoExecute(args_string, result);
static CommandObject::CommandArgumentEntry OptSetFiltered(uint32_t opt_set_mask, CommandObject::CommandArgumentEntry &cmd_arg_entry)
static llvm::raw_ostream & error(Stream &strm)
A command line argument class.
void AppendArguments(const Args &rhs)
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
void ReplaceArgumentAtIndex(size_t idx, llvm::StringRef arg_str, char quote_char='\0')
Replaces the argument value at index idx to arg_str if idx is a valid argument index.
llvm::ArrayRef< ArgEntry > entries() const
const char ** GetConstArgumentVector() const
Gets the argument vector.
void OutputFormattedHelpText(Stream &strm, llvm::StringRef prefix, llvm::StringRef help_text)
ExecutionContext GetExecutionContext() const
void OutputHelpText(Stream &stream, llvm::StringRef command_word, llvm::StringRef separator, llvm::StringRef help_text, uint32_t max_word_len)
Status PreprocessToken(std::string &token)
bool Execute(const char *args_string, CommandReturnObject &result) override
virtual bool DoExecute(Args &command, CommandReturnObject &result)=0
virtual bool DoExecute(llvm::StringRef command, CommandReturnObject &result)=0
bool Execute(const char *args_string, CommandReturnObject &result) override
std::vector< CommandArgumentData > CommandArgumentEntry
CommandArgumentEntry * GetArgumentEntryAtIndex(int idx)
virtual void SetHelpLong(llvm::StringRef str)
virtual bool WantsRawCommandString()=0
void GenerateHelpText(CommandReturnObject &result)
std::unique_lock< std::recursive_mutex > m_api_locker
bool HasOverrideCallback() const
static void AddIDsArgumentData(CommandArgumentEntry &arg, lldb::CommandArgumentType ID, lldb::CommandArgumentType IDRange)
bool ParseOptionsAndNotify(Args &args, CommandReturnObject &result, OptionGroupOptions &group_options, ExecutionContext &exe_ctx)
virtual const char * GetInvalidProcessDescription()
virtual llvm::StringRef GetHelpLong()
static const ArgumentTableEntry * FindArgumentDataByType(lldb::CommandArgumentType arg_type)
llvm::StringRef GetCommandName() const
Target & GetDummyTarget()
static lldb::CommandArgumentType LookupArgumentName(llvm::StringRef arg_name)
void GetFormattedCommandArguments(Stream &str, uint32_t opt_set_mask=LLDB_OPT_SET_ALL)
bool HelpTextContainsWord(llvm::StringRef search_word, bool search_short_help=true, bool search_long_help=true, bool search_syntax=true, bool search_options=true)
ExecutionContext m_exe_ctx
virtual const char * GetInvalidTargetDescription()
std::vector< CommandArgumentEntry > m_arguments
virtual void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector)
The input array contains a parsed version of the line.
virtual bool WantsCompletion()
CommandInterpreter & GetCommandInterpreter()
virtual bool IsDashDashCommand()
Target & GetSelectedTarget()
static const char * GetArgumentTypeAsCString(const lldb::CommandArgumentType arg_type)
CommandInterpreter & m_interpreter
Thread * GetDefaultThread()
virtual const char * GetInvalidRegContextDescription()
std::string m_cmd_help_long
virtual Options * GetOptions()
void SetSyntax(llvm::StringRef str)
static const char * GetArgumentDescriptionAsCString(const lldb::CommandArgumentType arg_type)
CommandObject(CommandInterpreter &interpreter, llvm::StringRef name, llvm::StringRef help="", llvm::StringRef syntax="", uint32_t flags=0)
virtual const char * GetInvalidFrameDescription()
void SetCommandName(llvm::StringRef name)
Flags & GetFlags()
The flags accessor.
int GetNumArgumentEntries()
bool ParseOptions(Args &args, CommandReturnObject &result)
void FormatLongHelpText(Stream &output_strm, llvm::StringRef long_help)
virtual llvm::StringRef GetSyntax()
virtual const char * GetInvalidThreadDescription()
static void GetArgumentHelp(Stream &str, lldb::CommandArgumentType arg_type, CommandInterpreter &interpreter)
bool CheckRequirements(CommandReturnObject &result)
Check the command to make sure anything required by this command is available.
virtual void HandleCompletion(CompletionRequest &request)
This default version handles calling option argument completions and then calls HandleArgumentComplet...
bool IsPairType(ArgumentRepetitionType arg_repeat_type)
Target & GetSelectedOrDummyTarget(bool prefer_dummy=false)
static const char * GetArgumentName(lldb::CommandArgumentType arg_type)
virtual llvm::StringRef GetHelp()
std::string m_cmd_help_short
bool InvokeOverrideCallback(const char **argv, CommandReturnObject &result)
virtual void SetHelp(llvm::StringRef str)
void AppendErrorWithFormatv(const char *format, Args &&... args)
void void AppendError(llvm::StringRef in_string)
Stream & GetErrorStream()
void SetStatus(lldb::ReturnStatus status)
Stream & GetOutputStream()
"lldb/Utility/ArgCompletionRequest.h"
const Args & GetParsedLine() const
size_t GetCursorIndex() const
A class to manage flag bits.
lldb::TargetSP GetSelectedTarget()
Target & GetDummyTarget()
Target & GetSelectedOrDummyTarget(bool prefer_dummy=false)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool HasThreadScope() const
Returns true the ExecutionContext object contains a valid target, process, and thread.
bool HasProcessScope() const
Returns true the ExecutionContext object contains a valid target and process.
void Clear()
Clear the object's state.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
Target * GetTargetPtr() const
Returns a pointer to the target object.
bool HasTargetScope() const
Returns true the ExecutionContext object contains a valid target.
bool HasFrameScope() const
Returns true the ExecutionContext object contains a valid target, process, thread and frame.
Process * GetProcessPtr() const
Returns a pointer to the process object.
RegisterContext * GetRegisterContext() const
Thread * GetThreadPtr() const
Returns a pointer to the thread object.
ValueType Get() const
Get accessor for all flags.
bool AnySet(ValueType mask) const
Test one or more flags.
A command line option parsing protocol class.
bool VerifyOptions(CommandReturnObject &result)
void GenerateOptionUsage(Stream &strm, CommandObject &cmd, uint32_t screen_width)
uint32_t NumCommandOptions()
Status NotifyOptionParsingFinished(ExecutionContext *execution_context)
void NotifyOptionParsingStarting(ExecutionContext *execution_context)
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.
llvm::Expected< Args > Parse(const Args &args, ExecutionContext *execution_context, lldb::PlatformSP platform_sp, bool require_validation)
Parse the provided arguments.
OptionElementVector ParseForCompletion(const Args &args, uint32_t cursor_index)
A plug-in interface definition class for debugging a process.
ThreadList & GetThreadList()
lldb::StateType GetState()
Get accessor for the current process state.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t EOL()
Output and End of Line character to the stream.
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
void IndentMore(unsigned amount=2)
Increment the current indentation level.
lldb::TraceSP GetTrace()
Get the Trace object containing processor trace information of this target.
const lldb::ProcessSP & GetProcessSP() const
std::recursive_mutex & GetAPIMutex()
lldb::ThreadSP GetSelectedThread()
A class that represents a running process on the host machine.
std::vector< OptionArgElement > OptionElementVector
@ eArgRepeatPairRangeOptional
llvm::ArrayRef< OptionEnumValueElement > OptionEnumValues
static constexpr CommandObject::ArgumentTableEntry g_argument_table[]
StateType
Process and Thread States.
@ eStateUnloaded
Process is object is valid, but not currently loaded.
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
@ eStateDetached
Process has been detached and can't be examined.
@ eStateStopped
Process or thread is stopped and can be examined.
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
@ eStateRunning
Process or thread is running and can't be examined.
@ eStateLaunching
Process is in the process of launching.
@ eStateAttaching
Process is currently trying to attach.
@ eStateExited
Process has exited and can't be examined.
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
@ eStateCrashed
Process or thread has crashed and can be examined.
@ eReturnStatusSuccessFinishNoResult
const char * c_str() const
llvm::StringRef ref() const
char GetQuoteChar() const
Entries in the main argument information table.
lldb::CommandArgumentType arg_type
OptionEnumValues enum_values
ArgumentHelpCallback help_function
Used to build individual command argument lists.
ArgumentRepetitionType arg_repetition
lldb::CommandArgumentType arg_type