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.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 LLDB_INSTRUMENT_VA(this);
668 return this->operator bool();
669}
670SBCommand::operator bool() const {
671 LLDB_INSTRUMENT_VA(this);
672
673 return m_opaque_sp.get() != nullptr;
674}
675
676const char *SBCommand::GetName() {
677 LLDB_INSTRUMENT_VA(this);
678
679 return (IsValid()
680 ? ConstString(m_opaque_sp->GetCommandName()).AsCString(nullptr)
681 : nullptr);
682}
683
684const char *SBCommand::GetHelp() {
685 LLDB_INSTRUMENT_VA(this);
686
687 return (IsValid() ? ConstString(m_opaque_sp->GetHelp()).AsCString(nullptr)
688 : nullptr);
689}
690
692 LLDB_INSTRUMENT_VA(this);
693
694 return (IsValid() ? ConstString(m_opaque_sp->GetHelpLong()).AsCString(nullptr)
695 : nullptr);
696}
697
698void SBCommand::SetHelp(const char *help) {
699 LLDB_INSTRUMENT_VA(this, help);
700
701 if (IsValid())
702 m_opaque_sp->SetHelp(help);
703}
704
705void SBCommand::SetHelpLong(const char *help) {
706 LLDB_INSTRUMENT_VA(this, help);
707
708 if (IsValid())
709 m_opaque_sp->SetHelpLong(help);
710}
711
713 const char *help) {
714 LLDB_INSTRUMENT_VA(this, name, help);
715
716 if (!IsValid())
717 return lldb::SBCommand();
718 if (!m_opaque_sp->IsMultiwordObject())
719 return lldb::SBCommand();
721 m_opaque_sp->GetCommandInterpreter(), name, help);
722 new_command->SetRemovable(true);
723 lldb::CommandObjectSP new_command_sp(new_command);
724 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
725 return lldb::SBCommand(new_command_sp);
726 return lldb::SBCommand();
727}
728
731 const char *help) {
732 LLDB_INSTRUMENT_VA(this, name, impl, help);
733 return AddCommand(name, impl, help, /*syntax=*/nullptr,
734 /*auto_repeat_command=*/"");
735}
736
739 const char *help, const char *syntax) {
740 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax);
741 return AddCommand(name, impl, help, syntax, /*auto_repeat_command=*/"");
742}
743
746 const char *help, const char *syntax,
747 const char *auto_repeat_command) {
748 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax, auto_repeat_command);
749
750 if (!IsValid())
751 return lldb::SBCommand();
752 if (!m_opaque_sp->IsMultiwordObject())
753 return lldb::SBCommand();
754 lldb::CommandObjectSP new_command_sp;
755 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
756 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax,
757 /*flags=*/0, auto_repeat_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
764 LLDB_INSTRUMENT_VA(this);
765
766 return (IsValid() ? m_opaque_sp->GetFlags().Get() : 0);
767}
768
769void SBCommand::SetFlags(uint32_t flags) {
770 LLDB_INSTRUMENT_VA(this, flags);
771
772 if (IsValid())
773 m_opaque_sp->GetFlags().Set(flags);
774}
775
777 lldb::SBCommandPrintCallback callback, void *baton) {
778 LLDB_INSTRUMENT_VA(this, callback, baton);
779
780 if (m_opaque_ptr)
781 m_opaque_ptr->SetPrintCallback(
782 [callback, baton](lldb_private::CommandReturnObject &result) {
783 SBCommandReturnObject sb_result(result);
784 return callback(sb_result, baton);
785 });
786}
#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 * 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.
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 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:151
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.