1 //===-- SBCommandInterpreter.cpp --------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/lldb-types.h"
11 #include "SBReproducerPrivate.h"
12 #include "lldb/Interpreter/CommandInterpreter.h"
13 #include "lldb/Interpreter/CommandObjectMultiword.h"
14 #include "lldb/Interpreter/CommandReturnObject.h"
15 #include "lldb/Target/Target.h"
16 #include "lldb/Utility/Listener.h"
18 #include "lldb/API/SBBroadcaster.h"
19 #include "lldb/API/SBCommandInterpreter.h"
20 #include "lldb/API/SBCommandReturnObject.h"
21 #include "lldb/API/SBEvent.h"
22 #include "lldb/API/SBExecutionContext.h"
23 #include "lldb/API/SBListener.h"
24 #include "lldb/API/SBProcess.h"
25 #include "lldb/API/SBStream.h"
26 #include "lldb/API/SBStringList.h"
27 #include "lldb/API/SBTarget.h"
32 using namespace lldb_private;
34 SBCommandInterpreterRunOptions::SBCommandInterpreterRunOptions() {
35 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCommandInterpreterRunOptions);
37 m_opaque_up.reset(new CommandInterpreterRunOptions());
40 SBCommandInterpreterRunOptions::~SBCommandInterpreterRunOptions() = default;
42 bool SBCommandInterpreterRunOptions::GetStopOnContinue() const {
43 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions,
46 return m_opaque_up->GetStopOnContinue();
49 void SBCommandInterpreterRunOptions::SetStopOnContinue(bool stop_on_continue) {
50 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnContinue,
51 (bool), stop_on_continue);
53 m_opaque_up->SetStopOnContinue(stop_on_continue);
56 bool SBCommandInterpreterRunOptions::GetStopOnError() const {
57 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions,
60 return m_opaque_up->GetStopOnError();
63 void SBCommandInterpreterRunOptions::SetStopOnError(bool stop_on_error) {
64 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnError,
65 (bool), stop_on_error);
67 m_opaque_up->SetStopOnError(stop_on_error);
70 bool SBCommandInterpreterRunOptions::GetStopOnCrash() const {
71 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions,
74 return m_opaque_up->GetStopOnCrash();
77 void SBCommandInterpreterRunOptions::SetStopOnCrash(bool stop_on_crash) {
78 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnCrash,
79 (bool), stop_on_crash);
81 m_opaque_up->SetStopOnCrash(stop_on_crash);
84 bool SBCommandInterpreterRunOptions::GetEchoCommands() const {
85 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions,
88 return m_opaque_up->GetEchoCommands();
91 void SBCommandInterpreterRunOptions::SetEchoCommands(bool echo_commands) {
92 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetEchoCommands,
93 (bool), echo_commands);
95 m_opaque_up->SetEchoCommands(echo_commands);
98 bool SBCommandInterpreterRunOptions::GetEchoCommentCommands() const {
99 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions,
100 GetEchoCommentCommands);
102 return m_opaque_up->GetEchoCommentCommands();
105 void SBCommandInterpreterRunOptions::SetEchoCommentCommands(bool echo) {
106 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions,
107 SetEchoCommentCommands, (bool), echo);
109 m_opaque_up->SetEchoCommentCommands(echo);
112 bool SBCommandInterpreterRunOptions::GetPrintResults() const {
113 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions,
116 return m_opaque_up->GetPrintResults();
119 void SBCommandInterpreterRunOptions::SetPrintResults(bool print_results) {
120 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetPrintResults,
121 (bool), print_results);
123 m_opaque_up->SetPrintResults(print_results);
126 bool SBCommandInterpreterRunOptions::GetAddToHistory() const {
127 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions,
130 return m_opaque_up->GetAddToHistory();
133 void SBCommandInterpreterRunOptions::SetAddToHistory(bool add_to_history) {
134 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetAddToHistory,
135 (bool), add_to_history);
137 m_opaque_up->SetAddToHistory(add_to_history);
140 lldb_private::CommandInterpreterRunOptions *
141 SBCommandInterpreterRunOptions::get() const {
142 return m_opaque_up.get();
145 lldb_private::CommandInterpreterRunOptions &
146 SBCommandInterpreterRunOptions::ref() const {
150 class CommandPluginInterfaceImplementation : public CommandObjectParsed {
152 CommandPluginInterfaceImplementation(CommandInterpreter &interpreter,
154 lldb::SBCommandPluginInterface *backend,
155 const char *help = nullptr,
156 const char *syntax = nullptr,
158 : CommandObjectParsed(interpreter, name, help, syntax, flags),
159 m_backend(backend) {}
161 bool IsRemovable() const override { return true; }
164 bool DoExecute(Args &command, CommandReturnObject &result) override {
165 SBCommandReturnObject sb_return(&result);
166 SBCommandInterpreter sb_interpreter(&m_interpreter);
167 SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this());
168 bool ret = m_backend->DoExecute(
169 debugger_sb, (char **)command.GetArgumentVector(), sb_return);
173 std::shared_ptr<lldb::SBCommandPluginInterface> m_backend;
176 SBCommandInterpreter::SBCommandInterpreter(CommandInterpreter *interpreter)
177 : m_opaque_ptr(interpreter) {
178 LLDB_RECORD_CONSTRUCTOR(SBCommandInterpreter,
179 (lldb_private::CommandInterpreter *), interpreter);
183 SBCommandInterpreter::SBCommandInterpreter(const SBCommandInterpreter &rhs)
184 : m_opaque_ptr(rhs.m_opaque_ptr) {
185 LLDB_RECORD_CONSTRUCTOR(SBCommandInterpreter,
186 (const lldb::SBCommandInterpreter &), rhs);
189 SBCommandInterpreter::~SBCommandInterpreter() = default;
191 const SBCommandInterpreter &SBCommandInterpreter::
192 operator=(const SBCommandInterpreter &rhs) {
194 const lldb::SBCommandInterpreter &,
195 SBCommandInterpreter, operator=,(const lldb::SBCommandInterpreter &),
198 m_opaque_ptr = rhs.m_opaque_ptr;
199 return LLDB_RECORD_RESULT(*this);
202 bool SBCommandInterpreter::IsValid() const {
203 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreter, IsValid);
204 return this->operator bool();
206 SBCommandInterpreter::operator bool() const {
207 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreter, operator bool);
209 return m_opaque_ptr != nullptr;
212 bool SBCommandInterpreter::CommandExists(const char *cmd) {
213 LLDB_RECORD_METHOD(bool, SBCommandInterpreter, CommandExists, (const char *),
216 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->CommandExists(cmd)
220 bool SBCommandInterpreter::AliasExists(const char *cmd) {
221 LLDB_RECORD_METHOD(bool, SBCommandInterpreter, AliasExists, (const char *),
224 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->AliasExists(cmd)
228 bool SBCommandInterpreter::IsActive() {
229 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, IsActive);
231 return (IsValid() ? m_opaque_ptr->IsActive() : false);
234 bool SBCommandInterpreter::WasInterrupted() const {
235 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreter, WasInterrupted);
237 return (IsValid() ? m_opaque_ptr->WasInterrupted() : false);
240 const char *SBCommandInterpreter::GetIOHandlerControlSequence(char ch) {
241 LLDB_RECORD_METHOD(const char *, SBCommandInterpreter,
242 GetIOHandlerControlSequence, (char), ch);
245 ? m_opaque_ptr->GetDebugger()
246 .GetTopIOHandlerControlSequence(ch)
252 SBCommandInterpreter::HandleCommand(const char *command_line,
253 SBCommandReturnObject &result,
254 bool add_to_history) {
255 LLDB_RECORD_METHOD(lldb::ReturnStatus, SBCommandInterpreter, HandleCommand,
256 (const char *, lldb::SBCommandReturnObject &, bool),
257 command_line, result, add_to_history);
259 SBExecutionContext sb_exe_ctx;
260 return HandleCommand(command_line, sb_exe_ctx, result, add_to_history);
263 lldb::ReturnStatus SBCommandInterpreter::HandleCommand(
264 const char *command_line, SBExecutionContext &override_context,
265 SBCommandReturnObject &result, bool add_to_history) {
266 LLDB_RECORD_METHOD(lldb::ReturnStatus, SBCommandInterpreter, HandleCommand,
267 (const char *, lldb::SBExecutionContext &,
268 lldb::SBCommandReturnObject &, bool),
269 command_line, override_context, result, add_to_history);
272 ExecutionContext ctx, *ctx_ptr;
273 if (override_context.get()) {
274 ctx = override_context.get()->Lock(true);
280 if (command_line && IsValid()) {
281 result.ref().SetInteractive(false);
282 m_opaque_ptr->HandleCommand(command_line,
283 add_to_history ? eLazyBoolYes : eLazyBoolNo,
284 result.ref(), ctx_ptr);
287 "SBCommandInterpreter or the command line is not valid");
288 result->SetStatus(eReturnStatusFailed);
292 return result.GetStatus();
295 void SBCommandInterpreter::HandleCommandsFromFile(
296 lldb::SBFileSpec &file, lldb::SBExecutionContext &override_context,
297 lldb::SBCommandInterpreterRunOptions &options,
298 lldb::SBCommandReturnObject result) {
299 LLDB_RECORD_METHOD(void, SBCommandInterpreter, HandleCommandsFromFile,
300 (lldb::SBFileSpec &, lldb::SBExecutionContext &,
301 lldb::SBCommandInterpreterRunOptions &,
302 lldb::SBCommandReturnObject),
303 file, override_context, options, result);
306 result->AppendError("SBCommandInterpreter is not valid.");
307 result->SetStatus(eReturnStatusFailed);
311 if (!file.IsValid()) {
313 file.GetDescription(s);
314 result->AppendErrorWithFormat("File is not valid: %s.", s.GetData());
315 result->SetStatus(eReturnStatusFailed);
318 FileSpec tmp_spec = file.ref();
319 ExecutionContext ctx, *ctx_ptr;
320 if (override_context.get()) {
321 ctx = override_context.get()->Lock(true);
326 m_opaque_ptr->HandleCommandsFromFile(tmp_spec, ctx_ptr, options.ref(),
330 int SBCommandInterpreter::HandleCompletion(
331 const char *current_line, const char *cursor, const char *last_char,
332 int match_start_point, int max_return_elements, SBStringList &matches) {
333 LLDB_RECORD_METHOD(int, SBCommandInterpreter, HandleCompletion,
334 (const char *, const char *, const char *, int, int,
335 lldb::SBStringList &),
336 current_line, cursor, last_char, match_start_point,
337 max_return_elements, matches);
339 SBStringList dummy_descriptions;
340 return HandleCompletionWithDescriptions(
341 current_line, cursor, last_char, match_start_point, max_return_elements,
342 matches, dummy_descriptions);
345 int SBCommandInterpreter::HandleCompletionWithDescriptions(
346 const char *current_line, const char *cursor, const char *last_char,
347 int match_start_point, int max_return_elements, SBStringList &matches,
348 SBStringList &descriptions) {
349 LLDB_RECORD_METHOD(int, SBCommandInterpreter,
350 HandleCompletionWithDescriptions,
351 (const char *, const char *, const char *, int, int,
352 lldb::SBStringList &, lldb::SBStringList &),
353 current_line, cursor, last_char, match_start_point,
354 max_return_elements, matches, descriptions);
356 int num_completions = 0;
358 // Sanity check the arguments that are passed in: cursor & last_char have to
359 // be within the current_line.
360 if (current_line == nullptr || cursor == nullptr || last_char == nullptr)
363 if (cursor < current_line || last_char < current_line)
366 size_t current_line_size = strlen(current_line);
367 if (cursor - current_line > static_cast<ptrdiff_t>(current_line_size) ||
368 last_char - current_line > static_cast<ptrdiff_t>(current_line_size))
373 lldb_private::StringList lldb_matches, lldb_descriptions;
374 num_completions = m_opaque_ptr->HandleCompletion(
375 current_line, cursor, last_char, match_start_point, max_return_elements,
376 lldb_matches, lldb_descriptions);
378 SBStringList temp_matches_list(&lldb_matches);
379 matches.AppendList(temp_matches_list);
380 SBStringList temp_descriptions_list(&lldb_descriptions);
381 descriptions.AppendList(temp_descriptions_list);
384 return num_completions;
387 int SBCommandInterpreter::HandleCompletionWithDescriptions(
388 const char *current_line, uint32_t cursor_pos, int match_start_point,
389 int max_return_elements, SBStringList &matches,
390 SBStringList &descriptions) {
391 LLDB_RECORD_METHOD(int, SBCommandInterpreter,
392 HandleCompletionWithDescriptions,
393 (const char *, uint32_t, int, int, lldb::SBStringList &,
394 lldb::SBStringList &),
395 current_line, cursor_pos, match_start_point,
396 max_return_elements, matches, descriptions);
398 const char *cursor = current_line + cursor_pos;
399 const char *last_char = current_line + strlen(current_line);
400 return HandleCompletionWithDescriptions(
401 current_line, cursor, last_char, match_start_point, max_return_elements,
402 matches, descriptions);
405 int SBCommandInterpreter::HandleCompletion(const char *current_line,
407 int match_start_point,
408 int max_return_elements,
409 lldb::SBStringList &matches) {
410 LLDB_RECORD_METHOD(int, SBCommandInterpreter, HandleCompletion,
411 (const char *, uint32_t, int, int, lldb::SBStringList &),
412 current_line, cursor_pos, match_start_point,
413 max_return_elements, matches);
415 const char *cursor = current_line + cursor_pos;
416 const char *last_char = current_line + strlen(current_line);
417 return HandleCompletion(current_line, cursor, last_char, match_start_point,
418 max_return_elements, matches);
421 bool SBCommandInterpreter::HasCommands() {
422 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasCommands);
424 return (IsValid() ? m_opaque_ptr->HasCommands() : false);
427 bool SBCommandInterpreter::HasAliases() {
428 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasAliases);
430 return (IsValid() ? m_opaque_ptr->HasAliases() : false);
433 bool SBCommandInterpreter::HasAliasOptions() {
434 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasAliasOptions);
436 return (IsValid() ? m_opaque_ptr->HasAliasOptions() : false);
439 SBProcess SBCommandInterpreter::GetProcess() {
440 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcess, SBCommandInterpreter, GetProcess);
442 SBProcess sb_process;
443 ProcessSP process_sp;
445 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
447 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
448 process_sp = target_sp->GetProcessSP();
449 sb_process.SetSP(process_sp);
453 return LLDB_RECORD_RESULT(sb_process);
456 SBDebugger SBCommandInterpreter::GetDebugger() {
457 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBDebugger, SBCommandInterpreter,
460 SBDebugger sb_debugger;
462 sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this());
464 return LLDB_RECORD_RESULT(sb_debugger);
467 bool SBCommandInterpreter::GetPromptOnQuit() {
468 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, GetPromptOnQuit);
470 return (IsValid() ? m_opaque_ptr->GetPromptOnQuit() : false);
473 void SBCommandInterpreter::SetPromptOnQuit(bool b) {
474 LLDB_RECORD_METHOD(void, SBCommandInterpreter, SetPromptOnQuit, (bool), b);
477 m_opaque_ptr->SetPromptOnQuit(b);
480 void SBCommandInterpreter::AllowExitCodeOnQuit(bool allow) {
481 LLDB_RECORD_METHOD(void, SBCommandInterpreter, AllowExitCodeOnQuit, (bool),
485 m_opaque_ptr->AllowExitCodeOnQuit(allow);
488 bool SBCommandInterpreter::HasCustomQuitExitCode() {
489 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasCustomQuitExitCode);
493 m_opaque_ptr->GetQuitExitCode(exited);
497 int SBCommandInterpreter::GetQuitStatus() {
498 LLDB_RECORD_METHOD_NO_ARGS(int, SBCommandInterpreter, GetQuitStatus);
501 return (m_opaque_ptr ? m_opaque_ptr->GetQuitExitCode(exited) : 0);
504 void SBCommandInterpreter::ResolveCommand(const char *command_line,
505 SBCommandReturnObject &result) {
506 LLDB_RECORD_METHOD(void, SBCommandInterpreter, ResolveCommand,
507 (const char *, lldb::SBCommandReturnObject &),
508 command_line, result);
511 if (command_line && IsValid()) {
512 m_opaque_ptr->ResolveCommand(command_line, result.ref());
515 "SBCommandInterpreter or the command line is not valid");
516 result->SetStatus(eReturnStatusFailed);
520 CommandInterpreter *SBCommandInterpreter::get() { return m_opaque_ptr; }
522 CommandInterpreter &SBCommandInterpreter::ref() {
523 assert(m_opaque_ptr);
524 return *m_opaque_ptr;
527 void SBCommandInterpreter::reset(
528 lldb_private::CommandInterpreter *interpreter) {
529 m_opaque_ptr = interpreter;
532 void SBCommandInterpreter::SourceInitFileInHomeDirectory(
533 SBCommandReturnObject &result) {
534 LLDB_RECORD_METHOD(void, SBCommandInterpreter, SourceInitFileInHomeDirectory,
535 (lldb::SBCommandReturnObject &), result);
539 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
540 std::unique_lock<std::recursive_mutex> lock;
542 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
543 m_opaque_ptr->SourceInitFileHome(result.ref());
545 result->AppendError("SBCommandInterpreter is not valid");
546 result->SetStatus(eReturnStatusFailed);
550 void SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory(
551 SBCommandReturnObject &result) {
552 LLDB_RECORD_METHOD(void, SBCommandInterpreter,
553 SourceInitFileInCurrentWorkingDirectory,
554 (lldb::SBCommandReturnObject &), result);
558 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
559 std::unique_lock<std::recursive_mutex> lock;
561 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
562 m_opaque_ptr->SourceInitFileCwd(result.ref());
564 result->AppendError("SBCommandInterpreter is not valid");
565 result->SetStatus(eReturnStatusFailed);
569 SBBroadcaster SBCommandInterpreter::GetBroadcaster() {
570 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBroadcaster, SBCommandInterpreter,
574 SBBroadcaster broadcaster(m_opaque_ptr, false);
577 return LLDB_RECORD_RESULT(broadcaster);
580 const char *SBCommandInterpreter::GetBroadcasterClass() {
581 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBCommandInterpreter,
582 GetBroadcasterClass);
584 return CommandInterpreter::GetStaticBroadcasterClass().AsCString();
587 const char *SBCommandInterpreter::GetArgumentTypeAsCString(
588 const lldb::CommandArgumentType arg_type) {
589 LLDB_RECORD_STATIC_METHOD(const char *, SBCommandInterpreter,
590 GetArgumentTypeAsCString,
591 (const lldb::CommandArgumentType), arg_type);
593 return CommandObject::GetArgumentTypeAsCString(arg_type);
596 const char *SBCommandInterpreter::GetArgumentDescriptionAsCString(
597 const lldb::CommandArgumentType arg_type) {
598 LLDB_RECORD_STATIC_METHOD(const char *, SBCommandInterpreter,
599 GetArgumentDescriptionAsCString,
600 (const lldb::CommandArgumentType), arg_type);
602 return CommandObject::GetArgumentDescriptionAsCString(arg_type);
605 bool SBCommandInterpreter::EventIsCommandInterpreterEvent(
606 const lldb::SBEvent &event) {
607 LLDB_RECORD_STATIC_METHOD(bool, SBCommandInterpreter,
608 EventIsCommandInterpreterEvent,
609 (const lldb::SBEvent &), event);
611 return event.GetBroadcasterClass() ==
612 SBCommandInterpreter::GetBroadcasterClass();
615 bool SBCommandInterpreter::SetCommandOverrideCallback(
616 const char *command_name, lldb::CommandOverrideCallback callback,
618 LLDB_RECORD_DUMMY(bool, SBCommandInterpreter, SetCommandOverrideCallback,
619 (const char *, lldb::CommandOverrideCallback, void *),
620 command_name, callback, baton);
622 if (command_name && command_name[0] && IsValid()) {
623 llvm::StringRef command_name_str = command_name;
624 CommandObject *cmd_obj =
625 m_opaque_ptr->GetCommandObjectForCommand(command_name_str);
627 assert(command_name_str.empty());
628 cmd_obj->SetOverrideCallback(callback, baton);
635 lldb::SBCommand SBCommandInterpreter::AddMultiwordCommand(const char *name,
637 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommandInterpreter, AddMultiwordCommand,
638 (const char *, const char *), name, help);
640 CommandObjectMultiword *new_command =
641 new CommandObjectMultiword(*m_opaque_ptr, name, help);
642 new_command->SetRemovable(true);
643 lldb::CommandObjectSP new_command_sp(new_command);
644 if (new_command_sp &&
645 m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
646 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp));
647 return LLDB_RECORD_RESULT(lldb::SBCommand());
650 lldb::SBCommand SBCommandInterpreter::AddCommand(
651 const char *name, lldb::SBCommandPluginInterface *impl, const char *help) {
653 lldb::SBCommand, SBCommandInterpreter, AddCommand,
654 (const char *, lldb::SBCommandPluginInterface *, const char *), name,
657 lldb::CommandObjectSP new_command_sp;
658 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
659 *m_opaque_ptr, name, impl, help);
661 if (new_command_sp &&
662 m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
663 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp));
664 return LLDB_RECORD_RESULT(lldb::SBCommand());
668 SBCommandInterpreter::AddCommand(const char *name,
669 lldb::SBCommandPluginInterface *impl,
670 const char *help, const char *syntax) {
671 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommandInterpreter, AddCommand,
672 (const char *, lldb::SBCommandPluginInterface *,
673 const char *, const char *),
674 name, impl, help, syntax);
676 lldb::CommandObjectSP new_command_sp;
677 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
678 *m_opaque_ptr, name, impl, help, syntax);
680 if (new_command_sp &&
681 m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
682 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp));
683 return LLDB_RECORD_RESULT(lldb::SBCommand());
686 SBCommand::SBCommand() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCommand); }
688 SBCommand::SBCommand(lldb::CommandObjectSP cmd_sp) : m_opaque_sp(cmd_sp) {}
690 bool SBCommand::IsValid() {
691 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommand, IsValid);
692 return this->operator bool();
694 SBCommand::operator bool() const {
695 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommand, operator bool);
697 return m_opaque_sp.get() != nullptr;
700 const char *SBCommand::GetName() {
701 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetName);
703 return (IsValid() ? ConstString(m_opaque_sp->GetCommandName()).AsCString() : nullptr);
706 const char *SBCommand::GetHelp() {
707 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetHelp);
709 return (IsValid() ? ConstString(m_opaque_sp->GetHelp()).AsCString()
713 const char *SBCommand::GetHelpLong() {
714 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetHelpLong);
716 return (IsValid() ? ConstString(m_opaque_sp->GetHelpLong()).AsCString()
720 void SBCommand::SetHelp(const char *help) {
721 LLDB_RECORD_METHOD(void, SBCommand, SetHelp, (const char *), help);
724 m_opaque_sp->SetHelp(help);
727 void SBCommand::SetHelpLong(const char *help) {
728 LLDB_RECORD_METHOD(void, SBCommand, SetHelpLong, (const char *), help);
731 m_opaque_sp->SetHelpLong(help);
734 lldb::SBCommand SBCommand::AddMultiwordCommand(const char *name,
736 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommand, AddMultiwordCommand,
737 (const char *, const char *), name, help);
740 return LLDB_RECORD_RESULT(lldb::SBCommand());
741 if (!m_opaque_sp->IsMultiwordObject())
742 return LLDB_RECORD_RESULT(lldb::SBCommand());
743 CommandObjectMultiword *new_command = new CommandObjectMultiword(
744 m_opaque_sp->GetCommandInterpreter(), name, help);
745 new_command->SetRemovable(true);
746 lldb::CommandObjectSP new_command_sp(new_command);
747 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
748 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp));
749 return LLDB_RECORD_RESULT(lldb::SBCommand());
752 lldb::SBCommand SBCommand::AddCommand(const char *name,
753 lldb::SBCommandPluginInterface *impl,
756 lldb::SBCommand, SBCommand, AddCommand,
757 (const char *, lldb::SBCommandPluginInterface *, const char *), name,
761 return LLDB_RECORD_RESULT(lldb::SBCommand());
762 if (!m_opaque_sp->IsMultiwordObject())
763 return LLDB_RECORD_RESULT(lldb::SBCommand());
764 lldb::CommandObjectSP new_command_sp;
765 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
766 m_opaque_sp->GetCommandInterpreter(), name, impl, help);
767 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
768 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp));
769 return LLDB_RECORD_RESULT(lldb::SBCommand());
772 lldb::SBCommand SBCommand::AddCommand(const char *name,
773 lldb::SBCommandPluginInterface *impl,
774 const char *help, const char *syntax) {
775 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommand, AddCommand,
776 (const char *, lldb::SBCommandPluginInterface *,
777 const char *, const char *),
778 name, impl, help, syntax);
781 return LLDB_RECORD_RESULT(lldb::SBCommand());
782 if (!m_opaque_sp->IsMultiwordObject())
783 return LLDB_RECORD_RESULT(lldb::SBCommand());
784 lldb::CommandObjectSP new_command_sp;
785 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
786 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax);
787 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
788 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp));
789 return LLDB_RECORD_RESULT(lldb::SBCommand());
792 uint32_t SBCommand::GetFlags() {
793 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBCommand, GetFlags);
795 return (IsValid() ? m_opaque_sp->GetFlags().Get() : 0);
798 void SBCommand::SetFlags(uint32_t flags) {
799 LLDB_RECORD_METHOD(void, SBCommand, SetFlags, (uint32_t), flags);
802 m_opaque_sp->GetFlags().Set(flags);
805 namespace lldb_private {
809 void RegisterMethods<SBCommandInterpreterRunOptions>(Registry &R) {
810 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreterRunOptions, ());
811 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
812 GetStopOnContinue, ());
813 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions,
814 SetStopOnContinue, (bool));
815 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
817 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnError,
819 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
821 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnCrash,
823 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
824 GetEchoCommands, ());
825 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetEchoCommands,
827 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
828 GetEchoCommentCommands, ());
829 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions,
830 SetEchoCommentCommands, (bool));
831 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
832 GetPrintResults, ());
833 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetPrintResults,
835 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
836 GetAddToHistory, ());
837 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetAddToHistory,
839 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreter,
840 (lldb_private::CommandInterpreter *));
841 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreter,
842 (const lldb::SBCommandInterpreter &));
843 LLDB_REGISTER_METHOD(
844 const lldb::SBCommandInterpreter &,
845 SBCommandInterpreter, operator=,(const lldb::SBCommandInterpreter &));
846 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, IsValid, ());
847 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, operator bool, ());
848 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, CommandExists,
850 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, AliasExists,
852 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, IsActive, ());
853 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, WasInterrupted, ());
854 LLDB_REGISTER_METHOD(const char *, SBCommandInterpreter,
855 GetIOHandlerControlSequence, (char));
856 LLDB_REGISTER_METHOD(lldb::ReturnStatus, SBCommandInterpreter,
858 (const char *, lldb::SBCommandReturnObject &, bool));
859 LLDB_REGISTER_METHOD(lldb::ReturnStatus, SBCommandInterpreter,
861 (const char *, lldb::SBExecutionContext &,
862 lldb::SBCommandReturnObject &, bool));
863 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, HandleCommandsFromFile,
864 (lldb::SBFileSpec &, lldb::SBExecutionContext &,
865 lldb::SBCommandInterpreterRunOptions &,
866 lldb::SBCommandReturnObject));
867 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, HandleCompletion,
868 (const char *, const char *, const char *, int, int,
869 lldb::SBStringList &));
870 LLDB_REGISTER_METHOD(int, SBCommandInterpreter,
871 HandleCompletionWithDescriptions,
872 (const char *, const char *, const char *, int, int,
873 lldb::SBStringList &, lldb::SBStringList &));
874 LLDB_REGISTER_METHOD(int, SBCommandInterpreter,
875 HandleCompletionWithDescriptions,
876 (const char *, uint32_t, int, int,
877 lldb::SBStringList &, lldb::SBStringList &));
878 LLDB_REGISTER_METHOD(
879 int, SBCommandInterpreter, HandleCompletion,
880 (const char *, uint32_t, int, int, lldb::SBStringList &));
881 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasCommands, ());
882 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasAliases, ());
883 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasAliasOptions, ());
884 LLDB_REGISTER_METHOD(lldb::SBProcess, SBCommandInterpreter, GetProcess, ());
885 LLDB_REGISTER_METHOD(lldb::SBDebugger, SBCommandInterpreter, GetDebugger,
887 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, GetPromptOnQuit, ());
888 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, SetPromptOnQuit, (bool));
889 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, AllowExitCodeOnQuit,
891 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasCustomQuitExitCode, ());
892 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, GetQuitStatus, ());
893 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, ResolveCommand,
894 (const char *, lldb::SBCommandReturnObject &));
895 LLDB_REGISTER_METHOD(void, SBCommandInterpreter,
896 SourceInitFileInHomeDirectory,
897 (lldb::SBCommandReturnObject &));
898 LLDB_REGISTER_METHOD(void, SBCommandInterpreter,
899 SourceInitFileInCurrentWorkingDirectory,
900 (lldb::SBCommandReturnObject &));
901 LLDB_REGISTER_METHOD(lldb::SBBroadcaster, SBCommandInterpreter,
903 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter,
904 GetBroadcasterClass, ());
905 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter,
906 GetArgumentTypeAsCString,
907 (const lldb::CommandArgumentType));
908 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter,
909 GetArgumentDescriptionAsCString,
910 (const lldb::CommandArgumentType));
911 LLDB_REGISTER_STATIC_METHOD(bool, SBCommandInterpreter,
912 EventIsCommandInterpreterEvent,
913 (const lldb::SBEvent &));
914 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommandInterpreter,
915 AddMultiwordCommand, (const char *, const char *));
916 LLDB_REGISTER_METHOD(
917 lldb::SBCommand, SBCommandInterpreter, AddCommand,
918 (const char *, lldb::SBCommandPluginInterface *, const char *));
919 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommandInterpreter, AddCommand,
920 (const char *, lldb::SBCommandPluginInterface *,
921 const char *, const char *));
922 LLDB_REGISTER_CONSTRUCTOR(SBCommand, ());
923 LLDB_REGISTER_METHOD(bool, SBCommand, IsValid, ());
924 LLDB_REGISTER_METHOD_CONST(bool, SBCommand, operator bool, ());
925 LLDB_REGISTER_METHOD(const char *, SBCommand, GetName, ());
926 LLDB_REGISTER_METHOD(const char *, SBCommand, GetHelp, ());
927 LLDB_REGISTER_METHOD(const char *, SBCommand, GetHelpLong, ());
928 LLDB_REGISTER_METHOD(void, SBCommand, SetHelp, (const char *));
929 LLDB_REGISTER_METHOD(void, SBCommand, SetHelpLong, (const char *));
930 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommand, AddMultiwordCommand,
931 (const char *, const char *));
932 LLDB_REGISTER_METHOD(
933 lldb::SBCommand, SBCommand, AddCommand,
934 (const char *, lldb::SBCommandPluginInterface *, const char *));
935 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommand, AddCommand,
936 (const char *, lldb::SBCommandPluginInterface *,
937 const char *, const char *));
938 LLDB_REGISTER_METHOD(uint32_t, SBCommand, GetFlags, ());
939 LLDB_REGISTER_METHOD(void, SBCommand, SetFlags, (uint32_t));