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"
19
24#include "lldb/API/SBEvent.h"
26#include "lldb/API/SBListener.h"
27#include "lldb/API/SBProcess.h"
28#include "lldb/API/SBStream.h"
30#include "lldb/API/SBTarget.h"
31
32#include <memory>
33#include <optional>
34
35using namespace lldb;
36using namespace lldb_private;
37
38namespace lldb_private {
40public:
42 const char *name,
44 const char *help = nullptr,
45 const char *syntax = nullptr,
46 uint32_t flags = 0,
47 const char *auto_repeat_command = "")
48 : CommandObjectParsed(interpreter, name, help, syntax, flags),
49 m_backend(backend) {
51 auto_repeat_command == nullptr
52 ? std::nullopt
53 : std::optional<std::string>(auto_repeat_command);
54 // We don't know whether any given command coming from this interface takes
55 // arguments or not so here we're just disabling the basic args check.
57 m_arguments.push_back({none_arg});
58 }
59
60 bool IsRemovable() const override { return true; }
61
62 /// More documentation is available in lldb::CommandObject::GetRepeatCommand,
63 /// but in short, if std::nullopt is returned, the previous command will be
64 /// repeated, and if an empty string is returned, no commands will be
65 /// executed.
66 std::optional<std::string> GetRepeatCommand(Args &current_command_args,
67 uint32_t index) override {
69 return std::nullopt;
70 else
72 }
73
74protected:
75 void DoExecute(Args &command, CommandReturnObject &result) override {
76 SBCommandReturnObject sb_return(result);
77 SBCommandInterpreter sb_interpreter(&m_interpreter);
78 SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this());
79 bool success = m_backend->DoExecute(debugger_sb,
80 command.GetArgumentVector(), sb_return);
81 // If the plugin command did not set its own status, infer it from the
82 // boolean return value so that callers always see a defined status.
83 if (result.GetStatus() == eReturnStatusInvalid)
86 }
88 std::optional<std::string> m_auto_repeat_command;
89};
90} // namespace lldb_private
91
95
97 : m_opaque_ptr(interpreter) {
98 LLDB_INSTRUMENT_VA(this, interpreter);
99}
100
105
107
110 LLDB_INSTRUMENT_VA(this, rhs);
111
113 return *this;
114}
115
117 LLDB_INSTRUMENT_VA(this);
118 return this->operator bool();
119}
120SBCommandInterpreter::operator bool() const {
121 LLDB_INSTRUMENT_VA(this);
122
123 return m_opaque_ptr != nullptr;
124}
125
127 LLDB_INSTRUMENT_VA(this, cmd);
128
129 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->CommandExists(cmd)
130 : false);
131}
132
134 LLDB_INSTRUMENT_VA(this, cmd);
135
136 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->UserCommandExists(cmd)
137 : false);
138}
139
141 LLDB_INSTRUMENT_VA(this, cmd);
142
143 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->AliasExists(cmd)
144 : false);
145}
146
148 LLDB_INSTRUMENT_VA(this);
149
150 return (IsValid() ? m_opaque_ptr->IsActive() : false);
151}
152
154 LLDB_INSTRUMENT_VA(this);
155
156 return (IsValid() ? m_opaque_ptr->GetDebugger().InterruptRequested() : false);
157}
158
160 LLDB_INSTRUMENT_VA(this);
161
162 return (IsValid() ? m_opaque_ptr->InterruptCommand() : false);
163}
164
166 LLDB_INSTRUMENT_VA(this, ch);
167
168 if (!IsValid())
169 return nullptr;
170
171 return m_opaque_ptr->GetDebugger().GetStringPool().Intern(
172 m_opaque_ptr->GetDebugger().GetTopIOHandlerControlSequence(ch));
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.GetString());
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 llvm::json::Value stats = m_opaque_ptr->GetStatistics();
598 data.m_impl_up->SetObjectSP(StructuredData::ParseJSONValue(stats));
599 return data;
600}
601
603 LLDB_INSTRUMENT_VA(this);
604
605 SBStructuredData data;
606 if (IsValid())
607 // A deep copy is performed by `std::make_shared` on the
608 // `StructuredData::Array`, via its implicitly-declared copy constructor.
609 // This ensures thread-safety between the user changing the returned
610 // `SBStructuredData` and the `CommandInterpreter` changing its internal
611 // `m_transcript`.
612 data.m_impl_up->SetObjectSP(
613 std::make_shared<StructuredData::Array>(m_opaque_ptr->GetTranscript()));
614 return data;
615}
616
618 const char *help) {
619 LLDB_INSTRUMENT_VA(this, name, help);
620
621 lldb::CommandObjectSP new_command_sp(
622 new CommandObjectMultiword(*m_opaque_ptr, name, help));
623 new_command_sp->GetAsMultiwordCommand()->SetRemovable(true);
624 Status add_error = m_opaque_ptr->AddUserCommand(name, new_command_sp, true);
625 if (add_error.Success())
626 return lldb::SBCommand(new_command_sp);
627 return lldb::SBCommand();
628}
629
631 const char *name, lldb::SBCommandPluginInterface *impl, const char *help) {
632 LLDB_INSTRUMENT_VA(this, name, impl, help);
633
634 return AddCommand(name, impl, help, /*syntax=*/nullptr,
635 /*auto_repeat_command=*/"");
636}
637
641 const char *help, const char *syntax) {
642 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax);
643 return AddCommand(name, impl, help, syntax, /*auto_repeat_command=*/"");
644}
645
647 const char *name, lldb::SBCommandPluginInterface *impl, const char *help,
648 const char *syntax, const char *auto_repeat_command) {
649 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax, auto_repeat_command);
650
651 lldb::CommandObjectSP new_command_sp;
652 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
653 *m_opaque_ptr, name, impl, help, syntax, /*flags=*/0,
654 auto_repeat_command);
655
656 Status add_error = m_opaque_ptr->AddUserCommand(name, new_command_sp, true);
657 if (add_error.Success())
658 return lldb::SBCommand(new_command_sp);
659 return lldb::SBCommand();
660}
661
663
665
667
671
673 LLDB_INSTRUMENT_VA(this, rhs);
674
675 if (this != &rhs)
677 return *this;
678}
679
682
684 m_opaque_sp = std::move(rhs.m_opaque_sp);
685 return *this;
686}
687
688SBCommand::~SBCommand() = default;
689
691
693 LLDB_INSTRUMENT_VA(this);
694 return this->operator bool();
695}
696SBCommand::operator bool() const {
697 LLDB_INSTRUMENT_VA(this);
698
699 return m_opaque_sp.get() != nullptr;
700}
701
702const char *SBCommand::GetName() {
703 LLDB_INSTRUMENT_VA(this);
704
705 return (IsValid() ? m_opaque_sp->GetCommandInterpreter()
706 .GetDebugger()
707 .GetStringPool()
708 .InternNonEmpty(m_opaque_sp->GetCommandName())
709 : nullptr);
710}
711
712const char *SBCommand::GetHelp() {
713 LLDB_INSTRUMENT_VA(this);
714
715 return (IsValid() ? m_opaque_sp->GetCommandInterpreter()
716 .GetDebugger()
717 .GetStringPool()
718 .InternNonEmpty(m_opaque_sp->GetHelp())
719 : nullptr);
720}
721
723 LLDB_INSTRUMENT_VA(this);
724
725 return (IsValid() ? m_opaque_sp->GetCommandInterpreter()
726 .GetDebugger()
727 .GetStringPool()
728 .InternNonEmpty(m_opaque_sp->GetHelpLong())
729 : nullptr);
730}
731
732void SBCommand::SetHelp(const char *help) {
733 LLDB_INSTRUMENT_VA(this, help);
734
735 if (IsValid())
736 m_opaque_sp->SetHelp(help);
737}
738
739void SBCommand::SetHelpLong(const char *help) {
740 LLDB_INSTRUMENT_VA(this, help);
741
742 if (IsValid())
743 m_opaque_sp->SetHelpLong(help);
744}
745
747 const char *help) {
748 LLDB_INSTRUMENT_VA(this, name, help);
749
750 if (!IsValid())
751 return lldb::SBCommand();
752 if (!m_opaque_sp->IsMultiwordObject())
753 return lldb::SBCommand();
755 m_opaque_sp->GetCommandInterpreter(), name, help);
756 new_command->SetRemovable(true);
757 lldb::CommandObjectSP new_command_sp(new_command);
758 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
759 return lldb::SBCommand(new_command_sp);
760 return lldb::SBCommand();
761}
762
765 const char *help) {
766 LLDB_INSTRUMENT_VA(this, name, impl, help);
767 return AddCommand(name, impl, help, /*syntax=*/nullptr,
768 /*auto_repeat_command=*/"");
769}
770
773 const char *help, const char *syntax) {
774 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax);
775 return AddCommand(name, impl, help, syntax, /*auto_repeat_command=*/"");
776}
777
780 const char *help, const char *syntax,
781 const char *auto_repeat_command) {
782 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax, auto_repeat_command);
783
784 if (!IsValid())
785 return lldb::SBCommand();
786 if (!m_opaque_sp->IsMultiwordObject())
787 return lldb::SBCommand();
788 lldb::CommandObjectSP new_command_sp;
789 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
790 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax,
791 /*flags=*/0, auto_repeat_command);
792 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
793 return lldb::SBCommand(new_command_sp);
794 return lldb::SBCommand();
795}
796
798 LLDB_INSTRUMENT_VA(this);
799
800 return (IsValid() ? m_opaque_sp->GetFlags().Get() : 0);
801}
802
803void SBCommand::SetFlags(uint32_t flags) {
804 LLDB_INSTRUMENT_VA(this, flags);
805
806 if (IsValid())
807 m_opaque_sp->GetFlags().Set(flags);
808}
809
811 lldb::SBCommandPrintCallback callback, void *baton) {
812 LLDB_INSTRUMENT_VA(this, callback, baton);
813
814 if (m_opaque_ptr)
815 m_opaque_ptr->SetPrintCallback(
816 [callback, baton](lldb_private::CommandReturnObject &result) {
817 SBCommandReturnObject sb_result(result);
818 return callback(sb_result, baton);
819 });
820}
#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 *)
lldb::SBCommand & operator=(const lldb::SBCommand &rhs)
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 * GetString() const
Exists so friend classes can use the StringString's data without putting it in the ConstString pool.
Definition SBStream.cpp:201
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.
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()
const char * Intern(llvm::StringRef str) const
Definition StringPool.h:78
const char * InternNonEmpty(llvm::StringRef str) const
Like Intern, but an empty string yields nullptr.
Definition StringPool.h:81
static StringPoolRef GetSystemPool()
The system pool. Only valid between Initialize and Terminate.
static ObjectSP ParseJSONValue(const llvm::json::Value &value)
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:57
lldb::CommandReturnObjectCallbackResult(* SBCommandPrintCallback)(lldb::SBCommandReturnObject &result, void *baton)
Definition SBDefines.h:152
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.