43 const char *help =
nullptr,
44 const char *syntax =
nullptr,
46 const char *auto_repeat_command =
"")
50 auto_repeat_command ==
nullptr
52 : std::optional<std::string>(auto_repeat_command);
66 uint32_t index)
override {
80 std::shared_ptr<lldb::SBCommandPluginInterface>
m_backend;
90 : m_opaque_ptr(interpreter) {
95 : m_opaque_ptr(rhs.m_opaque_ptr) {
111 return this->
operator bool();
113SBCommandInterpreter::operator bool()
const {
116 return m_opaque_ptr !=
nullptr;
172 bool add_to_history) {
176 return HandleCommand(command_line, sb_exe_ctx, result, add_to_history);
186 if (command_line &&
IsValid()) {
189 if (override_context.
get())
191 override_context.
get()->
Lock(
true),
198 "SBCommandInterpreter or the command line is not valid");
211 result->
AppendError(
"SBCommandInterpreter is not valid.");
222 if (override_context.
get())
224 override_context.
get()->
Lock(
true),
233 const char *current_line,
const char *cursor,
const char *last_char,
234 int match_start_point,
int max_return_elements,
SBStringList &matches) {
236 max_return_elements, matches);
240 current_line, cursor, last_char, match_start_point, max_return_elements,
241 matches, dummy_descriptions);
245 const char *current_line,
const char *cursor,
const char *last_char,
246 int match_start_point,
int max_return_elements,
SBStringList &matches,
249 max_return_elements, matches, descriptions);
253 if (current_line ==
nullptr || cursor ==
nullptr || last_char ==
nullptr)
256 if (cursor < current_line || last_char < current_line)
259 size_t current_line_size = strlen(current_line);
260 if (cursor - current_line >
static_cast<ptrdiff_t
>(current_line_size) ||
261 last_char - current_line >
static_cast<ptrdiff_t
>(current_line_size))
286 const size_t partial_name_len = command_partial_str.size();
287 common_prefix.erase(0, partial_name_len);
291 if (lldb_matches.
GetSize() == 1) {
296 common_prefix.push_back(quote_char);
297 common_prefix.push_back(
' ');
305 SBStringList temp_descriptions_list(&lldb_descriptions);
306 descriptions.
AppendList(temp_descriptions_list);
311 const char *current_line, uint32_t cursor_pos,
int match_start_point,
315 max_return_elements, matches, descriptions);
317 const char *cursor = current_line + cursor_pos;
318 const char *last_char = current_line + strlen(current_line);
320 current_line, cursor, last_char, match_start_point, max_return_elements,
321 matches, descriptions);
326 int match_start_point,
327 int max_return_elements,
330 max_return_elements, matches);
332 const char *cursor = current_line + cursor_pos;
333 const char *last_char = current_line + strlen(current_line);
335 max_return_elements, matches);
370 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
371 process_sp = target_sp->GetProcessSP();
372 sb_process.
SetSP(process_sp);
430 if (command_line &&
IsValid()) {
434 "SBCommandInterpreter or the command line is not valid");
457 std::unique_lock<std::recursive_mutex> lock;
459 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
462 result->
AppendError(
"SBCommandInterpreter is not valid");
480 std::unique_lock<std::recursive_mutex> lock;
482 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
485 result->
AppendError(
"SBCommandInterpreter is not valid");
496 std::unique_lock<std::recursive_mutex> lock;
498 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
501 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());
569 std::string json_str =
596 new_command_sp->GetAsMultiwordCommand()->SetRemovable(
true);
614 const char *help,
const char *syntax) {
616 return AddCommand(name, impl, help, syntax,
"");
621 const char *syntax,
const char *auto_repeat_command) {
625 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
627 auto_repeat_command);
641 return this->
operator bool();
643SBCommand::operator bool()
const {
646 return m_opaque_sp.get() !=
nullptr;
695 if (new_command_sp &&
m_opaque_sp->LoadSubCommand(name, new_command_sp))
710 const char *help,
const char *syntax) {
712 return AddCommand(name, impl, help, syntax,
"");
717 const char *help,
const char *syntax,
718 const char *auto_repeat_command) {
726 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
727 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax,
728 0, auto_repeat_command);
729 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()
SBStructuredData GetStatistics()
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...
SBStructuredData GetTranscript()
Returns a list of handled commands, output and error.
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)
StructuredDataImplUP m_impl_up
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 "~/....
llvm::json::Value GetStatistics()
static llvm::StringRef GetStaticBroadcasterClass()
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
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)
const StructuredData::Array & GetTranscript() const
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,...
void 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()
static ObjectSP ParseJSON(llvm::StringRef json_text)
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.