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->GetDebugger().GetSelectedTarget());
387 if (target_sp) {
388 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
389 process_sp = target_sp->GetProcessSP();
390 sb_process.SetSP(process_sp);
391 }
392 }
393
394 return sb_process;
395}
396
398 LLDB_INSTRUMENT_VA(this);
399
400 SBDebugger sb_debugger;
401 if (IsValid())
402 sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this());
403
404 return sb_debugger;
405}
406
408 LLDB_INSTRUMENT_VA(this);
409
410 return (IsValid() ? m_opaque_ptr->GetPromptOnQuit() : false);
411}
412
414 LLDB_INSTRUMENT_VA(this, b);
415
416 if (IsValid())
417 m_opaque_ptr->SetPromptOnQuit(b);
418}
419
421 LLDB_INSTRUMENT_VA(this, allow);
422
423 if (m_opaque_ptr)
424 m_opaque_ptr->AllowExitCodeOnQuit(allow);
425}
426
428 LLDB_INSTRUMENT_VA(this);
429
430 bool exited = false;
431 if (m_opaque_ptr)
432 m_opaque_ptr->GetQuitExitCode(exited);
433 return exited;
434}
435
437 LLDB_INSTRUMENT_VA(this);
438
439 bool exited = false;
440 return (m_opaque_ptr ? m_opaque_ptr->GetQuitExitCode(exited) : 0);
441}
442
443void SBCommandInterpreter::ResolveCommand(const char *command_line,
444 SBCommandReturnObject &result) {
445 LLDB_INSTRUMENT_VA(this, command_line, result);
446
447 result.Clear();
448 if (command_line && IsValid()) {
449 m_opaque_ptr->ResolveCommand(command_line, result.ref());
450 } else {
451 result->AppendError(
452 "SBCommandInterpreter or the command line is not valid");
453 }
454}
455
457
462
465 m_opaque_ptr = interpreter;
466}
467
469 SBCommandReturnObject &result) {
470 LLDB_INSTRUMENT_VA(this, result);
471
472 result.Clear();
473 if (IsValid()) {
474 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
475 std::unique_lock<std::recursive_mutex> lock;
476 if (target_sp)
477 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
478 m_opaque_ptr->SourceInitFileGlobal(result.ref());
479 } else {
480 result->AppendError("SBCommandInterpreter is not valid");
481 }
482}
483
485 SBCommandReturnObject &result) {
486 LLDB_INSTRUMENT_VA(this, result);
487
488 SourceInitFileInHomeDirectory(result, /*is_repl=*/false);
489}
490
492 SBCommandReturnObject &result, bool is_repl) {
493 LLDB_INSTRUMENT_VA(this, result, is_repl);
494
495 result.Clear();
496 if (IsValid()) {
497 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
498 std::unique_lock<std::recursive_mutex> lock;
499 if (target_sp)
500 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
501 m_opaque_ptr->SourceInitFileHome(result.ref(), is_repl);
502 } else {
503 result->AppendError("SBCommandInterpreter is not valid");
504 }
505}
506
508 SBCommandReturnObject &result) {
509 LLDB_INSTRUMENT_VA(this, result);
510
511 result.Clear();
512 if (IsValid()) {
513 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
514 std::unique_lock<std::recursive_mutex> lock;
515 if (target_sp)
516 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
517 m_opaque_ptr->SourceInitFileCwd(result.ref());
518 } else {
519 result->AppendError("SBCommandInterpreter is not valid");
520 }
521}
522
524 LLDB_INSTRUMENT_VA(this);
525
526 SBBroadcaster broadcaster(m_opaque_ptr, false);
527
528 return broadcaster;
529}
530
537
545
553
555 const lldb::SBEvent &event) {
556 LLDB_INSTRUMENT_VA(event);
557
558 return event.GetBroadcasterClass() ==
560}
561
563 const char *command_name, lldb::CommandOverrideCallback callback,
564 void *baton) {
565 LLDB_INSTRUMENT_VA(this, command_name, callback, baton);
566
567 if (command_name && command_name[0] && IsValid()) {
568 llvm::StringRef command_name_str = command_name;
569 CommandObject *cmd_obj =
570 m_opaque_ptr->GetCommandObjectForCommand(command_name_str);
571 if (cmd_obj) {
572 assert(command_name_str.empty());
573 cmd_obj->SetOverrideCallback(callback, baton);
574 return true;
575 }
576 }
577 return false;
578}
579
581 LLDB_INSTRUMENT_VA(this);
582
583 SBStructuredData data;
584 if (!IsValid())
585 return data;
586
587 std::string json_str =
588 llvm::formatv("{0:2}", m_opaque_ptr->GetStatistics()).str();
589 data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
590 return data;
591}
592
594 LLDB_INSTRUMENT_VA(this);
595
596 SBStructuredData data;
597 if (IsValid())
598 // A deep copy is performed by `std::make_shared` on the
599 // `StructuredData::Array`, via its implicitly-declared copy constructor.
600 // This ensures thread-safety between the user changing the returned
601 // `SBStructuredData` and the `CommandInterpreter` changing its internal
602 // `m_transcript`.
603 data.m_impl_up->SetObjectSP(
604 std::make_shared<StructuredData::Array>(m_opaque_ptr->GetTranscript()));
605 return data;
606}
607
609 const char *help) {
610 LLDB_INSTRUMENT_VA(this, name, help);
611
612 lldb::CommandObjectSP new_command_sp(
613 new CommandObjectMultiword(*m_opaque_ptr, name, help));
614 new_command_sp->GetAsMultiwordCommand()->SetRemovable(true);
615 Status add_error = m_opaque_ptr->AddUserCommand(name, new_command_sp, true);
616 if (add_error.Success())
617 return lldb::SBCommand(new_command_sp);
618 return lldb::SBCommand();
619}
620
622 const char *name, lldb::SBCommandPluginInterface *impl, const char *help) {
623 LLDB_INSTRUMENT_VA(this, name, impl, help);
624
625 return AddCommand(name, impl, help, /*syntax=*/nullptr,
626 /*auto_repeat_command=*/"");
627}
628
632 const char *help, const char *syntax) {
633 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax);
634 return AddCommand(name, impl, help, syntax, /*auto_repeat_command=*/"");
635}
636
638 const char *name, lldb::SBCommandPluginInterface *impl, const char *help,
639 const char *syntax, const char *auto_repeat_command) {
640 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax, auto_repeat_command);
641
642 lldb::CommandObjectSP new_command_sp;
643 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
644 *m_opaque_ptr, name, impl, help, syntax, /*flags=*/0,
645 auto_repeat_command);
646
647 Status add_error = m_opaque_ptr->AddUserCommand(name, new_command_sp, true);
648 if (add_error.Success())
649 return lldb::SBCommand(new_command_sp);
650 return lldb::SBCommand();
651}
652
654
656
658 LLDB_INSTRUMENT_VA(this);
659 return this->operator bool();
660}
661SBCommand::operator bool() const {
662 LLDB_INSTRUMENT_VA(this);
663
664 return m_opaque_sp.get() != nullptr;
665}
666
667const char *SBCommand::GetName() {
668 LLDB_INSTRUMENT_VA(this);
669
670 return (IsValid()
671 ? ConstString(m_opaque_sp->GetCommandName()).AsCString(nullptr)
672 : nullptr);
673}
674
675const char *SBCommand::GetHelp() {
676 LLDB_INSTRUMENT_VA(this);
677
678 return (IsValid() ? ConstString(m_opaque_sp->GetHelp()).AsCString(nullptr)
679 : nullptr);
680}
681
683 LLDB_INSTRUMENT_VA(this);
684
685 return (IsValid() ? ConstString(m_opaque_sp->GetHelpLong()).AsCString(nullptr)
686 : nullptr);
687}
688
689void SBCommand::SetHelp(const char *help) {
690 LLDB_INSTRUMENT_VA(this, help);
691
692 if (IsValid())
693 m_opaque_sp->SetHelp(help);
694}
695
696void SBCommand::SetHelpLong(const char *help) {
697 LLDB_INSTRUMENT_VA(this, help);
698
699 if (IsValid())
700 m_opaque_sp->SetHelpLong(help);
701}
702
704 const char *help) {
705 LLDB_INSTRUMENT_VA(this, name, help);
706
707 if (!IsValid())
708 return lldb::SBCommand();
709 if (!m_opaque_sp->IsMultiwordObject())
710 return lldb::SBCommand();
712 m_opaque_sp->GetCommandInterpreter(), name, help);
713 new_command->SetRemovable(true);
714 lldb::CommandObjectSP new_command_sp(new_command);
715 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
716 return lldb::SBCommand(new_command_sp);
717 return lldb::SBCommand();
718}
719
722 const char *help) {
723 LLDB_INSTRUMENT_VA(this, name, impl, help);
724 return AddCommand(name, impl, help, /*syntax=*/nullptr,
725 /*auto_repeat_command=*/"");
726}
727
730 const char *help, const char *syntax) {
731 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax);
732 return AddCommand(name, impl, help, syntax, /*auto_repeat_command=*/"");
733}
734
737 const char *help, const char *syntax,
738 const char *auto_repeat_command) {
739 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax, auto_repeat_command);
740
741 if (!IsValid())
742 return lldb::SBCommand();
743 if (!m_opaque_sp->IsMultiwordObject())
744 return lldb::SBCommand();
745 lldb::CommandObjectSP new_command_sp;
746 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
747 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax,
748 /*flags=*/0, auto_repeat_command);
749 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
750 return lldb::SBCommand(new_command_sp);
751 return lldb::SBCommand();
752}
753
755 LLDB_INSTRUMENT_VA(this);
756
757 return (IsValid() ? m_opaque_sp->GetFlags().Get() : 0);
758}
759
760void SBCommand::SetFlags(uint32_t flags) {
761 LLDB_INSTRUMENT_VA(this, flags);
762
763 if (IsValid())
764 m_opaque_sp->GetFlags().Set(flags);
765}
766
768 lldb::SBCommandPrintCallback callback, void *baton) {
769 LLDB_INSTRUMENT_VA(this, callback, baton);
770
771 if (m_opaque_ptr)
772 m_opaque_ptr->SetPrintCallback(
773 [callback, baton](lldb_private::CommandReturnObject &result) {
774 SBCommandReturnObject sb_result(result);
775 return callback(sb_result, baton);
776 });
777}
#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:44
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:57
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 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:149
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.