[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / source / API / SBCommandInterpreter.cpp
blob6e5ebe6a7ded73479333113a6f4e00b7a1c3d9ee
1 //===-- SBCommandInterpreter.cpp --------------------------------*- C++ -*-===//
2 //
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
6 //
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"
29 #include <memory>
31 using namespace lldb;
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,
44 GetStopOnContinue);
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,
58 GetStopOnError);
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,
72 GetStopOnCrash);
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,
86 GetEchoCommands);
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,
114 GetPrintResults);
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,
128 GetAddToHistory);
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 {
147 return *m_opaque_up;
150 class CommandPluginInterfaceImplementation : public CommandObjectParsed {
151 public:
152 CommandPluginInterfaceImplementation(CommandInterpreter &interpreter,
153 const char *name,
154 lldb::SBCommandPluginInterface *backend,
155 const char *help = nullptr,
156 const char *syntax = nullptr,
157 uint32_t flags = 0)
158 : CommandObjectParsed(interpreter, name, help, syntax, flags),
159 m_backend(backend) {}
161 bool IsRemovable() const override { return true; }
163 protected:
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);
170 return ret;
172 std::shared_ptr<lldb::SBCommandPluginInterface> m_backend;
175 SBCommandInterpreter::SBCommandInterpreter(CommandInterpreter *interpreter)
176 : m_opaque_ptr(interpreter) {
177 LLDB_RECORD_CONSTRUCTOR(SBCommandInterpreter,
178 (lldb_private::CommandInterpreter *), interpreter);
182 SBCommandInterpreter::SBCommandInterpreter(const SBCommandInterpreter &rhs)
183 : m_opaque_ptr(rhs.m_opaque_ptr) {
184 LLDB_RECORD_CONSTRUCTOR(SBCommandInterpreter,
185 (const lldb::SBCommandInterpreter &), rhs);
188 SBCommandInterpreter::~SBCommandInterpreter() = default;
190 const SBCommandInterpreter &SBCommandInterpreter::
191 operator=(const SBCommandInterpreter &rhs) {
192 LLDB_RECORD_METHOD(
193 const lldb::SBCommandInterpreter &,
194 SBCommandInterpreter, operator=,(const lldb::SBCommandInterpreter &),
195 rhs);
197 m_opaque_ptr = rhs.m_opaque_ptr;
198 return LLDB_RECORD_RESULT(*this);
201 bool SBCommandInterpreter::IsValid() const {
202 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreter, IsValid);
203 return this->operator bool();
205 SBCommandInterpreter::operator bool() const {
206 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreter, operator bool);
208 return m_opaque_ptr != nullptr;
211 bool SBCommandInterpreter::CommandExists(const char *cmd) {
212 LLDB_RECORD_METHOD(bool, SBCommandInterpreter, CommandExists, (const char *),
213 cmd);
215 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->CommandExists(cmd)
216 : false);
219 bool SBCommandInterpreter::AliasExists(const char *cmd) {
220 LLDB_RECORD_METHOD(bool, SBCommandInterpreter, AliasExists, (const char *),
221 cmd);
223 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->AliasExists(cmd)
224 : false);
227 bool SBCommandInterpreter::IsActive() {
228 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, IsActive);
230 return (IsValid() ? m_opaque_ptr->IsActive() : false);
233 bool SBCommandInterpreter::WasInterrupted() const {
234 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreter, WasInterrupted);
236 return (IsValid() ? m_opaque_ptr->WasInterrupted() : false);
239 const char *SBCommandInterpreter::GetIOHandlerControlSequence(char ch) {
240 LLDB_RECORD_METHOD(const char *, SBCommandInterpreter,
241 GetIOHandlerControlSequence, (char), ch);
243 return (IsValid()
244 ? m_opaque_ptr->GetDebugger()
245 .GetTopIOHandlerControlSequence(ch)
246 .GetCString()
247 : nullptr);
250 lldb::ReturnStatus
251 SBCommandInterpreter::HandleCommand(const char *command_line,
252 SBCommandReturnObject &result,
253 bool add_to_history) {
254 LLDB_RECORD_METHOD(lldb::ReturnStatus, SBCommandInterpreter, HandleCommand,
255 (const char *, lldb::SBCommandReturnObject &, bool),
256 command_line, result, add_to_history);
258 SBExecutionContext sb_exe_ctx;
259 return HandleCommand(command_line, sb_exe_ctx, result, add_to_history);
262 lldb::ReturnStatus SBCommandInterpreter::HandleCommand(
263 const char *command_line, SBExecutionContext &override_context,
264 SBCommandReturnObject &result, bool add_to_history) {
265 LLDB_RECORD_METHOD(lldb::ReturnStatus, SBCommandInterpreter, HandleCommand,
266 (const char *, lldb::SBExecutionContext &,
267 lldb::SBCommandReturnObject &, bool),
268 command_line, override_context, result, add_to_history);
271 ExecutionContext ctx, *ctx_ptr;
272 if (override_context.get()) {
273 ctx = override_context.get()->Lock(true);
274 ctx_ptr = &ctx;
275 } else
276 ctx_ptr = nullptr;
278 result.Clear();
279 if (command_line && IsValid()) {
280 result.ref().SetInteractive(false);
281 m_opaque_ptr->HandleCommand(command_line,
282 add_to_history ? eLazyBoolYes : eLazyBoolNo,
283 result.ref(), ctx_ptr);
284 } else {
285 result->AppendError(
286 "SBCommandInterpreter or the command line is not valid");
287 result->SetStatus(eReturnStatusFailed);
291 return result.GetStatus();
294 void SBCommandInterpreter::HandleCommandsFromFile(
295 lldb::SBFileSpec &file, lldb::SBExecutionContext &override_context,
296 lldb::SBCommandInterpreterRunOptions &options,
297 lldb::SBCommandReturnObject result) {
298 LLDB_RECORD_METHOD(void, SBCommandInterpreter, HandleCommandsFromFile,
299 (lldb::SBFileSpec &, lldb::SBExecutionContext &,
300 lldb::SBCommandInterpreterRunOptions &,
301 lldb::SBCommandReturnObject),
302 file, override_context, options, result);
304 if (!IsValid()) {
305 result->AppendError("SBCommandInterpreter is not valid.");
306 result->SetStatus(eReturnStatusFailed);
307 return;
310 if (!file.IsValid()) {
311 SBStream s;
312 file.GetDescription(s);
313 result->AppendErrorWithFormat("File is not valid: %s.", s.GetData());
314 result->SetStatus(eReturnStatusFailed);
317 FileSpec tmp_spec = file.ref();
318 ExecutionContext ctx, *ctx_ptr;
319 if (override_context.get()) {
320 ctx = override_context.get()->Lock(true);
321 ctx_ptr = &ctx;
322 } else
323 ctx_ptr = nullptr;
325 m_opaque_ptr->HandleCommandsFromFile(tmp_spec, ctx_ptr, options.ref(),
326 result.ref());
329 int SBCommandInterpreter::HandleCompletion(
330 const char *current_line, const char *cursor, const char *last_char,
331 int match_start_point, int max_return_elements, SBStringList &matches) {
332 LLDB_RECORD_METHOD(int, SBCommandInterpreter, HandleCompletion,
333 (const char *, const char *, const char *, int, int,
334 lldb::SBStringList &),
335 current_line, cursor, last_char, match_start_point,
336 max_return_elements, matches);
338 SBStringList dummy_descriptions;
339 return HandleCompletionWithDescriptions(
340 current_line, cursor, last_char, match_start_point, max_return_elements,
341 matches, dummy_descriptions);
344 int SBCommandInterpreter::HandleCompletionWithDescriptions(
345 const char *current_line, const char *cursor, const char *last_char,
346 int match_start_point, int max_return_elements, SBStringList &matches,
347 SBStringList &descriptions) {
348 LLDB_RECORD_METHOD(int, SBCommandInterpreter,
349 HandleCompletionWithDescriptions,
350 (const char *, const char *, const char *, int, int,
351 lldb::SBStringList &, lldb::SBStringList &),
352 current_line, cursor, last_char, match_start_point,
353 max_return_elements, matches, descriptions);
355 // Sanity check the arguments that are passed in: cursor & last_char have to
356 // be within the current_line.
357 if (current_line == nullptr || cursor == nullptr || last_char == nullptr)
358 return 0;
360 if (cursor < current_line || last_char < current_line)
361 return 0;
363 size_t current_line_size = strlen(current_line);
364 if (cursor - current_line > static_cast<ptrdiff_t>(current_line_size) ||
365 last_char - current_line > static_cast<ptrdiff_t>(current_line_size))
366 return 0;
368 if (!IsValid())
369 return 0;
371 lldb_private::StringList lldb_matches, lldb_descriptions;
372 CompletionResult result;
373 CompletionRequest request(current_line, cursor - current_line, result);
374 m_opaque_ptr->HandleCompletion(request);
375 result.GetMatches(lldb_matches);
376 result.GetDescriptions(lldb_descriptions);
378 // Make the result array indexed from 1 again by adding the 'common prefix'
379 // of all completions as element 0. This is done to emulate the old API.
380 if (request.GetParsedLine().GetArgumentCount() == 0) {
381 // If we got an empty string, insert nothing.
382 lldb_matches.InsertStringAtIndex(0, "");
383 lldb_descriptions.InsertStringAtIndex(0, "");
384 } else {
385 // Now figure out if there is a common substring, and if so put that in
386 // element 0, otherwise put an empty string in element 0.
387 std::string command_partial_str = request.GetCursorArgumentPrefix().str();
389 std::string common_prefix = lldb_matches.LongestCommonPrefix();
390 const size_t partial_name_len = command_partial_str.size();
391 common_prefix.erase(0, partial_name_len);
393 // If we matched a unique single command, add a space... Only do this if
394 // the completer told us this was a complete word, however...
395 if (lldb_matches.GetSize() == 1) {
396 char quote_char = request.GetParsedArg().GetQuoteChar();
397 common_prefix =
398 Args::EscapeLLDBCommandArgument(common_prefix, quote_char);
399 if (request.GetParsedArg().IsQuoted())
400 common_prefix.push_back(quote_char);
401 common_prefix.push_back(' ');
403 lldb_matches.InsertStringAtIndex(0, common_prefix.c_str());
404 lldb_descriptions.InsertStringAtIndex(0, "");
407 SBStringList temp_matches_list(&lldb_matches);
408 matches.AppendList(temp_matches_list);
409 SBStringList temp_descriptions_list(&lldb_descriptions);
410 descriptions.AppendList(temp_descriptions_list);
411 return result.GetNumberOfResults();
414 int SBCommandInterpreter::HandleCompletionWithDescriptions(
415 const char *current_line, uint32_t cursor_pos, int match_start_point,
416 int max_return_elements, SBStringList &matches,
417 SBStringList &descriptions) {
418 LLDB_RECORD_METHOD(int, SBCommandInterpreter,
419 HandleCompletionWithDescriptions,
420 (const char *, uint32_t, int, int, lldb::SBStringList &,
421 lldb::SBStringList &),
422 current_line, cursor_pos, match_start_point,
423 max_return_elements, matches, descriptions);
425 const char *cursor = current_line + cursor_pos;
426 const char *last_char = current_line + strlen(current_line);
427 return HandleCompletionWithDescriptions(
428 current_line, cursor, last_char, match_start_point, max_return_elements,
429 matches, descriptions);
432 int SBCommandInterpreter::HandleCompletion(const char *current_line,
433 uint32_t cursor_pos,
434 int match_start_point,
435 int max_return_elements,
436 lldb::SBStringList &matches) {
437 LLDB_RECORD_METHOD(int, SBCommandInterpreter, HandleCompletion,
438 (const char *, uint32_t, int, int, lldb::SBStringList &),
439 current_line, cursor_pos, match_start_point,
440 max_return_elements, matches);
442 const char *cursor = current_line + cursor_pos;
443 const char *last_char = current_line + strlen(current_line);
444 return HandleCompletion(current_line, cursor, last_char, match_start_point,
445 max_return_elements, matches);
448 bool SBCommandInterpreter::HasCommands() {
449 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasCommands);
451 return (IsValid() ? m_opaque_ptr->HasCommands() : false);
454 bool SBCommandInterpreter::HasAliases() {
455 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasAliases);
457 return (IsValid() ? m_opaque_ptr->HasAliases() : false);
460 bool SBCommandInterpreter::HasAliasOptions() {
461 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasAliasOptions);
463 return (IsValid() ? m_opaque_ptr->HasAliasOptions() : false);
466 SBProcess SBCommandInterpreter::GetProcess() {
467 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcess, SBCommandInterpreter, GetProcess);
469 SBProcess sb_process;
470 ProcessSP process_sp;
471 if (IsValid()) {
472 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
473 if (target_sp) {
474 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
475 process_sp = target_sp->GetProcessSP();
476 sb_process.SetSP(process_sp);
480 return LLDB_RECORD_RESULT(sb_process);
483 SBDebugger SBCommandInterpreter::GetDebugger() {
484 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBDebugger, SBCommandInterpreter,
485 GetDebugger);
487 SBDebugger sb_debugger;
488 if (IsValid())
489 sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this());
491 return LLDB_RECORD_RESULT(sb_debugger);
494 bool SBCommandInterpreter::GetPromptOnQuit() {
495 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, GetPromptOnQuit);
497 return (IsValid() ? m_opaque_ptr->GetPromptOnQuit() : false);
500 void SBCommandInterpreter::SetPromptOnQuit(bool b) {
501 LLDB_RECORD_METHOD(void, SBCommandInterpreter, SetPromptOnQuit, (bool), b);
503 if (IsValid())
504 m_opaque_ptr->SetPromptOnQuit(b);
507 void SBCommandInterpreter::AllowExitCodeOnQuit(bool allow) {
508 LLDB_RECORD_METHOD(void, SBCommandInterpreter, AllowExitCodeOnQuit, (bool),
509 allow);
511 if (m_opaque_ptr)
512 m_opaque_ptr->AllowExitCodeOnQuit(allow);
515 bool SBCommandInterpreter::HasCustomQuitExitCode() {
516 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasCustomQuitExitCode);
518 bool exited = false;
519 if (m_opaque_ptr)
520 m_opaque_ptr->GetQuitExitCode(exited);
521 return exited;
524 int SBCommandInterpreter::GetQuitStatus() {
525 LLDB_RECORD_METHOD_NO_ARGS(int, SBCommandInterpreter, GetQuitStatus);
527 bool exited = false;
528 return (m_opaque_ptr ? m_opaque_ptr->GetQuitExitCode(exited) : 0);
531 void SBCommandInterpreter::ResolveCommand(const char *command_line,
532 SBCommandReturnObject &result) {
533 LLDB_RECORD_METHOD(void, SBCommandInterpreter, ResolveCommand,
534 (const char *, lldb::SBCommandReturnObject &),
535 command_line, result);
537 result.Clear();
538 if (command_line && IsValid()) {
539 m_opaque_ptr->ResolveCommand(command_line, result.ref());
540 } else {
541 result->AppendError(
542 "SBCommandInterpreter or the command line is not valid");
543 result->SetStatus(eReturnStatusFailed);
547 CommandInterpreter *SBCommandInterpreter::get() { return m_opaque_ptr; }
549 CommandInterpreter &SBCommandInterpreter::ref() {
550 assert(m_opaque_ptr);
551 return *m_opaque_ptr;
554 void SBCommandInterpreter::reset(
555 lldb_private::CommandInterpreter *interpreter) {
556 m_opaque_ptr = interpreter;
559 void SBCommandInterpreter::SourceInitFileInHomeDirectory(
560 SBCommandReturnObject &result) {
561 LLDB_RECORD_METHOD(void, SBCommandInterpreter, SourceInitFileInHomeDirectory,
562 (lldb::SBCommandReturnObject &), result);
564 result.Clear();
565 if (IsValid()) {
566 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
567 std::unique_lock<std::recursive_mutex> lock;
568 if (target_sp)
569 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
570 m_opaque_ptr->SourceInitFileHome(result.ref());
571 } else {
572 result->AppendError("SBCommandInterpreter is not valid");
573 result->SetStatus(eReturnStatusFailed);
577 void SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory(
578 SBCommandReturnObject &result) {
579 LLDB_RECORD_METHOD(void, SBCommandInterpreter,
580 SourceInitFileInCurrentWorkingDirectory,
581 (lldb::SBCommandReturnObject &), result);
583 result.Clear();
584 if (IsValid()) {
585 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
586 std::unique_lock<std::recursive_mutex> lock;
587 if (target_sp)
588 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
589 m_opaque_ptr->SourceInitFileCwd(result.ref());
590 } else {
591 result->AppendError("SBCommandInterpreter is not valid");
592 result->SetStatus(eReturnStatusFailed);
596 SBBroadcaster SBCommandInterpreter::GetBroadcaster() {
597 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBroadcaster, SBCommandInterpreter,
598 GetBroadcaster);
601 SBBroadcaster broadcaster(m_opaque_ptr, false);
604 return LLDB_RECORD_RESULT(broadcaster);
607 const char *SBCommandInterpreter::GetBroadcasterClass() {
608 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBCommandInterpreter,
609 GetBroadcasterClass);
611 return CommandInterpreter::GetStaticBroadcasterClass().AsCString();
614 const char *SBCommandInterpreter::GetArgumentTypeAsCString(
615 const lldb::CommandArgumentType arg_type) {
616 LLDB_RECORD_STATIC_METHOD(const char *, SBCommandInterpreter,
617 GetArgumentTypeAsCString,
618 (const lldb::CommandArgumentType), arg_type);
620 return CommandObject::GetArgumentTypeAsCString(arg_type);
623 const char *SBCommandInterpreter::GetArgumentDescriptionAsCString(
624 const lldb::CommandArgumentType arg_type) {
625 LLDB_RECORD_STATIC_METHOD(const char *, SBCommandInterpreter,
626 GetArgumentDescriptionAsCString,
627 (const lldb::CommandArgumentType), arg_type);
629 return CommandObject::GetArgumentDescriptionAsCString(arg_type);
632 bool SBCommandInterpreter::EventIsCommandInterpreterEvent(
633 const lldb::SBEvent &event) {
634 LLDB_RECORD_STATIC_METHOD(bool, SBCommandInterpreter,
635 EventIsCommandInterpreterEvent,
636 (const lldb::SBEvent &), event);
638 return event.GetBroadcasterClass() ==
639 SBCommandInterpreter::GetBroadcasterClass();
642 bool SBCommandInterpreter::SetCommandOverrideCallback(
643 const char *command_name, lldb::CommandOverrideCallback callback,
644 void *baton) {
645 LLDB_RECORD_DUMMY(bool, SBCommandInterpreter, SetCommandOverrideCallback,
646 (const char *, lldb::CommandOverrideCallback, void *),
647 command_name, callback, baton);
649 if (command_name && command_name[0] && IsValid()) {
650 llvm::StringRef command_name_str = command_name;
651 CommandObject *cmd_obj =
652 m_opaque_ptr->GetCommandObjectForCommand(command_name_str);
653 if (cmd_obj) {
654 assert(command_name_str.empty());
655 cmd_obj->SetOverrideCallback(callback, baton);
656 return true;
659 return false;
662 lldb::SBCommand SBCommandInterpreter::AddMultiwordCommand(const char *name,
663 const char *help) {
664 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommandInterpreter, AddMultiwordCommand,
665 (const char *, const char *), name, help);
667 CommandObjectMultiword *new_command =
668 new CommandObjectMultiword(*m_opaque_ptr, name, help);
669 new_command->SetRemovable(true);
670 lldb::CommandObjectSP new_command_sp(new_command);
671 if (new_command_sp &&
672 m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
673 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp));
674 return LLDB_RECORD_RESULT(lldb::SBCommand());
677 lldb::SBCommand SBCommandInterpreter::AddCommand(
678 const char *name, lldb::SBCommandPluginInterface *impl, const char *help) {
679 LLDB_RECORD_METHOD(
680 lldb::SBCommand, SBCommandInterpreter, AddCommand,
681 (const char *, lldb::SBCommandPluginInterface *, const char *), name,
682 impl, help);
684 lldb::CommandObjectSP new_command_sp;
685 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
686 *m_opaque_ptr, name, impl, help);
688 if (new_command_sp &&
689 m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
690 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp));
691 return LLDB_RECORD_RESULT(lldb::SBCommand());
694 lldb::SBCommand
695 SBCommandInterpreter::AddCommand(const char *name,
696 lldb::SBCommandPluginInterface *impl,
697 const char *help, const char *syntax) {
698 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommandInterpreter, AddCommand,
699 (const char *, lldb::SBCommandPluginInterface *,
700 const char *, const char *),
701 name, impl, help, syntax);
703 lldb::CommandObjectSP new_command_sp;
704 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
705 *m_opaque_ptr, name, impl, help, syntax);
707 if (new_command_sp &&
708 m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
709 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp));
710 return LLDB_RECORD_RESULT(lldb::SBCommand());
713 SBCommand::SBCommand() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCommand); }
715 SBCommand::SBCommand(lldb::CommandObjectSP cmd_sp) : m_opaque_sp(cmd_sp) {}
717 bool SBCommand::IsValid() {
718 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommand, IsValid);
719 return this->operator bool();
721 SBCommand::operator bool() const {
722 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommand, operator bool);
724 return m_opaque_sp.get() != nullptr;
727 const char *SBCommand::GetName() {
728 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetName);
730 return (IsValid() ? ConstString(m_opaque_sp->GetCommandName()).AsCString() : nullptr);
733 const char *SBCommand::GetHelp() {
734 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetHelp);
736 return (IsValid() ? ConstString(m_opaque_sp->GetHelp()).AsCString()
737 : nullptr);
740 const char *SBCommand::GetHelpLong() {
741 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetHelpLong);
743 return (IsValid() ? ConstString(m_opaque_sp->GetHelpLong()).AsCString()
744 : nullptr);
747 void SBCommand::SetHelp(const char *help) {
748 LLDB_RECORD_METHOD(void, SBCommand, SetHelp, (const char *), help);
750 if (IsValid())
751 m_opaque_sp->SetHelp(help);
754 void SBCommand::SetHelpLong(const char *help) {
755 LLDB_RECORD_METHOD(void, SBCommand, SetHelpLong, (const char *), help);
757 if (IsValid())
758 m_opaque_sp->SetHelpLong(help);
761 lldb::SBCommand SBCommand::AddMultiwordCommand(const char *name,
762 const char *help) {
763 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommand, AddMultiwordCommand,
764 (const char *, const char *), name, help);
766 if (!IsValid())
767 return LLDB_RECORD_RESULT(lldb::SBCommand());
768 if (!m_opaque_sp->IsMultiwordObject())
769 return LLDB_RECORD_RESULT(lldb::SBCommand());
770 CommandObjectMultiword *new_command = new CommandObjectMultiword(
771 m_opaque_sp->GetCommandInterpreter(), name, help);
772 new_command->SetRemovable(true);
773 lldb::CommandObjectSP new_command_sp(new_command);
774 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
775 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp));
776 return LLDB_RECORD_RESULT(lldb::SBCommand());
779 lldb::SBCommand SBCommand::AddCommand(const char *name,
780 lldb::SBCommandPluginInterface *impl,
781 const char *help) {
782 LLDB_RECORD_METHOD(
783 lldb::SBCommand, SBCommand, AddCommand,
784 (const char *, lldb::SBCommandPluginInterface *, const char *), name,
785 impl, help);
787 if (!IsValid())
788 return LLDB_RECORD_RESULT(lldb::SBCommand());
789 if (!m_opaque_sp->IsMultiwordObject())
790 return LLDB_RECORD_RESULT(lldb::SBCommand());
791 lldb::CommandObjectSP new_command_sp;
792 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
793 m_opaque_sp->GetCommandInterpreter(), name, impl, help);
794 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
795 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp));
796 return LLDB_RECORD_RESULT(lldb::SBCommand());
799 lldb::SBCommand SBCommand::AddCommand(const char *name,
800 lldb::SBCommandPluginInterface *impl,
801 const char *help, const char *syntax) {
802 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommand, AddCommand,
803 (const char *, lldb::SBCommandPluginInterface *,
804 const char *, const char *),
805 name, impl, help, syntax);
807 if (!IsValid())
808 return LLDB_RECORD_RESULT(lldb::SBCommand());
809 if (!m_opaque_sp->IsMultiwordObject())
810 return LLDB_RECORD_RESULT(lldb::SBCommand());
811 lldb::CommandObjectSP new_command_sp;
812 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
813 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax);
814 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
815 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp));
816 return LLDB_RECORD_RESULT(lldb::SBCommand());
819 uint32_t SBCommand::GetFlags() {
820 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBCommand, GetFlags);
822 return (IsValid() ? m_opaque_sp->GetFlags().Get() : 0);
825 void SBCommand::SetFlags(uint32_t flags) {
826 LLDB_RECORD_METHOD(void, SBCommand, SetFlags, (uint32_t), flags);
828 if (IsValid())
829 m_opaque_sp->GetFlags().Set(flags);
832 namespace lldb_private {
833 namespace repro {
835 template <>
836 void RegisterMethods<SBCommandInterpreterRunOptions>(Registry &R) {
837 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreterRunOptions, ());
838 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
839 GetStopOnContinue, ());
840 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions,
841 SetStopOnContinue, (bool));
842 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
843 GetStopOnError, ());
844 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnError,
845 (bool));
846 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
847 GetStopOnCrash, ());
848 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnCrash,
849 (bool));
850 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
851 GetEchoCommands, ());
852 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetEchoCommands,
853 (bool));
854 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
855 GetEchoCommentCommands, ());
856 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions,
857 SetEchoCommentCommands, (bool));
858 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
859 GetPrintResults, ());
860 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetPrintResults,
861 (bool));
862 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
863 GetAddToHistory, ());
864 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetAddToHistory,
865 (bool));
866 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreter,
867 (lldb_private::CommandInterpreter *));
868 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreter,
869 (const lldb::SBCommandInterpreter &));
870 LLDB_REGISTER_METHOD(
871 const lldb::SBCommandInterpreter &,
872 SBCommandInterpreter, operator=,(const lldb::SBCommandInterpreter &));
873 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, IsValid, ());
874 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, operator bool, ());
875 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, CommandExists,
876 (const char *));
877 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, AliasExists,
878 (const char *));
879 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, IsActive, ());
880 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, WasInterrupted, ());
881 LLDB_REGISTER_METHOD(const char *, SBCommandInterpreter,
882 GetIOHandlerControlSequence, (char));
883 LLDB_REGISTER_METHOD(lldb::ReturnStatus, SBCommandInterpreter,
884 HandleCommand,
885 (const char *, lldb::SBCommandReturnObject &, bool));
886 LLDB_REGISTER_METHOD(lldb::ReturnStatus, SBCommandInterpreter,
887 HandleCommand,
888 (const char *, lldb::SBExecutionContext &,
889 lldb::SBCommandReturnObject &, bool));
890 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, HandleCommandsFromFile,
891 (lldb::SBFileSpec &, lldb::SBExecutionContext &,
892 lldb::SBCommandInterpreterRunOptions &,
893 lldb::SBCommandReturnObject));
894 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, HandleCompletion,
895 (const char *, const char *, const char *, int, int,
896 lldb::SBStringList &));
897 LLDB_REGISTER_METHOD(int, SBCommandInterpreter,
898 HandleCompletionWithDescriptions,
899 (const char *, const char *, const char *, int, int,
900 lldb::SBStringList &, lldb::SBStringList &));
901 LLDB_REGISTER_METHOD(int, SBCommandInterpreter,
902 HandleCompletionWithDescriptions,
903 (const char *, uint32_t, int, int,
904 lldb::SBStringList &, lldb::SBStringList &));
905 LLDB_REGISTER_METHOD(
906 int, SBCommandInterpreter, HandleCompletion,
907 (const char *, uint32_t, int, int, lldb::SBStringList &));
908 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasCommands, ());
909 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasAliases, ());
910 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasAliasOptions, ());
911 LLDB_REGISTER_METHOD(lldb::SBProcess, SBCommandInterpreter, GetProcess, ());
912 LLDB_REGISTER_METHOD(lldb::SBDebugger, SBCommandInterpreter, GetDebugger,
913 ());
914 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, GetPromptOnQuit, ());
915 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, SetPromptOnQuit, (bool));
916 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, AllowExitCodeOnQuit,
917 (bool));
918 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasCustomQuitExitCode, ());
919 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, GetQuitStatus, ());
920 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, ResolveCommand,
921 (const char *, lldb::SBCommandReturnObject &));
922 LLDB_REGISTER_METHOD(void, SBCommandInterpreter,
923 SourceInitFileInHomeDirectory,
924 (lldb::SBCommandReturnObject &));
925 LLDB_REGISTER_METHOD(void, SBCommandInterpreter,
926 SourceInitFileInCurrentWorkingDirectory,
927 (lldb::SBCommandReturnObject &));
928 LLDB_REGISTER_METHOD(lldb::SBBroadcaster, SBCommandInterpreter,
929 GetBroadcaster, ());
930 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter,
931 GetBroadcasterClass, ());
932 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter,
933 GetArgumentTypeAsCString,
934 (const lldb::CommandArgumentType));
935 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter,
936 GetArgumentDescriptionAsCString,
937 (const lldb::CommandArgumentType));
938 LLDB_REGISTER_STATIC_METHOD(bool, SBCommandInterpreter,
939 EventIsCommandInterpreterEvent,
940 (const lldb::SBEvent &));
941 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommandInterpreter,
942 AddMultiwordCommand, (const char *, const char *));
943 LLDB_REGISTER_METHOD(
944 lldb::SBCommand, SBCommandInterpreter, AddCommand,
945 (const char *, lldb::SBCommandPluginInterface *, const char *));
946 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommandInterpreter, AddCommand,
947 (const char *, lldb::SBCommandPluginInterface *,
948 const char *, const char *));
949 LLDB_REGISTER_CONSTRUCTOR(SBCommand, ());
950 LLDB_REGISTER_METHOD(bool, SBCommand, IsValid, ());
951 LLDB_REGISTER_METHOD_CONST(bool, SBCommand, operator bool, ());
952 LLDB_REGISTER_METHOD(const char *, SBCommand, GetName, ());
953 LLDB_REGISTER_METHOD(const char *, SBCommand, GetHelp, ());
954 LLDB_REGISTER_METHOD(const char *, SBCommand, GetHelpLong, ());
955 LLDB_REGISTER_METHOD(void, SBCommand, SetHelp, (const char *));
956 LLDB_REGISTER_METHOD(void, SBCommand, SetHelpLong, (const char *));
957 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommand, AddMultiwordCommand,
958 (const char *, const char *));
959 LLDB_REGISTER_METHOD(
960 lldb::SBCommand, SBCommand, AddCommand,
961 (const char *, lldb::SBCommandPluginInterface *, const char *));
962 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommand, AddCommand,
963 (const char *, lldb::SBCommandPluginInterface *,
964 const char *, const char *));
965 LLDB_REGISTER_METHOD(uint32_t, SBCommand, GetFlags, ());
966 LLDB_REGISTER_METHOD(void, SBCommand, SetFlags, (uint32_t));