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 {
78 bool success =
m_backend->DoExecute(debugger_sb,
117 return this->
operator bool();
119SBCommandInterpreter::operator
bool()
const {
171 m_opaque_ptr->GetDebugger().GetTopIOHandlerControlSequence(ch))
178 bool add_to_history) {
182 return HandleCommand(command_line, sb_exe_ctx, result, add_to_history);
192 if (command_line &&
IsValid()) {
195 if (override_context.
get())
196 m_opaque_ptr->HandleCommand(command_line, do_add_to_history,
197 override_context.
get()->
Lock(
true),
200 m_opaque_ptr->HandleCommand(command_line, do_add_to_history,
204 "SBCommandInterpreter or the command line is not valid");
217 result->
AppendError(
"SBCommandInterpreter is not valid");
228 if (override_context.
get())
230 override_context.
get()->
Lock(
true),
231 options.
ref(), result.
ref());
238 const char *current_line,
const char *cursor,
const char *last_char,
239 int match_start_point,
int max_return_elements,
SBStringList &matches) {
241 max_return_elements, matches);
245 current_line, cursor, last_char, match_start_point, max_return_elements,
246 matches, dummy_descriptions);
250 const char *current_line,
const char *cursor,
const char *last_char,
251 int match_start_point,
int max_return_elements,
SBStringList &matches,
254 max_return_elements, matches, descriptions);
258 if (current_line ==
nullptr || cursor ==
nullptr || last_char ==
nullptr)
261 if (cursor < current_line || last_char < current_line)
264 size_t current_line_size = strlen(current_line);
265 if (cursor - current_line >
static_cast<ptrdiff_t
>(current_line_size) ||
266 last_char - current_line >
static_cast<ptrdiff_t
>(current_line_size))
272 if (max_return_elements == 0)
278 if (max_return_elements > 0)
285 if (max_return_elements > 0 &&
286 lldb_matches.
GetSize() >
static_cast<size_t>(max_return_elements)) {
287 lldb_matches.
SetSize(max_return_elements);
288 lldb_descriptions.
SetSize(max_return_elements);
290 int number_of_matches = lldb_matches.
GetSize();
304 const size_t partial_name_len = command_partial_str.size();
305 common_prefix.erase(0, partial_name_len);
309 if (lldb_matches.
GetSize() == 1) {
314 common_prefix.push_back(quote_char);
315 common_prefix.push_back(
' ');
323 SBStringList temp_descriptions_list(&lldb_descriptions);
324 descriptions.
AppendList(temp_descriptions_list);
325 return number_of_matches;
329 const char *current_line, uint32_t cursor_pos,
int match_start_point,
333 max_return_elements, matches, descriptions);
335 const char *cursor = current_line + cursor_pos;
336 const char *last_char = current_line + strlen(current_line);
338 current_line, cursor, last_char, match_start_point, max_return_elements,
339 matches, descriptions);
344 int match_start_point,
345 int max_return_elements,
348 max_return_elements, matches);
350 const char *cursor = current_line + cursor_pos;
351 const char *last_char = current_line + strlen(current_line);
353 max_return_elements, matches);
388 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
389 process_sp = target_sp->GetProcessSP();
390 sb_process.
SetSP(process_sp);
448 if (command_line &&
IsValid()) {
452 "SBCommandInterpreter or the command line is not valid");
475 std::unique_lock<std::recursive_mutex> lock;
477 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
480 result->
AppendError(
"SBCommandInterpreter is not valid");
498 std::unique_lock<std::recursive_mutex> lock;
500 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
503 result->
AppendError(
"SBCommandInterpreter is not valid");
514 std::unique_lock<std::recursive_mutex> lock;
516 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
519 result->
AppendError(
"SBCommandInterpreter is not valid");
558 return event.GetBroadcasterClass() ==
567 if (command_name && command_name[0] &&
IsValid()) {
568 llvm::StringRef command_name_str = command_name;
570 m_opaque_ptr->GetCommandObjectForCommand(command_name_str);
572 assert(command_name_str.empty());
587 std::string json_str =
588 llvm::formatv(
"{0:2}",
m_opaque_ptr->GetStatistics()).str();
604 std::make_shared<StructuredData::Array>(
m_opaque_ptr->GetTranscript()));
614 new_command_sp->GetAsMultiwordCommand()->SetRemovable(
true);
632 const char *help,
const char *syntax) {
634 return AddCommand(name, impl, help, syntax,
"");
639 const char *syntax,
const char *auto_repeat_command) {
643 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
645 auto_repeat_command);
659 return this->
operator bool();
661SBCommand::operator
bool()
const {
715 if (new_command_sp &&
m_opaque_sp->LoadSubCommand(name, new_command_sp))
730 const char *help,
const char *syntax) {
732 return AddCommand(name, impl, help, syntax,
"");
737 const char *help,
const char *syntax,
738 const char *auto_repeat_command) {
746 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
747 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax,
748 0, auto_repeat_command);
749 if (new_command_sp &&
m_opaque_sp->LoadSubCommand(name, new_command_sp))
775 return callback(sb_result, baton);
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
lldb_private::CommandInterpreterRunOptions & ref() const
lldb::SBCommand AddMultiwordCommand(const char *name, const char *help)
void SetPrintCallback(lldb::SBCommandPrintCallback callback, void *baton)
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.
static llvm::StringRef GetStaticBroadcasterClass()
void SetRemovable(bool removable)
CommandObjectParsed(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
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)
lldb::SBCommandPluginInterface * m_backend
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="")
bool IsRemovable() const override
void AppendError(llvm::StringRef in_string)
void SetInteractive(bool b)
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
lldb::ReturnStatus GetStatus() const
"lldb/Utility/ArgCompletionRequest.h"
void SetMaxReturnElements(size_t max_return_elements)
Sets the maximum number of completions that should be returned.
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.
void GetMatches(StringList &matches) const
Adds all collected completion matches to the given list.
A uniqued constant string class.
const char * GetCString() const
Get the string value as a C string.
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
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
lldb::CommandReturnObjectCallbackResult(* SBCommandPrintCallback)(lldb::SBCommandReturnObject &result, void *baton)
std::shared_ptr< lldb_private::Process > ProcessSP
ReturnStatus
Command Return Status Types.
@ eReturnStatusSuccessFinishResult
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.