22#include "llvm/ADT/ScopeExit.h"
44class DoExecuteStatusCheck {
46 explicit DoExecuteStatusCheck(CommandReturnObject &result)
50 ~DoExecuteStatusCheck() {
52 "DoExecute did not set a status on the CommandReturnObject");
56 CommandReturnObject &m_result;
63 llvm::StringRef name, llvm::StringRef help,
64 llvm::StringRef syntax, uint32_t flags)
128 if (options !=
nullptr) {
134 const bool require_validation =
true;
135 llvm::Expected<Args> args_or = options->
Parse(
140 args = std::move(*args_or);
175 m_exe_ctx.GetTargetPtr()->IsDummyTarget());
186 const bool adopt_dummy_target = flags & eCommandAllowsDummyTarget;
189 if (flags & (eCommandRequiresTarget | eCommandRequiresProcess |
190 eCommandRequiresThread | eCommandRequiresFrame |
191 eCommandTryTargetAPILock)) {
194 if ((flags & eCommandRequiresTarget) &&
200 if ((flags & eCommandRequiresProcess) && !
m_exe_ctx.HasProcessScope()) {
208 if ((flags & eCommandRequiresThread) && !
m_exe_ctx.HasThreadScope()) {
218 if ((flags & eCommandRequiresFrame) && !
m_exe_ctx.HasFrameScope()) {
230 if ((flags & eCommandRequiresRegContext) &&
231 (
m_exe_ctx.GetRegisterContext() ==
nullptr)) {
236 if (flags & eCommandTryTargetAPILock) {
239 std::unique_lock<std::recursive_mutex>(target->
GetAPIMutex());
243 if (
GetFlags().AnySet(eCommandProcessMustBeLaunched |
244 eCommandProcessMustBePaused)) {
246 if (process ==
nullptr) {
248 if (
GetFlags().Test(eCommandProcessMustBeLaunched)) {
267 if (
GetFlags().Test(eCommandProcessMustBeLaunched)) {
275 if (
GetFlags().Test(eCommandProcessMustBePaused)) {
276 result.
AppendError(
"Process is running. Use 'process interrupt' to "
284 if (
GetFlags().Test(eCommandProcessMustBeTraced)) {
286 if (target && !target->
GetTrace()) {
304 llvm::scope_exit reset_ctx([
this]() {
Cleanup(); });
318 if (cur_options !=
nullptr) {
324 if (handled_by_options)
336 if (num_arg_entries != 1)
341 assert(entry_ptr &&
"We said there was one entry, but there wasn't.");
347 if (entry.size() != 1)
370 bool search_short_help,
371 bool search_long_help,
373 bool search_options) {
374 bool found_word =
false;
376 llvm::StringRef short_help =
GetHelp();
378 llvm::StringRef syntax_help =
GetSyntax();
380 if (search_short_help && short_help.contains_insensitive(search_word))
382 else if (search_long_help && long_help.contains_insensitive(search_word))
384 else if (search_syntax && syntax_help.contains_insensitive(search_word))
387 if (!found_word && search_options &&
GetOptions() !=
nullptr) {
393 if (!usage_help.
Empty()) {
394 llvm::StringRef usage_text = usage_help.
GetString();
395 if (usage_text.contains_insensitive(search_word))
430 arg_entry.push_back(simple_arg);
475 help_text, name_str.
GetSize());
486 if (!enum_values.empty()) {
491 std::max(longest, llvm::StringRef(element.string_value).size());
496 element.usage, longest);
528std::optional<ArgumentRepetitionType>
530 return llvm::StringSwitch<ArgumentRepetitionType>(
string)
549 for (
unsigned i = 0; i < cmd_arg_entry.size(); ++i)
550 if (opt_set_mask & cmd_arg_entry[i].arg_opt_set_association)
551 ret_val.push_back(cmd_arg_entry[i]);
560 uint32_t opt_set_mask) {
562 for (
int i = 0; i < num_args; ++i) {
570 if (arg_entry.empty())
572 int num_alternatives = arg_entry.size();
574 if ((num_alternatives == 2) &&
IsPairType(arg_entry[0].arg_repetition)) {
577 switch (arg_entry[0].arg_repetition) {
579 str.
Printf(
"<%s> <%s>", first_name, second_name);
582 str.
Printf(
"[<%s> <%s>]", first_name, second_name);
585 str.
Printf(
"<%s> <%s> [<%s> <%s> [...]]", first_name, second_name,
586 first_name, second_name);
589 str.
Printf(
"[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name,
590 first_name, second_name);
593 str.
Printf(
"<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name,
594 first_name, second_name);
597 str.
Printf(
"[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name,
598 first_name, second_name);
613 for (
int j = 0; j < num_alternatives; ++j) {
619 std::string name_str = std::string(names.
GetString());
620 switch (arg_entry[0].arg_repetition) {
622 str.
Printf(
"<%s>", name_str.c_str());
625 str.
Printf(
"<%s> [<%s> [...]]", name_str.c_str(), name_str.c_str());
628 str.
Printf(
"[<%s> [<%s> [...]]]", name_str.c_str(), name_str.c_str());
631 str.
Printf(
"[<%s>]", name_str.c_str());
634 str.
Printf(
"<%s_1> .. <%s_n>", name_str.c_str(), name_str.c_str());
657 arg_name = arg_name.ltrim(
'<').rtrim(
'>');
667 llvm::StringRef long_help) {
669 std::stringstream lineStream{std::string(long_help)};
671 while (std::getline(lineStream, line)) {
676 size_t result = line.find_first_not_of(
" \t");
677 if (result == std::string::npos) {
680 std::string whitespace_prefix = line.substr(0, result);
681 std::string remainder = line.substr(result);
695 std::string help_text(
GetHelp());
697 help_text.append(
" Expects 'raw' input (see 'help raw-input'.)");
700 output_strm <<
"\nSyntax: " <<
GetSyntax() <<
"\n";
702 if (options !=
nullptr) {
709 if (!long_help.empty()) {
719 "\nImportant Note: Because this command takes 'raw' input, if you "
720 "use any command options"
721 " you must use ' -- ' between the end of the command options and the "
722 "beginning of the raw input.",
729 "\nThis command takes options and free-form arguments. If your "
731 " option specifiers (i.e., they start with a - or --), you must use "
733 " the end of the command options and the beginning of the arguments.",
762 arg.push_back(id_arg);
763 arg.push_back(id_range_arg);
770 "Invalid argument type passed to GetArgumentTypeAsCString");
777 "Invalid argument type passed to GetArgumentDescriptionAsCString");
792 const bool adopt_dummy_target = flags & eCommandAllowsDummyTarget;
796 m_interpreter.GetExecutionContext(adopt_dummy_target).GetTargetPtr();
800 assert(target || !(flags & (eCommandRequiresTarget | eCommandRequiresProcess |
801 eCommandRequiresThread | eCommandRequiresFrame)));
808 return thread_to_use;
828 bool handled =
false;
829 Args cmd_args(args_string);
837 for (
auto entry : llvm::enumerate(cmd_args.
entries())) {
841 std::string opt_string = value.
c_str();
860 DoExecuteStatusCheck check(result);
871 bool handled =
false;
875 full_command += args_string;
876 const char *argv[2] = {
nullptr,
nullptr};
877 argv[0] = full_command.c_str();
882 DoExecuteStatusCheck check(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.
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
void OutputFormattedHelpText(Stream &strm, llvm::StringRef prefix, llvm::StringRef help_text, std::optional< Stream::HighlightSettings > highlight=std::nullopt)
void OutputHelpText(Stream &stream, llvm::StringRef command_word, llvm::StringRef separator, llvm::StringRef help_text, uint32_t max_word_len)
ExecutionContext GetExecutionContext(bool adopt_dummy_target=true) const
Returns the execution context the interpreter should run a command in.
virtual void DoExecute(Args &command, CommandReturnObject &result)=0
void Execute(const char *args_string, CommandReturnObject &result) override
void Execute(const char *args_string, CommandReturnObject &result) override
virtual void DoExecute(llvm::StringRef command, CommandReturnObject &result)=0
std::vector< CommandArgumentData > CommandArgumentEntry
CommandArgumentEntry * GetArgumentEntryAtIndex(int idx)
virtual void SetHelpLong(llvm::StringRef str)
virtual bool WantsRawCommandString()=0
void GenerateHelpText(CommandReturnObject &result)
lldb::CommandOverrideCallback m_deprecated_command_override_callback
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
std::unique_lock< std::recursive_mutex > m_api_locker
bool HasOverrideCallback() const
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
static std::optional< ArgumentRepetitionType > ArgRepetitionFromString(llvm::StringRef string)
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 bool WantsCompletion()
lldb_private::CommandOverrideCallbackWithResult m_command_override_callback
void AddIDsArgumentData(IDType type)
CommandInterpreter & GetCommandInterpreter()
virtual bool IsDashDashCommand()
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()
virtual void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector)
The default version handles argument definitions that have only one argument type,...
bool ParseOptions(Args &args, CommandReturnObject &result)
void FormatLongHelpText(Stream &output_strm, llvm::StringRef long_help)
Target * GetTarget()
Get the target this command should operate on.
virtual llvm::StringRef GetSyntax()
virtual const char * GetInvalidThreadDescription()
void * m_command_override_baton
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...
static bool IsPairType(ArgumentRepetitionType arg_repeat_type)
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 AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void SetError(Status error)
void AppendErrorWithFormatv(const char *format, Args &&...args)
Stream & GetOutputStream()
"lldb/Utility/ArgCompletionRequest.h"
const Args & GetParsedLine() const
size_t GetCursorIndex() const
A class to manage flag bits.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ValueType Get() const
Get accessor for all flags.
A command line option parsing protocol class.
void GenerateOptionUsage(Stream &strm, CommandObject &cmd, uint32_t screen_width, bool use_color)
llvm::Error VerifyOptions()
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.
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
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()
bool IsDummyTarget() const
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
@ eArgTypeBreakpointIDRange
@ eArgTypeWatchpointIDRange
const char * c_str() const
llvm::StringRef ref() const
char GetQuoteChar() const
Entries in the main argument information table.
lldb::CompletionType completion_type
lldb::CommandArgumentType arg_type
ArgumentHelpCallback help_function
Used to build individual command argument lists.
ArgumentRepetitionType arg_repetition
lldb::CommandArgumentType arg_type