42 const char *help =
nullptr,
43 const char *syntax =
nullptr,
45 const char *auto_repeat_command =
"")
49 auto_repeat_command ==
nullptr
51 : std::optional<std::string>(auto_repeat_command);
65 uint32_t index)
override {
81 std::shared_ptr<lldb::SBCommandPluginInterface>
m_backend;
91 : m_opaque_ptr(interpreter) {
96 : m_opaque_ptr(rhs.m_opaque_ptr) {
112 return this->
operator bool();
114SBCommandInterpreter::operator bool()
const {
117 return m_opaque_ptr !=
nullptr;
173 bool add_to_history) {
177 return HandleCommand(command_line, sb_exe_ctx, result, add_to_history);
187 if (command_line &&
IsValid()) {
190 if (override_context.
get())
192 override_context.
get()->
Lock(
true),
199 "SBCommandInterpreter or the command line is not valid");
212 result->
AppendError(
"SBCommandInterpreter is not valid.");
223 if (override_context.
get())
225 override_context.
get()->
Lock(
true),
234 const char *current_line,
const char *cursor,
const char *last_char,
235 int match_start_point,
int max_return_elements,
SBStringList &matches) {
237 max_return_elements, matches);
241 current_line, cursor, last_char, match_start_point, max_return_elements,
242 matches, dummy_descriptions);
246 const char *current_line,
const char *cursor,
const char *last_char,
247 int match_start_point,
int max_return_elements,
SBStringList &matches,
250 max_return_elements, matches, descriptions);
254 if (current_line ==
nullptr || cursor ==
nullptr || last_char ==
nullptr)
257 if (cursor < current_line || last_char < current_line)
260 size_t current_line_size = strlen(current_line);
261 if (cursor - current_line >
static_cast<ptrdiff_t
>(current_line_size) ||
262 last_char - current_line >
static_cast<ptrdiff_t
>(current_line_size))
287 const size_t partial_name_len = command_partial_str.size();
288 common_prefix.erase(0, partial_name_len);
292 if (lldb_matches.
GetSize() == 1) {
297 common_prefix.push_back(quote_char);
298 common_prefix.push_back(
' ');
306 SBStringList temp_descriptions_list(&lldb_descriptions);
307 descriptions.
AppendList(temp_descriptions_list);
312 const char *current_line, uint32_t cursor_pos,
int match_start_point,
316 max_return_elements, matches, descriptions);
318 const char *cursor = current_line + cursor_pos;
319 const char *last_char = current_line + strlen(current_line);
321 current_line, cursor, last_char, match_start_point, max_return_elements,
322 matches, descriptions);
327 int match_start_point,
328 int max_return_elements,
331 max_return_elements, matches);
333 const char *cursor = current_line + cursor_pos;
334 const char *last_char = current_line + strlen(current_line);
336 max_return_elements, matches);
371 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
372 process_sp = target_sp->GetProcessSP();
373 sb_process.
SetSP(process_sp);
431 if (command_line &&
IsValid()) {
435 "SBCommandInterpreter or the command line is not valid");
458 std::unique_lock<std::recursive_mutex> lock;
460 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
463 result->
AppendError(
"SBCommandInterpreter is not valid");
481 std::unique_lock<std::recursive_mutex> lock;
483 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
486 result->
AppendError(
"SBCommandInterpreter is not valid");
497 std::unique_lock<std::recursive_mutex> lock;
499 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
502 result->
AppendError(
"SBCommandInterpreter is not valid");
540 return event.GetBroadcasterClass() ==
549 if (command_name && command_name[0] &&
IsValid()) {
550 llvm::StringRef command_name_str = command_name;
554 assert(command_name_str.empty());
568 new_command_sp->GetAsMultiwordCommand()->SetRemovable(
true);
586 const char *help,
const char *syntax) {
588 return AddCommand(name, impl, help, syntax,
"");
593 const char *syntax,
const char *auto_repeat_command) {
597 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
599 auto_repeat_command);
613 return this->
operator bool();
615SBCommand::operator bool()
const {
618 return m_opaque_sp.get() !=
nullptr;
667 if (new_command_sp &&
m_opaque_sp->LoadSubCommand(name, new_command_sp))
682 const char *help,
const char *syntax) {
684 return AddCommand(name, impl, help, syntax,
"");
689 const char *help,
const char *syntax,
690 const char *auto_repeat_command) {
698 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
699 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax,
700 0, auto_repeat_command);
701 if (new_command_sp &&
m_opaque_sp->LoadSubCommand(name, new_command_sp))
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
lldb_private::CommandInterpreterRunOptions & ref() const
lldb::SBCommand AddMultiwordCommand(const char *name, const char *help)
const lldb::SBCommandInterpreter & operator=(const lldb::SBCommandInterpreter &rhs)
lldb::SBProcess GetProcess()
lldb_private::CommandInterpreter & ref()
void ResolveCommand(const char *command_line, SBCommandReturnObject &result)
Resolve the command just as HandleCommand would, expanding abbreviations and aliases.
lldb::SBDebugger GetDebugger()
static const char * GetBroadcasterClass()
const char * GetIOHandlerControlSequence(char ch)
Get the string that needs to be written to the debugger stdin file handle when a control character is...
lldb::SBCommand AddCommand(const char *name, lldb::SBCommandPluginInterface *impl, const char *help)
Add a new command to the lldb::CommandInterpreter.
void AllowExitCodeOnQuit(bool allow)
Sets whether the command interpreter should allow custom exit codes for the 'quit' command.
bool AliasExists(const char *cmd)
Return whether the passed in name or command path exists and is an alias to some other command.
bool IsActive()
Return true if the command interpreter is the active IO handler.
static const char * GetArgumentDescriptionAsCString(const lldb::CommandArgumentType arg_type)
int HandleCompletion(const char *current_line, const char *cursor, const char *last_char, int match_start_point, int max_return_elements, lldb::SBStringList &matches)
void reset(lldb_private::CommandInterpreter *)
static const char * GetArgumentTypeAsCString(const lldb::CommandArgumentType arg_type)
bool SetCommandOverrideCallback(const char *command_name, lldb::CommandOverrideCallback callback, void *baton)
bool WasInterrupted() const
Returns whether an interrupt flag was raised either by the SBDebugger - when the function is not runn...
void SourceInitFileInCurrentWorkingDirectory(lldb::SBCommandReturnObject &result)
bool UserCommandExists(const char *cmd)
Return whether a user defined command with the passed in name or command path exists.
bool InterruptCommand()
Interrupts the command currently executing in the RunCommandInterpreter thread.
void SourceInitFileInHomeDirectory(lldb::SBCommandReturnObject &result)
lldb_private::CommandInterpreter * m_opaque_ptr
void HandleCommandsFromFile(lldb::SBFileSpec &file, lldb::SBExecutionContext &override_context, lldb::SBCommandInterpreterRunOptions &options, lldb::SBCommandReturnObject result)
lldb_private::CommandInterpreter * get()
bool HasCustomQuitExitCode()
Returns true if the user has called the 'quit' command with a custom exit code.
int HandleCompletionWithDescriptions(const char *current_line, const char *cursor, const char *last_char, int match_start_point, int max_return_elements, lldb::SBStringList &matches, lldb::SBStringList &descriptions)
void SourceInitFileInGlobalDirectory(lldb::SBCommandReturnObject &result)
void SetPromptOnQuit(bool b)
bool CommandExists(const char *cmd)
Return whether a built-in command with the passed in name or command path exists.
lldb::ReturnStatus HandleCommand(const char *command_line, lldb::SBCommandReturnObject &result, bool add_to_history=false)
lldb::SBBroadcaster GetBroadcaster()
int GetQuitStatus()
Returns the exit code that the user has specified when running the 'quit' command.
static bool EventIsCommandInterpreterEvent(const lldb::SBEvent &event)
lldb::ReturnStatus GetStatus()
lldb_private::CommandReturnObject & ref() const
const char * GetHelpLong()
lldb::CommandObjectSP m_opaque_sp
lldb::SBCommand AddMultiwordCommand(const char *name, const char *help=nullptr)
void SetHelpLong(const char *)
void SetFlags(uint32_t flags)
lldb::SBCommand AddCommand(const char *name, lldb::SBCommandPluginInterface *impl, const char *help=nullptr)
Add a new subcommand to the lldb::SBCommand.
void SetHelp(const char *)
void reset(const lldb::DebuggerSP &debugger_sp)
lldb_private::ExecutionContextRef * get() const
const lldb_private::FileSpec & ref() const
bool GetDescription(lldb::SBStream &description) const
void SetSP(const lldb::ProcessSP &process_sp)
void AppendList(const char **strv, int strc)
A command line argument class.
char ** GetArgumentVector()
Gets the argument vector.
static std::string EscapeLLDBCommandArgument(const std::string &arg, char quote_char)
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
void SetPromptOnQuit(bool enable)
void SourceInitFileHome(CommandReturnObject &result, bool is_repl)
We will first see if there is an application specific ".lldbinit" file whose name is "~/....
bool HasAliasOptions() const
void HandleCompletion(CompletionRequest &request)
void ResolveCommand(const char *command_line, CommandReturnObject &result)
bool HandleCommand(const char *command_line, LazyBool add_to_history, const ExecutionContext &override_context, CommandReturnObject &result)
void SourceInitFileGlobal(CommandReturnObject &result)
Status AddUserCommand(llvm::StringRef name, const lldb::CommandObjectSP &cmd_sp, bool can_replace)
bool AliasExists(llvm::StringRef cmd) const
Determine whether an alias command with this name exists.
bool CommandExists(llvm::StringRef cmd) const
Determine whether a root level, built-in command with this name exists.
bool GetPromptOnQuit() const
static ConstString & GetStaticBroadcasterClass()
int GetQuitExitCode(bool &exited) const
Returns the exit code that the user has specified when running the 'quit' command.
CommandObject * GetCommandObjectForCommand(llvm::StringRef &command_line)
bool UserCommandExists(llvm::StringRef cmd) const
Determine whether a root-level user command with this name exists.
void AllowExitCodeOnQuit(bool allow)
Specify if the command interpreter should allow that the user can specify a custom exit code when cal...
void HandleCommandsFromFile(FileSpec &file, const ExecutionContext &context, const CommandInterpreterRunOptions &options, CommandReturnObject &result)
Execute a list of commands from a file.
void SourceInitFileCwd(CommandReturnObject &result)
void SetRemovable(bool removable)
std::vector< CommandArgumentEntry > m_arguments
static const char * GetArgumentTypeAsCString(const lldb::CommandArgumentType arg_type)
CommandInterpreter & m_interpreter
void SetOverrideCallback(lldb::CommandOverrideCallback callback, void *baton)
static const char * GetArgumentDescriptionAsCString(const lldb::CommandArgumentType arg_type)
std::optional< std::string > GetRepeatCommand(Args ¤t_command_args, uint32_t index) override
More documentation is available in lldb::CommandObject::GetRepeatCommand, but in short,...
bool DoExecute(Args &command, CommandReturnObject &result) override
std::optional< std::string > m_auto_repeat_command
CommandPluginInterfaceImplementation(CommandInterpreter &interpreter, const char *name, lldb::SBCommandPluginInterface *backend, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0, const char *auto_repeat_command="")
std::shared_ptr< lldb::SBCommandPluginInterface > m_backend
bool IsRemovable() const override
void void AppendError(llvm::StringRef in_string)
void SetInteractive(bool b)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
"lldb/Utility/ArgCompletionRequest.h"
const Args & GetParsedLine() const
llvm::StringRef GetCursorArgumentPrefix() const
const Args::ArgEntry & GetParsedArg()
void GetDescriptions(StringList &descriptions) const
Adds all collected completion descriptions to the given list.
std::size_t GetNumberOfResults() const
void GetMatches(StringList &matches) const
Adds all collected completion matches to the given list.
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
const char * GetCString() const
Get the string value as a C string.
lldb::TargetSP GetSelectedTarget()
bool InterruptRequested(const char *cur_func, const char *formatv, Args &&...args)
This is the correct way to query the state of Interruption.
llvm::StringRef GetTopIOHandlerControlSequence(char ch)
ExecutionContext Lock(bool thread_and_frame_only_if_stopped) const
Create an ExecutionContext object from this object.
bool Success() const
Test for success condition.
void InsertStringAtIndex(size_t idx, const std::string &str)
std::string LongestCommonPrefix()
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
std::shared_ptr< lldb_private::Process > ProcessSP
ReturnStatus
Command Return Status Types.
bool(* CommandOverrideCallback)(void *baton, const char **argv)
std::shared_ptr< lldb_private::Target > TargetSP
bool IsQuoted() const
Returns true if this argument was quoted in any way.
char GetQuoteChar() const
Used to build individual command argument lists.