LLDB mainline
CommandInterpreter.h
Go to the documentation of this file.
1//===-- CommandInterpreter.h ------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_INTERPRETER_COMMANDINTERPRETER_H
10#define LLDB_INTERPRETER_COMMANDINTERPRETER_H
11
12#include "lldb/Core/Debugger.h"
13#include "lldb/Core/IOHandler.h"
18#include "lldb/Utility/Args.h"
21#include "lldb/Utility/Event.h"
22#include "lldb/Utility/Log.h"
26#include "lldb/lldb-forward.h"
27#include "lldb/lldb-private.h"
28
29#include <mutex>
30#include <optional>
31#include <stack>
32#include <unordered_map>
33
34namespace lldb_private {
35class CommandInterpreter;
36
38public:
40
41 uint32_t GetNumErrors() const { return m_num_errors; }
42
44
46 return m_result == result;
47 }
48
49protected:
51
53
55
56private:
57 int m_num_errors = 0;
60};
61
63public:
64 /// Construct a CommandInterpreterRunOptions object. This class is used to
65 /// control all the instances where we run multiple commands, e.g.
66 /// HandleCommands, HandleCommandsFromFile, RunCommandInterpreter.
67 ///
68 /// The meanings of the options in this object are:
69 ///
70 /// \param[in] stop_on_continue
71 /// If \b true, execution will end on the first command that causes the
72 /// process in the execution context to continue. If \b false, we won't
73 /// check the execution status.
74 /// \param[in] stop_on_error
75 /// If \b true, execution will end on the first command that causes an
76 /// error.
77 /// \param[in] stop_on_crash
78 /// If \b true, when a command causes the target to run, and the end of the
79 /// run is a signal or exception, stop executing the commands.
80 /// \param[in] echo_commands
81 /// If \b true, echo the command before executing it. If \b false, execute
82 /// silently.
83 /// \param[in] echo_comments
84 /// If \b true, echo command even if it is a pure comment line. If
85 /// \b false, print no ouput in this case. This setting has an effect only
86 /// if echo_commands is \b true.
87 /// \param[in] print_results
88 /// If \b true and the command succeeds, print the results of the command
89 /// after executing it. If \b false, execute silently.
90 /// \param[in] print_errors
91 /// If \b true and the command fails, print the results of the command
92 /// after executing it. If \b false, execute silently.
93 /// \param[in] add_to_history
94 /// If \b true add the commands to the command history. If \b false, don't
95 /// add them.
97 LazyBool stop_on_error, LazyBool stop_on_crash,
98 LazyBool echo_commands, LazyBool echo_comments,
99 LazyBool print_results, LazyBool print_errors,
100 LazyBool add_to_history)
101 : m_stop_on_continue(stop_on_continue), m_stop_on_error(stop_on_error),
102 m_stop_on_crash(stop_on_crash), m_echo_commands(echo_commands),
103 m_echo_comment_commands(echo_comments), m_print_results(print_results),
104 m_print_errors(print_errors), m_add_to_history(add_to_history) {}
105
107
108 void SetSilent(bool silent) {
109 LazyBool value = silent ? eLazyBoolNo : eLazyBoolYes;
110
111 m_print_results = value;
112 m_print_errors = value;
113 m_echo_commands = value;
115 m_add_to_history = value;
116 }
117 // These return the default behaviors if the behavior is not
118 // eLazyBoolCalculate. But I've also left the ivars public since for
119 // different ways of running the interpreter you might want to force
120 // different defaults... In that case, just grab the LazyBool ivars directly
121 // and do what you want with eLazyBoolCalculate.
123
124 void SetStopOnContinue(bool stop_on_continue) {
125 m_stop_on_continue = stop_on_continue ? eLazyBoolYes : eLazyBoolNo;
126 }
127
129
130 void SetStopOnError(bool stop_on_error) {
131 m_stop_on_error = stop_on_error ? eLazyBoolYes : eLazyBoolNo;
132 }
133
135
136 void SetStopOnCrash(bool stop_on_crash) {
137 m_stop_on_crash = stop_on_crash ? eLazyBoolYes : eLazyBoolNo;
138 }
139
141
142 void SetEchoCommands(bool echo_commands) {
143 m_echo_commands = echo_commands ? eLazyBoolYes : eLazyBoolNo;
144 }
145
148 }
149
150 void SetEchoCommentCommands(bool echo_comments) {
152 }
153
155
156 void SetPrintResults(bool print_results) {
157 m_print_results = print_results ? eLazyBoolYes : eLazyBoolNo;
158 }
159
161
162 void SetPrintErrors(bool print_errors) {
163 m_print_errors = print_errors ? eLazyBoolYes : eLazyBoolNo;
164 }
165
167
168 void SetAddToHistory(bool add_to_history) {
169 m_add_to_history = add_to_history ? eLazyBoolYes : eLazyBoolNo;
170 }
171
172 bool GetAutoHandleEvents() const {
174 }
175
176 void SetAutoHandleEvents(bool auto_handle_events) {
177 m_auto_handle_events = auto_handle_events ? eLazyBoolYes : eLazyBoolNo;
178 }
179
180 bool GetSpawnThread() const { return DefaultToNo(m_spawn_thread); }
181
182 void SetSpawnThread(bool spawn_thread) {
183 m_spawn_thread = spawn_thread ? eLazyBoolYes : eLazyBoolNo;
184 }
185
196
197private:
198 static bool DefaultToYes(LazyBool flag) {
199 switch (flag) {
200 case eLazyBoolNo:
201 return false;
202 default:
203 return true;
204 }
205 }
206
207 static bool DefaultToNo(LazyBool flag) {
208 switch (flag) {
209 case eLazyBoolYes:
210 return true;
211 default:
212 return false;
213 }
214 }
215};
216
218 public Properties,
219 public IOHandlerDelegate {
220public:
221 enum {
224 eBroadcastBitQuitCommandReceived = (1 << 2), // User entered quit
227 };
228
229 /// Tristate boolean to manage children omission warnings.
231 eNoOmission = 0, ///< No children were omitted.
232 eUnwarnedOmission = 1, ///< Children omitted, and not yet notified.
233 eWarnedOmission = 2 ///< Children omitted and notified.
234 };
235
237 eCommandTypesBuiltin = 0x0001, //< native commands such as "frame"
238 eCommandTypesUserDef = 0x0002, //< scripted commands
239 eCommandTypesUserMW = 0x0004, //< multiword commands (command containers)
240 eCommandTypesAliases = 0x0008, //< aliases such as "po"
241 eCommandTypesHidden = 0x0010, //< commands prefixed with an underscore
242 eCommandTypesAllThem = 0xFFFF //< all commands
243 };
244
245 // The CommandAlias and CommandInterpreter both have a hand in
246 // substituting for alias commands. They work by writing special tokens
247 // in the template form of the Alias command, and then detecting them when the
248 // command is executed. These are the special tokens:
249 static const char *g_no_argument;
250 static const char *g_need_argument;
251 static const char *g_argument;
252
253 CommandInterpreter(Debugger &debugger, bool synchronous_execution);
254
255 ~CommandInterpreter() override = default;
256
257 // These two functions fill out the Broadcaster interface:
258
259 static llvm::StringRef GetStaticBroadcasterClass();
260
261 llvm::StringRef GetBroadcasterClass() const override {
263 }
264
266 void SourceInitFileHome(CommandReturnObject &result, bool is_repl);
268
269 bool AddCommand(llvm::StringRef name, const lldb::CommandObjectSP &cmd_sp,
270 bool can_replace);
271
272 Status AddUserCommand(llvm::StringRef name,
273 const lldb::CommandObjectSP &cmd_sp, bool can_replace);
274
275 lldb::CommandObjectSP GetCommandSPExact(llvm::StringRef cmd,
276 bool include_aliases = false) const;
277
278 CommandObject *GetCommandObject(llvm::StringRef cmd,
279 StringList *matches = nullptr,
280 StringList *descriptions = nullptr) const;
281
282 CommandObject *GetUserCommandObject(llvm::StringRef cmd,
283 StringList *matches = nullptr,
284 StringList *descriptions = nullptr) const;
285
286 /// Determine whether a root level, built-in command with this name exists.
287 bool CommandExists(llvm::StringRef cmd) const;
288
289 /// Determine whether an alias command with this name exists
290 bool AliasExists(llvm::StringRef cmd) const;
291
292 /// Determine whether a root-level user command with this name exists.
293 bool UserCommandExists(llvm::StringRef cmd) const;
294
295 /// Determine whether a root-level user multiword command with this name
296 /// exists.
297 bool UserMultiwordCommandExists(llvm::StringRef cmd) const;
298
299 /// Look up the command pointed to by path encoded in the arguments of
300 /// the incoming command object. If all the path components exist
301 /// and are all actual commands - not aliases, and the leaf command is a
302 /// multiword command, return the command. Otherwise return nullptr, and put
303 /// a useful diagnostic in the Status object.
304 ///
305 /// \param[in] path
306 /// An Args object holding the path in its arguments
307 /// \param[in] leaf_is_command
308 /// If true, return the container of the leaf name rather than looking up
309 /// the whole path as a leaf command. The leaf needn't exist in this case.
310 /// \param[in,out] result
311 /// If the path is not found, this error shows where we got off track.
312 /// \return
313 /// If found, a pointer to the CommandObjectMultiword pointed to by path,
314 /// or to the container of the leaf element is is_leaf_command.
315 /// Returns nullptr under two circumstances:
316 /// 1) The command in not found (check error.Fail)
317 /// 2) is_leaf is true and the path has only a leaf. We don't have a
318 /// dummy "contains everything MWC, so we return null here, but
319 /// in this case error.Success is true.
320
322 bool leaf_is_command,
323 Status &result);
324
325 CommandAlias *AddAlias(llvm::StringRef alias_name,
326 lldb::CommandObjectSP &command_obj_sp,
327 llvm::StringRef args_string = llvm::StringRef());
328
329 /// Remove a command if it is removable (python or regex command). If \b force
330 /// is provided, the command is removed regardless of its removable status.
331 bool RemoveCommand(llvm::StringRef cmd, bool force = false);
332
333 bool RemoveAlias(llvm::StringRef alias_name);
334
335 bool GetAliasFullName(llvm::StringRef cmd, std::string &full_name) const;
336
337 bool RemoveUserMultiword(llvm::StringRef multiword_name);
338
339 // Do we want to allow top-level user multiword commands to be deleted?
341
342 bool RemoveUser(llvm::StringRef alias_name);
343
344 void RemoveAllUser() { m_user_dict.clear(); }
345
346 const CommandAlias *GetAlias(llvm::StringRef alias_name) const;
347
348 CommandObject *BuildAliasResult(llvm::StringRef alias_name,
349 std::string &raw_input_string,
350 std::string &alias_result,
351 CommandReturnObject &result);
352
353 bool HandleCommand(const char *command_line, LazyBool add_to_history,
354 const ExecutionContext &override_context,
355 CommandReturnObject &result);
356
357 bool HandleCommand(const char *command_line, LazyBool add_to_history,
358 CommandReturnObject &result,
359 bool force_repeat_command = false);
360
361 bool InterruptCommand();
362
363 /// Execute a list of commands in sequence.
364 ///
365 /// \param[in] commands
366 /// The list of commands to execute.
367 /// \param[in,out] context
368 /// The execution context in which to run the commands.
369 /// \param[in] options
370 /// This object holds the options used to control when to stop, whether to
371 /// execute commands,
372 /// etc.
373 /// \param[out] result
374 /// This is marked as succeeding with no output if all commands execute
375 /// safely,
376 /// and failed with some explanation if we aborted executing the commands
377 /// at some point.
378 void HandleCommands(const StringList &commands,
379 const ExecutionContext &context,
380 const CommandInterpreterRunOptions &options,
381 CommandReturnObject &result);
382
383 void HandleCommands(const StringList &commands,
384 const CommandInterpreterRunOptions &options,
385 CommandReturnObject &result);
386
387 /// Execute a list of commands from a file.
388 ///
389 /// \param[in] file
390 /// The file from which to read in commands.
391 /// \param[in,out] context
392 /// The execution context in which to run the commands.
393 /// \param[in] options
394 /// This object holds the options used to control when to stop, whether to
395 /// execute commands,
396 /// etc.
397 /// \param[out] result
398 /// This is marked as succeeding with no output if all commands execute
399 /// safely,
400 /// and failed with some explanation if we aborted executing the commands
401 /// at some point.
402 void HandleCommandsFromFile(FileSpec &file, const ExecutionContext &context,
403 const CommandInterpreterRunOptions &options,
404 CommandReturnObject &result);
405
407 const CommandInterpreterRunOptions &options,
408 CommandReturnObject &result);
409
410 CommandObject *GetCommandObjectForCommand(llvm::StringRef &command_line);
411
412 /// Returns the auto-suggestion string that should be added to the given
413 /// command line.
414 std::optional<std::string> GetAutoSuggestionForCommand(llvm::StringRef line);
415
416 // This handles command line completion.
417 void HandleCompletion(CompletionRequest &request);
418
419 // This version just returns matches, and doesn't compute the substring. It
420 // is here so the Help command can call it for the first argument.
422
423 int GetCommandNamesMatchingPartialString(const char *cmd_cstr,
424 bool include_aliases,
425 StringList &matches,
426 StringList &descriptions);
427
428 void GetHelp(CommandReturnObject &result,
429 uint32_t types = eCommandTypesAllThem);
430
431 void GetAliasHelp(const char *alias_name, StreamString &help_string);
432
433 void OutputFormattedHelpText(Stream &strm, llvm::StringRef prefix,
434 llvm::StringRef help_text);
435
436 void OutputFormattedHelpText(Stream &stream, llvm::StringRef command_word,
437 llvm::StringRef separator,
438 llvm::StringRef help_text, size_t max_word_len);
439
440 // this mimics OutputFormattedHelpText but it does perform a much simpler
441 // formatting, basically ensuring line alignment. This is only good if you
442 // have some complicated layout for your help text and want as little help as
443 // reasonable in properly displaying it. Most of the times, you simply want
444 // to type some text and have it printed in a reasonable way on screen. If
445 // so, use OutputFormattedHelpText
446 void OutputHelpText(Stream &stream, llvm::StringRef command_word,
447 llvm::StringRef separator, llvm::StringRef help_text,
448 uint32_t max_word_len);
449
451
453
454 lldb::PlatformSP GetPlatform(bool prefer_target_platform);
455
456 const char *ProcessEmbeddedScriptCommands(const char *arg);
457
458 void UpdatePrompt(llvm::StringRef prompt);
459
460 bool Confirm(llvm::StringRef message, bool default_answer);
461
463
464 void Initialize();
465
466 void Clear();
467
468 bool HasCommands() const;
469
470 bool HasAliases() const;
471
472 bool HasUserCommands() const;
473
474 bool HasUserMultiwordCommands() const;
475
476 bool HasAliasOptions() const;
477
478 void BuildAliasCommandArgs(CommandObject *alias_cmd_obj,
479 const char *alias_name, Args &cmd_args,
480 std::string &raw_input_string,
481 CommandReturnObject &result);
482
483 /// Picks the number out of a string of the form "%NNN", otherwise return 0.
484 int GetOptionArgumentPosition(const char *in_string);
485
486 void SkipLLDBInitFiles(bool skip_lldbinit_files) {
487 m_skip_lldbinit_files = skip_lldbinit_files;
488 }
489
490 void SkipAppInitFiles(bool skip_app_init_files) {
491 m_skip_app_init_files = skip_app_init_files;
492 }
493
494 bool GetSynchronous();
495
496 void FindCommandsForApropos(llvm::StringRef word, StringList &commands_found,
497 StringList &commands_help,
498 bool search_builtin_commands,
499 bool search_user_commands,
500 bool search_alias_commands,
501 bool search_user_mw_commands);
502
504
505 bool SetBatchCommandMode(bool value) {
506 const bool old_value = m_batch_command_mode;
507 m_batch_command_mode = value;
508 return old_value;
509 }
510
514 }
515
519 }
520
521 void PrintWarningsIfNecessary(Stream &s, const std::string &cmd_name) {
523 s.Printf("*** Some of the displayed variables have more members than the "
524 "debugger will show by default. To show all of them, you can "
525 "either use the --show-all-children option to %s or raise the "
526 "limit by changing the target.max-children-count setting.\n",
527 cmd_name.c_str());
529 }
530
532 s.Printf("*** Some of the displayed variables have a greater depth of "
533 "members than the debugger will show by default. To increase "
534 "the limit, use the --depth option to %s, or raise the limit by "
535 "changing the target.max-children-depth setting.\n",
536 cmd_name.c_str());
538 }
539 }
540
542
543 bool IsActive();
544
547
548 void GetLLDBCommandsFromIOHandler(const char *prompt,
549 IOHandlerDelegate &delegate,
550 void *baton = nullptr);
551
552 void GetPythonCommandsFromIOHandler(const char *prompt,
553 IOHandlerDelegate &delegate,
554 void *baton = nullptr);
555
556 const char *GetCommandPrefix();
557
558 // Properties
559 bool GetExpandRegexAliases() const;
560
561 bool GetPromptOnQuit() const;
562 void SetPromptOnQuit(bool enable);
563
564 bool GetSaveTranscript() const;
565 void SetSaveTranscript(bool enable);
566
567 bool GetSaveSessionOnQuit() const;
568 void SetSaveSessionOnQuit(bool enable);
569
570 bool GetOpenTranscriptInEditor() const;
571 void SetOpenTranscriptInEditor(bool enable);
572
574 void SetSaveSessionDirectory(llvm::StringRef path);
575
576 bool GetEchoCommands() const;
577 void SetEchoCommands(bool enable);
578
579 bool GetEchoCommentCommands() const;
580 void SetEchoCommentCommands(bool enable);
581
582 bool GetRepeatPreviousCommand() const;
583
584 bool GetRequireCommandOverwrite() const;
585
587 return m_user_dict;
588 }
589
591 return m_user_mw_dict;
592 }
593
595 return m_command_dict;
596 }
597
599
600 /// Specify if the command interpreter should allow that the user can
601 /// specify a custom exit code when calling 'quit'.
602 void AllowExitCodeOnQuit(bool allow);
603
604 /// Sets the exit code for the quit command.
605 /// \param[in] exit_code
606 /// The exit code that the driver should return on exit.
607 /// \return True if the exit code was successfully set; false if the
608 /// interpreter doesn't allow custom exit codes.
609 /// \see AllowExitCodeOnQuit
610 [[nodiscard]] bool SetQuitExitCode(int exit_code);
611
612 /// Returns the exit code that the user has specified when running the
613 /// 'quit' command.
614 /// \param[out] exited
615 /// Set to true if the user has called quit with a custom exit code.
616 int GetQuitExitCode(bool &exited) const;
617
618 void ResolveCommand(const char *command_line, CommandReturnObject &result);
619
620 bool GetStopCmdSourceOnError() const;
621
623 GetIOHandler(bool force_create = false,
624 CommandInterpreterRunOptions *options = nullptr);
625
626 bool GetSpaceReplPrompts() const;
627
628 /// Save the current debugger session transcript to a file on disk.
629 /// \param output_file
630 /// The file path to which the session transcript will be written. Since
631 /// the argument is optional, an arbitrary temporary file will be create
632 /// when no argument is passed.
633 /// \param result
634 /// This is used to pass function output and error messages.
635 /// \return \b true if the session transcript was successfully written to
636 /// disk, \b false otherwise.
638 std::optional<std::string> output_file = std::nullopt);
639
641
642 bool IsInteractive();
643
644 bool IOHandlerInterrupt(IOHandler &io_handler) override;
645
646 Status PreprocessCommand(std::string &command);
647 Status PreprocessToken(std::string &token);
648
649 void IncreaseCommandUsage(const CommandObject &cmd_obj) {
650 ++m_command_usages[cmd_obj.GetCommandName()];
651 }
652
653 llvm::json::Value GetStatistics();
655
656protected:
657 friend class Debugger;
658
659 // This checks just the RunCommandInterpreter interruption state. It is only
660 // meant to be used in Debugger::InterruptRequested
661 bool WasInterrupted() const;
662
663 // IOHandlerDelegate functions
664 void IOHandlerInputComplete(IOHandler &io_handler,
665 std::string &line) override;
666
667 llvm::StringRef IOHandlerGetControlSequence(char ch) override {
668 static constexpr llvm::StringLiteral control_sequence("quit\n");
669 if (ch == 'd')
670 return control_sequence;
671 return {};
672 }
673
674 void GetProcessOutput();
675
676 bool DidProcessStopAbnormally() const;
677
678 void SetSynchronous(bool value);
679
680 lldb::CommandObjectSP GetCommandSP(llvm::StringRef cmd,
681 bool include_aliases = true,
682 bool exact = true,
683 StringList *matches = nullptr,
684 StringList *descriptions = nullptr) const;
685
686private:
687 void OverrideExecutionContext(const ExecutionContext &override_context);
688
690
691 void SourceInitFile(FileSpec file, CommandReturnObject &result);
692
693 // Completely resolves aliases and abbreviations, returning a pointer to the
694 // final command object and updating command_line to the fully substituted
695 // and translated command.
696 CommandObject *ResolveCommandImpl(std::string &command_line,
697 CommandReturnObject &result);
698
699 void FindCommandsForApropos(llvm::StringRef word, StringList &commands_found,
700 StringList &commands_help,
701 const CommandObject::CommandMap &command_map);
702
703 // An interruptible wrapper around the stream output
704 void PrintCommandOutput(IOHandler &io_handler, llvm::StringRef str,
705 bool is_stdout);
706
707 bool EchoCommandNonInteractive(llvm::StringRef line,
708 const Flags &io_handler_flags) const;
709
710 // A very simple state machine which models the command handling transitions
712 eIdle,
715 };
716
717 std::atomic<CommandHandlingState> m_command_state{
719
721
724
725 Debugger &m_debugger; // The debugger session that this interpreter is
726 // associated with
727 // Execution contexts that were temporarily set by some of HandleCommand*
728 // overloads.
729 std::stack<ExecutionContext> m_overriden_exe_contexts;
733 CommandObject::CommandMap m_command_dict; // Stores basic built-in commands
734 // (they cannot be deleted, removed
735 // or overwritten).
737 m_alias_dict; // Stores user aliases/abbreviations for commands
738 CommandObject::CommandMap m_user_dict; // Stores user-defined commands
740 m_user_mw_dict; // Stores user-defined multiword commands
742 std::string m_repeat_command; // Stores the command that will be executed for
743 // an empty command string.
747 /// Whether we truncated a value's list of children and whether the user has
748 /// been told.
750 /// Whether we reached the maximum child nesting depth and whether the user
751 /// has been told.
753
754 // FIXME: Stop using this to control adding to the history and then replace
755 // this with m_command_source_dirs.size().
757 /// A stack of directory paths. When not empty, the last one is the directory
758 /// of the file that's currently sourced.
759 std::vector<FileSpec> m_command_source_dirs;
760 std::vector<uint32_t> m_command_source_flags;
762
763 // The exit code the user has requested when calling the 'quit' command.
764 // No value means the user hasn't set a custom exit code so far.
765 std::optional<int> m_quit_exit_code;
766 // If the driver is accepts custom exit codes for the 'quit' command.
767 bool m_allow_exit_code = false;
768
769 /// Command usage statistics.
770 typedef llvm::StringMap<uint64_t> CommandUsageMap;
772
773 /// Turn on settings `interpreter.save-transcript` for LLDB to populate
774 /// this stream. Otherwise this stream is empty.
776
777 /// Contains a list of handled commands and their details. Each element in
778 /// the list is a dictionary with the following keys/values:
779 /// - "command" (string): The command that was executed.
780 /// - "output" (string): The output of the command. Empty ("") if no output.
781 /// - "error" (string): The error of the command. Empty ("") if no error.
782 /// - "seconds" (float): The time it took to execute the command.
783 ///
784 /// Turn on settings `interpreter.save-transcript` for LLDB to populate
785 /// this list. Otherwise this list is empty.
787};
788
789} // namespace lldb_private
790
791#endif // LLDB_INTERPRETER_COMMANDINTERPRETER_H
A command line argument class.
Definition: Args.h:33
An event broadcasting class.
Definition: Broadcaster.h:145
void SetStopOnContinue(bool stop_on_continue)
void SetAutoHandleEvents(bool auto_handle_events)
CommandInterpreterRunOptions(LazyBool stop_on_continue, LazyBool stop_on_error, LazyBool stop_on_crash, LazyBool echo_commands, LazyBool echo_comments, LazyBool print_results, LazyBool print_errors, LazyBool add_to_history)
Construct a CommandInterpreterRunOptions object.
bool IsResult(lldb::CommandInterpreterResult result)
lldb::CommandInterpreterResult GetResult() const
void SetResult(lldb::CommandInterpreterResult result)
lldb::CommandInterpreterResult m_result
bool EchoCommandNonInteractive(llvm::StringRef line, const Flags &io_handler_flags) const
void UpdatePrompt(llvm::StringRef prompt)
bool IOHandlerInterrupt(IOHandler &io_handler) override
void SourceInitFileHome(CommandReturnObject &result, bool is_repl)
We will first see if there is an application specific ".lldbinit" file whose name is "~/....
std::optional< std::string > GetAutoSuggestionForCommand(llvm::StringRef line)
Returns the auto-suggestion string that should be added to the given command line.
void IOHandlerInputComplete(IOHandler &io_handler, std::string &line) override
Called when a line or lines have been retrieved.
std::stack< ExecutionContext > m_overriden_exe_contexts
void OutputFormattedHelpText(Stream &strm, llvm::StringRef prefix, llvm::StringRef help_text)
bool Confirm(llvm::StringRef message, bool default_answer)
bool UserMultiwordCommandExists(llvm::StringRef cmd) const
Determine whether a root-level user multiword command with this name exists.
static llvm::StringRef GetStaticBroadcasterClass()
void GetAliasHelp(const char *alias_name, StreamString &help_string)
void IncreaseCommandUsage(const CommandObject &cmd_obj)
bool RemoveAlias(llvm::StringRef alias_name)
void SetSaveSessionDirectory(llvm::StringRef path)
void SourceInitFile(FileSpec file, CommandReturnObject &result)
CommandAlias * AddAlias(llvm::StringRef alias_name, lldb::CommandObjectSP &command_obj_sp, llvm::StringRef args_string=llvm::StringRef())
int GetCommandNamesMatchingPartialString(const char *cmd_cstr, bool include_aliases, StringList &matches, StringList &descriptions)
void FindCommandsForApropos(llvm::StringRef word, StringList &commands_found, StringList &commands_help, bool search_builtin_commands, bool search_user_commands, bool search_alias_commands, bool search_user_mw_commands)
CommandObject * GetCommandObject(llvm::StringRef cmd, StringList *matches=nullptr, StringList *descriptions=nullptr) const
std::atomic< CommandHandlingState > m_command_state
Status PreprocessCommand(std::string &command)
CommandObject::CommandMap m_alias_dict
CommandObject * ResolveCommandImpl(std::string &command_line, CommandReturnObject &result)
CommandObject::CommandMap m_command_dict
ChildrenOmissionWarningStatus m_truncation_warning
Whether we truncated a value's list of children and whether the user has been told.
void SkipAppInitFiles(bool skip_app_init_files)
void HandleCompletion(CompletionRequest &request)
CommandInterpreterRunResult m_result
void SkipLLDBInitFiles(bool skip_lldbinit_files)
ChildrenOmissionWarningStatus m_max_depth_warning
Whether we reached the maximum child nesting depth and whether the user has been told.
void ResolveCommand(const char *command_line, CommandReturnObject &result)
bool SetQuitExitCode(int exit_code)
Sets the exit code for the quit command.
CommandInterpreterRunResult RunCommandInterpreter(CommandInterpreterRunOptions &options)
bool HandleCommand(const char *command_line, LazyBool add_to_history, const ExecutionContext &override_context, CommandReturnObject &result)
CommandObject::CommandMap m_user_dict
ExecutionContext GetExecutionContext() const
const CommandObject::CommandMap & GetUserCommands() const
CommandObject * GetUserCommandObject(llvm::StringRef cmd, StringList *matches=nullptr, StringList *descriptions=nullptr) const
void SourceInitFileGlobal(CommandReturnObject &result)
bool GetAliasFullName(llvm::StringRef cmd, std::string &full_name) const
CommandObjectMultiword * VerifyUserMultiwordCmdPath(Args &path, bool leaf_is_command, Status &result)
Look up the command pointed to by path encoded in the arguments of the incoming command object.
void HandleCompletionMatches(CompletionRequest &request)
Status AddUserCommand(llvm::StringRef name, const lldb::CommandObjectSP &cmd_sp, bool can_replace)
llvm::StringMap< uint64_t > CommandUsageMap
Command usage statistics.
bool AddCommand(llvm::StringRef name, const lldb::CommandObjectSP &cmd_sp, bool can_replace)
void PrintCommandOutput(IOHandler &io_handler, llvm::StringRef str, bool is_stdout)
bool AliasExists(llvm::StringRef cmd) const
Determine whether an alias command with this name exists.
int GetOptionArgumentPosition(const char *in_string)
Picks the number out of a string of the form "%NNN", otherwise return 0.
void GetHelp(CommandReturnObject &result, uint32_t types=eCommandTypesAllThem)
bool CommandExists(llvm::StringRef cmd) const
Determine whether a root level, built-in command with this name exists.
bool SaveTranscript(CommandReturnObject &result, std::optional< std::string > output_file=std::nullopt)
Save the current debugger session transcript to a file on disk.
int GetQuitExitCode(bool &exited) const
Returns the exit code that the user has specified when running the 'quit' command.
~CommandInterpreter() override=default
lldb::PlatformSP GetPlatform(bool prefer_target_platform)
void GetPythonCommandsFromIOHandler(const char *prompt, IOHandlerDelegate &delegate, void *baton=nullptr)
lldb::CommandObjectSP GetCommandSPExact(llvm::StringRef cmd, bool include_aliases=false) const
const CommandAlias * GetAlias(llvm::StringRef alias_name) const
bool RemoveUser(llvm::StringRef alias_name)
void GetLLDBCommandsFromIOHandler(const char *prompt, IOHandlerDelegate &delegate, void *baton=nullptr)
lldb::CommandObjectSP GetCommandSP(llvm::StringRef cmd, bool include_aliases=true, bool exact=true, StringList *matches=nullptr, StringList *descriptions=nullptr) const
void OutputHelpText(Stream &stream, llvm::StringRef command_word, llvm::StringRef separator, llvm::StringRef help_text, uint32_t max_word_len)
CommandObject * GetCommandObjectForCommand(llvm::StringRef &command_line)
Status PreprocessToken(std::string &token)
bool RemoveUserMultiword(llvm::StringRef multiword_name)
ChildrenOmissionWarningStatus
Tristate boolean to manage children omission warnings.
@ eNoOmission
No children were omitted.
@ eWarnedOmission
Children omitted and notified.
@ eUnwarnedOmission
Children omitted, and not yet notified.
bool UserCommandExists(llvm::StringRef cmd) const
Determine whether a root-level user command with this name exists.
lldb::IOHandlerSP GetIOHandler(bool force_create=false, CommandInterpreterRunOptions *options=nullptr)
const CommandObject::CommandMap & GetUserMultiwordCommands() const
void BuildAliasCommandArgs(CommandObject *alias_cmd_obj, const char *alias_name, Args &cmd_args, std::string &raw_input_string, CommandReturnObject &result)
std::vector< uint32_t > m_command_source_flags
CommandObject * BuildAliasResult(llvm::StringRef alias_name, std::string &raw_input_string, std::string &alias_result, CommandReturnObject &result)
void OverrideExecutionContext(const ExecutionContext &override_context)
const CommandObject::CommandMap & GetCommands() const
const char * ProcessEmbeddedScriptCommands(const char *arg)
void AllowExitCodeOnQuit(bool allow)
Specify if the command interpreter should allow that the user can specify a custom exit code when cal...
CommandObject::CommandMap m_user_mw_dict
StreamString m_transcript_stream
Turn on settings interpreter.save-transcript for LLDB to populate this stream.
void HandleCommandsFromFile(FileSpec &file, const ExecutionContext &context, const CommandInterpreterRunOptions &options, CommandReturnObject &result)
Execute a list of commands from a file.
void SourceInitFileCwd(CommandReturnObject &result)
void PrintWarningsIfNecessary(Stream &s, const std::string &cmd_name)
std::vector< FileSpec > m_command_source_dirs
A stack of directory paths.
llvm::StringRef IOHandlerGetControlSequence(char ch) override
void HandleCommands(const StringList &commands, const ExecutionContext &context, const CommandInterpreterRunOptions &options, CommandReturnObject &result)
Execute a list of commands in sequence.
llvm::StringRef GetBroadcasterClass() const override
This needs to be filled in if you are going to register the broadcaster with the broadcaster manager ...
StructuredData::Array m_transcript
Contains a list of handled commands and their details.
bool RemoveCommand(llvm::StringRef cmd, bool force=false)
Remove a command if it is removable (python or regex command).
const StructuredData::Array & GetTranscript() const
const CommandObject::CommandMap & GetAliases() const
llvm::StringRef GetCommandName() const
std::map< std::string, lldb::CommandObjectSP > CommandMap
"lldb/Utility/ArgCompletionRequest.h"
A class to manage flag bits.
Definition: Debugger.h:80
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file utility class.
Definition: FileSpec.h:56
A class to manage flags.
Definition: Flags.h:22
A delegate class for use with IOHandler subclasses.
Definition: IOHandler.h:190
An error handling class.
Definition: Status.h:44
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::IOHandler > IOHandlerSP
Definition: lldb-forward.h:356
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
Definition: lldb-forward.h:328
CommandInterpreterResult
The result from a command interpreter run.
@ eCommandInterpreterResultSuccess
Command interpreter finished successfully.
std::shared_ptr< lldb_private::Platform > PlatformSP
Definition: lldb-forward.h:383