LLDB mainline
SBCommandInterpreter.cpp
Go to the documentation of this file.
1//===-- SBCommandInterpreter.cpp ------------------------------------------===//
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//===----------------------------------------------------------------------===//
8
10#include "lldb/lldb-types.h"
11
15#include "lldb/Target/Target.h"
18
23#include "lldb/API/SBEvent.h"
25#include "lldb/API/SBListener.h"
26#include "lldb/API/SBProcess.h"
27#include "lldb/API/SBStream.h"
29#include "lldb/API/SBTarget.h"
30
31#include <memory>
32#include <optional>
33
34using namespace lldb;
35using namespace lldb_private;
36
37namespace lldb_private {
39public:
41 const char *name,
43 const char *help = nullptr,
44 const char *syntax = nullptr,
45 uint32_t flags = 0,
46 const char *auto_repeat_command = "")
47 : CommandObjectParsed(interpreter, name, help, syntax, flags),
48 m_backend(backend) {
50 auto_repeat_command == nullptr
51 ? std::nullopt
52 : std::optional<std::string>(auto_repeat_command);
53 // We don't know whether any given command coming from this interface takes
54 // arguments or not so here we're just disabling the basic args check.
56 m_arguments.push_back({none_arg});
57 }
58
59 bool IsRemovable() const override { return true; }
60
61 /// More documentation is available in lldb::CommandObject::GetRepeatCommand,
62 /// but in short, if std::nullopt is returned, the previous command will be
63 /// repeated, and if an empty string is returned, no commands will be
64 /// executed.
65 std::optional<std::string> GetRepeatCommand(Args &current_command_args,
66 uint32_t index) override {
68 return std::nullopt;
69 else
71 }
72
73protected:
74 void DoExecute(Args &command, CommandReturnObject &result) override {
75 SBCommandReturnObject sb_return(result);
76 SBCommandInterpreter sb_interpreter(&m_interpreter);
77 SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this());
78 bool success = m_backend->DoExecute(debugger_sb,
79 command.GetArgumentVector(), sb_return);
80 // If the plugin command did not set its own status, infer it from the
81 // boolean return value so that callers always see a defined status.
82 if (result.GetStatus() == eReturnStatusInvalid)
85 }
87 std::optional<std::string> m_auto_repeat_command;
88};
89} // namespace lldb_private
90
94
96 : m_opaque_ptr(interpreter) {
97 LLDB_INSTRUMENT_VA(this, interpreter);
98}
99
104
106
109 LLDB_INSTRUMENT_VA(this, rhs);
110
112 return *this;
113}
114
116 LLDB_INSTRUMENT_VA(this);
117 return this->operator bool();
118}
119SBCommandInterpreter::operator bool() const {
120 LLDB_INSTRUMENT_VA(this);
121
122 return m_opaque_ptr != nullptr;
123}
124
126 LLDB_INSTRUMENT_VA(this, cmd);
127
128 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->CommandExists(cmd)
129 : false);
130}
131
133 LLDB_INSTRUMENT_VA(this, cmd);
134
135 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->UserCommandExists(cmd)
136 : false);
137}
138
140 LLDB_INSTRUMENT_VA(this, cmd);
141
142 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->AliasExists(cmd)
143 : false);
144}
145
147 LLDB_INSTRUMENT_VA(this);
148
149 return (IsValid() ? m_opaque_ptr->IsActive() : false);
150}
151
153 LLDB_INSTRUMENT_VA(this);
154
155 return (IsValid() ? m_opaque_ptr->GetDebugger().InterruptRequested() : false);
156}
157
159 LLDB_INSTRUMENT_VA(this);
160
161 return (IsValid() ? m_opaque_ptr->InterruptCommand() : false);
162}
163
165 LLDB_INSTRUMENT_VA(this, ch);
166
167 if (!IsValid())
168 return nullptr;
169
170 return ConstString(
171 m_opaque_ptr->GetDebugger().GetTopIOHandlerControlSequence(ch))
172 .GetCString();
173}
174
176SBCommandInterpreter::HandleCommand(const char *command_line,
177 SBCommandReturnObject &result,
178 bool add_to_history) {
179 LLDB_INSTRUMENT_VA(this, command_line, result, add_to_history);
180
181 SBExecutionContext sb_exe_ctx;
182 return HandleCommand(command_line, sb_exe_ctx, result, add_to_history);
183}
184
186 const char *command_line, SBExecutionContext &override_context,
187 SBCommandReturnObject &result, bool add_to_history) {
188 LLDB_INSTRUMENT_VA(this, command_line, override_context, result,
189 add_to_history);
190
191 result.Clear();
192 if (command_line && IsValid()) {
193 result.ref().SetInteractive(false);
194 auto do_add_to_history = add_to_history ? eLazyBoolYes : eLazyBoolNo;
195 if (override_context.get())
196 m_opaque_ptr->HandleCommand(command_line, do_add_to_history,
197 override_context.get()->Lock(true),
198 result.ref());
199 else
200 m_opaque_ptr->HandleCommand(command_line, do_add_to_history,
201 result.ref());
202 } else {
203 result->AppendError(
204 "SBCommandInterpreter or the command line is not valid");
205 }
206
207 return result.GetStatus();
208}
209
211 lldb::SBFileSpec &file, lldb::SBExecutionContext &override_context,
214 LLDB_INSTRUMENT_VA(this, file, override_context, options, result);
215
216 if (!IsValid()) {
217 result->AppendError("SBCommandInterpreter is not valid");
218 return;
219 }
220
221 if (!file.IsValid()) {
222 SBStream s;
223 file.GetDescription(s);
224 result->AppendErrorWithFormat("File is not valid: %s", s.GetData());
225 }
226
227 FileSpec tmp_spec = file.ref();
228 if (override_context.get())
229 m_opaque_ptr->HandleCommandsFromFile(tmp_spec,
230 override_context.get()->Lock(true),
231 options.ref(), result.ref());
232
233 else
234 m_opaque_ptr->HandleCommandsFromFile(tmp_spec, options.ref(), result.ref());
235}
236
238 const char *current_line, const char *cursor, const char *last_char,
239 int match_start_point, int max_return_elements, SBStringList &matches) {
240 LLDB_INSTRUMENT_VA(this, current_line, cursor, last_char, match_start_point,
241 max_return_elements, matches);
242
243 SBStringList dummy_descriptions;
245 current_line, cursor, last_char, match_start_point, max_return_elements,
246 matches, dummy_descriptions);
247}
248
250 const char *current_line, const char *cursor, const char *last_char,
251 int match_start_point, int max_return_elements, SBStringList &matches,
252 SBStringList &descriptions) {
253 LLDB_INSTRUMENT_VA(this, current_line, cursor, last_char, match_start_point,
254 max_return_elements, matches, descriptions);
255
256 // Sanity check the arguments that are passed in: cursor & last_char have to
257 // be within the current_line.
258 if (current_line == nullptr || cursor == nullptr || last_char == nullptr)
259 return 0;
260
261 if (cursor < current_line || last_char < current_line)
262 return 0;
263
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))
267 return 0;
268
269 if (!IsValid())
270 return 0;
271
272 if (max_return_elements == 0)
273 return 0;
274
275 lldb_private::StringList lldb_matches, lldb_descriptions;
276 CompletionResult result;
277 CompletionRequest request(current_line, cursor - current_line, result);
278 if (max_return_elements > 0)
279 request.SetMaxReturnElements(max_return_elements);
280 m_opaque_ptr->HandleCompletion(request);
281 result.GetMatches(lldb_matches);
282 result.GetDescriptions(lldb_descriptions);
283
284 // limit the matches to the max_return_elements if necessary
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);
289 }
290 int number_of_matches = lldb_matches.GetSize();
291
292 // Make the result array indexed from 1 again by adding the 'common prefix'
293 // of all completions as element 0. This is done to emulate the old API.
294 if (request.GetParsedLine().GetArgumentCount() == 0) {
295 // If we got an empty string, insert nothing.
296 lldb_matches.InsertStringAtIndex(0, "");
297 lldb_descriptions.InsertStringAtIndex(0, "");
298 } else {
299 // Now figure out if there is a common substring, and if so put that in
300 // element 0, otherwise put an empty string in element 0.
301 std::string command_partial_str = request.GetCursorArgumentPrefix().str();
302
303 std::string common_prefix = lldb_matches.LongestCommonPrefix();
304 const size_t partial_name_len = command_partial_str.size();
305 common_prefix.erase(0, partial_name_len);
306
307 // If we matched a unique single command, add a space... Only do this if
308 // the completer told us this was a complete word, however...
309 if (lldb_matches.GetSize() == 1) {
310 char quote_char = request.GetParsedArg().GetQuoteChar();
311 common_prefix =
312 Args::EscapeLLDBCommandArgument(common_prefix, quote_char);
313 if (request.GetParsedArg().IsQuoted())
314 common_prefix.push_back(quote_char);
315 common_prefix.push_back(' ');
316 }
317 lldb_matches.InsertStringAtIndex(0, common_prefix.c_str());
318 lldb_descriptions.InsertStringAtIndex(0, "");
319 }
320
321 SBStringList temp_matches_list(&lldb_matches);
322 matches.AppendList(temp_matches_list);
323 SBStringList temp_descriptions_list(&lldb_descriptions);
324 descriptions.AppendList(temp_descriptions_list);
325 return number_of_matches;
326}
327
329 const char *current_line, uint32_t cursor_pos, int match_start_point,
330 int max_return_elements, SBStringList &matches,
331 SBStringList &descriptions) {
332 LLDB_INSTRUMENT_VA(this, current_line, cursor_pos, match_start_point,
333 max_return_elements, matches, descriptions);
334
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);
340}
341
342int SBCommandInterpreter::HandleCompletion(const char *current_line,
343 uint32_t cursor_pos,
344 int match_start_point,
345 int max_return_elements,
346 lldb::SBStringList &matches) {
347 LLDB_INSTRUMENT_VA(this, current_line, cursor_pos, match_start_point,
348 max_return_elements, matches);
349
350 const char *cursor = current_line + cursor_pos;
351 const char *last_char = current_line + strlen(current_line);
352 return HandleCompletion(current_line, cursor, last_char, match_start_point,
353 max_return_elements, matches);
354}
355
357 LLDB_INSTRUMENT_VA(this);
358
359 return (IsValid() ? m_opaque_ptr->HasCommands() : false);
360}
361
363 LLDB_INSTRUMENT_VA(this);
364
365 return (IsValid() ? m_opaque_ptr->HasAliases() : false);
366}
367
369 LLDB_INSTRUMENT_VA(this);
370
371 return (IsValid() ? m_opaque_ptr->HasAliasOptions() : false);
372}
373
375 LLDB_INSTRUMENT_VA(this);
376
377 return (IsValid() ? m_opaque_ptr->IsInteractive() : false);
378}
379
381 LLDB_INSTRUMENT_VA(this);
382
383 SBProcess sb_process;
384 ProcessSP process_sp;
385 if (IsValid()) {
386 TargetSP target_sp(m_opaque_ptr->GetSelectedTarget());
387 if (target_sp) {
388 TargetAPIMutex api_lock = target_sp->GetAPIMutex();
389 std::lock_guard<TargetAPIMutex> guard(api_lock);
390 process_sp = target_sp->GetProcessSP();
391 sb_process.SetSP(process_sp);
392 }
393 }
394
395 return sb_process;
396}
397
399 LLDB_INSTRUMENT_VA(this);
400
401 SBDebugger sb_debugger;
402 if (IsValid())
403 sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this());
404
405 return sb_debugger;
406}
407
409 LLDB_INSTRUMENT_VA(this);
410
411 return (IsValid() ? m_opaque_ptr->GetPromptOnQuit() : false);
412}
413
415 LLDB_INSTRUMENT_VA(this, b);
416
417 if (IsValid())
418 m_opaque_ptr->SetPromptOnQuit(b);
419}
420
422 LLDB_INSTRUMENT_VA(this, allow);
423
424 if (m_opaque_ptr)
425 m_opaque_ptr->AllowExitCodeOnQuit(allow);
426}
427
429 LLDB_INSTRUMENT_VA(this);
430
431 bool exited = false;
432 if (m_opaque_ptr)
433 m_opaque_ptr->GetQuitExitCode(exited);
434 return exited;
435}
436
438 LLDB_INSTRUMENT_VA(this);
439
440 bool exited = false;
441 return (m_opaque_ptr ? m_opaque_ptr->GetQuitExitCode(exited) : 0);
442}
443
444void SBCommandInterpreter::ResolveCommand(const char *command_line,
445 SBCommandReturnObject &result) {
446 LLDB_INSTRUMENT_VA(this, command_line, result);
447
448 result.Clear();
449 if (command_line && IsValid()) {
450 m_opaque_ptr->ResolveCommand(command_line, result.ref());
451 } else {
452 result->AppendError(
453 "SBCommandInterpreter or the command line is not valid");
454 }
455}
456
458
463
466 m_opaque_ptr = interpreter;
467}
468
470 SBCommandReturnObject &result) {
471 LLDB_INSTRUMENT_VA(this, result);
472
473 result.Clear();
474 if (IsValid()) {
475 TargetSP target_sp(m_opaque_ptr->GetSelectedTarget());
476 TargetAPIMutex api_lock;
477 std::unique_lock<TargetAPIMutex> guard;
478 if (target_sp) {
479 api_lock = TargetAPIMutex(target_sp->GetAPIMutex());
480 guard = std::unique_lock<TargetAPIMutex>(api_lock);
481 }
482 m_opaque_ptr->SourceInitFileGlobal(result.ref());
483 } else {
484 result->AppendError("SBCommandInterpreter is not valid");
485 }
486}
487
489 SBCommandReturnObject &result) {
490 LLDB_INSTRUMENT_VA(this, result);
491
492 SourceInitFileInHomeDirectory(result, /*is_repl=*/false);
493}
494
496 SBCommandReturnObject &result, bool is_repl) {
497 LLDB_INSTRUMENT_VA(this, result, is_repl);
498
499 result.Clear();
500 if (IsValid()) {
501 TargetSP target_sp(m_opaque_ptr->GetSelectedTarget());
502 TargetAPIMutex api_lock;
503 std::unique_lock<TargetAPIMutex> guard;
504 if (target_sp) {
505 api_lock = TargetAPIMutex(target_sp->GetAPIMutex());
506 guard = std::unique_lock<TargetAPIMutex>(api_lock);
507 }
508 m_opaque_ptr->SourceInitFileHome(result.ref(), is_repl);
509 } else {
510 result->AppendError("SBCommandInterpreter is not valid");
511 }
512}
513
515 SBCommandReturnObject &result) {
516 LLDB_INSTRUMENT_VA(this, result);
517
518 result.Clear();
519 if (IsValid()) {
520 TargetSP target_sp(m_opaque_ptr->GetSelectedTarget());
521 TargetAPIMutex api_lock;
522 std::unique_lock<TargetAPIMutex> guard;
523 if (target_sp) {
524 api_lock = TargetAPIMutex(target_sp->GetAPIMutex());
525 guard = std::unique_lock<TargetAPIMutex>(api_lock);
526 }
527 m_opaque_ptr->SourceInitFileCwd(result.ref());
528 } else {
529 result->AppendError("SBCommandInterpreter is not valid");
530 }
531}
532
534 LLDB_INSTRUMENT_VA(this);
535
536 SBBroadcaster broadcaster(m_opaque_ptr, false);
537
538 return broadcaster;
539}
540
547
555
563
565 const lldb::SBEvent &event) {
566 LLDB_INSTRUMENT_VA(event);
567
568 return event.GetBroadcasterClass() ==
570}
571
573 const char *command_name, lldb::CommandOverrideCallback callback,
574 void *baton) {
575 LLDB_INSTRUMENT_VA(this, command_name, callback, baton);
576
577 if (command_name && command_name[0] && IsValid()) {
578 llvm::StringRef command_name_str = command_name;
579 CommandObject *cmd_obj =
580 m_opaque_ptr->GetCommandObjectForCommand(command_name_str);
581 if (cmd_obj) {
582 assert(command_name_str.empty());
583 cmd_obj->SetOverrideCallback(callback, baton);
584 return true;
585 }
586 }
587 return false;
588}
589
591 LLDB_INSTRUMENT_VA(this);
592
593 SBStructuredData data;
594 if (!IsValid())
595 return data;
596
597 std::string json_str =
598 llvm::formatv("{0:2}", m_opaque_ptr->GetStatistics()).str();
599 data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
600 return data;
601}
602
604 LLDB_INSTRUMENT_VA(this);
605
606 SBStructuredData data;
607 if (IsValid())
608 // A deep copy is performed by `std::make_shared` on the
609 // `StructuredData::Array`, via its implicitly-declared copy constructor.
610 // This ensures thread-safety between the user changing the returned
611 // `SBStructuredData` and the `CommandInterpreter` changing its internal
612 // `m_transcript`.
613 data.m_impl_up->SetObjectSP(
614 std::make_shared<StructuredData::Array>(m_opaque_ptr->GetTranscript()));
615 return data;
616}
617
619 const char *help) {
620 LLDB_INSTRUMENT_VA(this, name, help);
621
622 lldb::CommandObjectSP new_command_sp(
623 new CommandObjectMultiword(*m_opaque_ptr, name, help));
624 new_command_sp->GetAsMultiwordCommand()->SetRemovable(true);
625 Status add_error = m_opaque_ptr->AddUserCommand(name, new_command_sp, true);
626 if (add_error.Success())
627 return lldb::SBCommand(new_command_sp);
628 return lldb::SBCommand();
629}
630
632 const char *name, lldb::SBCommandPluginInterface *impl, const char *help) {
633 LLDB_INSTRUMENT_VA(this, name, impl, help);
634
635 return AddCommand(name, impl, help, /*syntax=*/nullptr,
636 /*auto_repeat_command=*/"");
637}
638
642 const char *help, const char *syntax) {
643 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax);
644 return AddCommand(name, impl, help, syntax, /*auto_repeat_command=*/"");
645}
646
648 const char *name, lldb::SBCommandPluginInterface *impl, const char *help,
649 const char *syntax, const char *auto_repeat_command) {
650 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax, auto_repeat_command);
651
652 lldb::CommandObjectSP new_command_sp;
653 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
654 *m_opaque_ptr, name, impl, help, syntax, /*flags=*/0,
655 auto_repeat_command);
656
657 Status add_error = m_opaque_ptr->AddUserCommand(name, new_command_sp, true);
658 if (add_error.Success())
659 return lldb::SBCommand(new_command_sp);
660 return lldb::SBCommand();
661}
662
664
666
668 LLDB_INSTRUMENT_VA(this);
669 return this->operator bool();
670}
671SBCommand::operator bool() const {
672 LLDB_INSTRUMENT_VA(this);
673
674 return m_opaque_sp.get() != nullptr;
675}
676
677const char *SBCommand::GetName() {
678 LLDB_INSTRUMENT_VA(this);
679
680 return (IsValid()
681 ? ConstString(m_opaque_sp->GetCommandName()).AsCString(nullptr)
682 : nullptr);
683}
684
685const char *SBCommand::GetHelp() {
686 LLDB_INSTRUMENT_VA(this);
687
688 return (IsValid() ? ConstString(m_opaque_sp->GetHelp()).AsCString(nullptr)
689 : nullptr);
690}
691
693 LLDB_INSTRUMENT_VA(this);
694
695 return (IsValid() ? ConstString(m_opaque_sp->GetHelpLong()).AsCString(nullptr)
696 : nullptr);
697}
698
699void SBCommand::SetHelp(const char *help) {
700 LLDB_INSTRUMENT_VA(this, help);
701
702 if (IsValid())
703 m_opaque_sp->SetHelp(help);
704}
705
706void SBCommand::SetHelpLong(const char *help) {
707 LLDB_INSTRUMENT_VA(this, help);
708
709 if (IsValid())
710 m_opaque_sp->SetHelpLong(help);
711}
712
714 const char *help) {
715 LLDB_INSTRUMENT_VA(this, name, help);
716
717 if (!IsValid())
718 return lldb::SBCommand();
719 if (!m_opaque_sp->IsMultiwordObject())
720 return lldb::SBCommand();
722 m_opaque_sp->GetCommandInterpreter(), name, help);
723 new_command->SetRemovable(true);
724 lldb::CommandObjectSP new_command_sp(new_command);
725 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
726 return lldb::SBCommand(new_command_sp);
727 return lldb::SBCommand();
728}
729
732 const char *help) {
733 LLDB_INSTRUMENT_VA(this, name, impl, help);
734 return AddCommand(name, impl, help, /*syntax=*/nullptr,
735 /*auto_repeat_command=*/"");
736}
737
740 const char *help, const char *syntax) {
741 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax);
742 return AddCommand(name, impl, help, syntax, /*auto_repeat_command=*/"");
743}
744
747 const char *help, const char *syntax,
748 const char *auto_repeat_command) {
749 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax, auto_repeat_command);
750
751 if (!IsValid())
752 return lldb::SBCommand();
753 if (!m_opaque_sp->IsMultiwordObject())
754 return lldb::SBCommand();
755 lldb::CommandObjectSP new_command_sp;
756 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
757 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax,
758 /*flags=*/0, auto_repeat_command);
759 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
760 return lldb::SBCommand(new_command_sp);
761 return lldb::SBCommand();
762}
763
765 LLDB_INSTRUMENT_VA(this);
766
767 return (IsValid() ? m_opaque_sp->GetFlags().Get() : 0);
768}
769
770void SBCommand::SetFlags(uint32_t flags) {
771 LLDB_INSTRUMENT_VA(this, flags);
772
773 if (IsValid())
774 m_opaque_sp->GetFlags().Set(flags);
775}
776
778 lldb::SBCommandPrintCallback callback, void *baton) {
779 LLDB_INSTRUMENT_VA(this, callback, baton);
780
781 if (m_opaque_ptr)
782 m_opaque_ptr->SetPrintCallback(
783 [callback, baton](lldb_private::CommandReturnObject &result) {
784 SBCommandReturnObject sb_result(result);
785 return callback(sb_result, baton);
786 });
787}
#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_private::CommandInterpreter & ref()
void ResolveCommand(const char *command_line, SBCommandReturnObject &result)
Resolve the command just as HandleCommand would, expanding abbreviations and aliases.
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)
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_private::CommandReturnObject & ref() const
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
bool IsValid() const
const lldb_private::FileSpec & ref() const
bool GetDescription(lldb::SBStream &description) const
void SetSP(const lldb::ProcessSP &process_sp)
const char * GetData()
Definition SBStream.cpp:45
void AppendList(const char **strv, int strc)
StructuredDataImplUP m_impl_up
A command line argument class.
Definition Args.h:33
char ** GetArgumentVector()
Gets the argument vector.
Definition Args.cpp:279
static std::string EscapeLLDBCommandArgument(const std::string &arg, char quote_char)
Definition Args.cpp:613
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition Args.h:120
static llvm::StringRef GetStaticBroadcasterClass()
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)
std::optional< std::string > GetRepeatCommand(Args &current_command_args, uint32_t index) override
More documentation is available in lldb::CommandObject::GetRepeatCommand, but in short,...
void DoExecute(Args &command, CommandReturnObject &result) override
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="")
void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
"lldb/Utility/ArgCompletionRequest.h"
void SetMaxReturnElements(size_t max_return_elements)
Sets the maximum number of completions that should be returned.
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.
Definition ConstString.h:40
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.
A file utility class.
Definition FileSpec.h:56
An error handling class.
Definition Status.h:118
bool Success() const
Test for success condition.
Definition Status.cpp:303
void InsertStringAtIndex(size_t idx, const std::string &str)
void SetSize(size_t n)
Definition StringList.h:56
std::string LongestCommonPrefix()
static ObjectSP ParseJSON(llvm::StringRef json_text)
A Lockable handle over a Target's API mutex, returned by Target::GetAPIMutex() and backing the public...
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
class LLDB_API SBCommand
Definition SBDefines.h:56
lldb::CommandReturnObjectCallbackResult(* SBCommandPrintCallback)(lldb::SBCommandReturnObject &result, void *baton)
Definition SBDefines.h:150
std::shared_ptr< lldb_private::Process > ProcessSP
ReturnStatus
Command Return Status Types.
@ eReturnStatusFailed
@ eReturnStatusSuccessFinishResult
@ eReturnStatusInvalid
bool(* CommandOverrideCallback)(void *baton, const char **argv)
Definition lldb-types.h:74
std::shared_ptr< lldb_private::Target > TargetSP
bool IsQuoted() const
Returns true if this argument was quoted in any way.
Definition Args.h:54
char GetQuoteChar() const
Definition Args.h:55
Used to build individual command argument lists.