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"
19#include "lldb/Utility/Baton.h"
22#include "lldb/Utility/Event.h"
23#include "lldb/Utility/Log.h"
27#include "lldb/lldb-forward.h"
28#include "lldb/lldb-private.h"
29
30#include <mutex>
31#include <optional>
32#include <stack>
33#include <unordered_map>
34
35namespace lldb_private {
37
62
64public:
65 /// Construct a CommandInterpreterRunOptions object. This class is used to
66 /// control all the instances where we run multiple commands, e.g.
67 /// HandleCommands, HandleCommandsFromFile, RunCommandInterpreter.
68 ///
69 /// The meanings of the options in this object are:
70 ///
71 /// \param[in] stop_on_continue
72 /// If \b true, execution will end on the first command that causes the
73 /// process in the execution context to continue. If \b false, we won't
74 /// check the execution status.
75 /// \param[in] stop_on_error
76 /// If \b true, execution will end on the first command that causes an
77 /// error.
78 /// \param[in] stop_on_crash
79 /// If \b true, when a command causes the target to run, and the end of the
80 /// run is a signal or exception, stop executing the commands.
81 /// \param[in] echo_commands
82 /// If \b true, echo the command before executing it. If \b false, execute
83 /// silently.
84 /// \param[in] echo_comments
85 /// If \b true, echo command even if it is a pure comment line. If
86 /// \b false, print no ouput in this case. This setting has an effect only
87 /// if echo_commands is \b true.
88 /// \param[in] print_results
89 /// If \b true and the command succeeds, print the results of the command
90 /// after executing it. If \b false, execute silently.
91 /// \param[in] print_errors
92 /// If \b true and the command fails, print the results of the command
93 /// after executing it. If \b false, execute silently.
94 /// \param[in] add_to_history
95 /// If \b true add the commands to the command history. If \b false, don't
96 /// add them.
97 /// \param[in] handle_repeats
98 /// If \b true then treat empty lines as repeat commands even if the
99 /// interpreter is non-interactive.
101 LazyBool stop_on_error, LazyBool stop_on_crash,
102 LazyBool echo_commands, LazyBool echo_comments,
103 LazyBool print_results, LazyBool print_errors,
104 LazyBool add_to_history, LazyBool handle_repeats)
105 : m_stop_on_continue(stop_on_continue), m_stop_on_error(stop_on_error),
106 m_stop_on_crash(stop_on_crash), m_echo_commands(echo_commands),
107 m_echo_comment_commands(echo_comments), m_print_results(print_results),
108 m_print_errors(print_errors), m_add_to_history(add_to_history),
109 m_allow_repeats(handle_repeats) {}
110
112
113 void SetSilent(bool silent) {
114 LazyBool value = silent ? eLazyBoolNo : eLazyBoolYes;
115
116 m_print_results = value;
117 m_print_errors = value;
118 m_echo_commands = value;
120 m_add_to_history = value;
121 }
122 // These return the default behaviors if the behavior is not
123 // eLazyBoolCalculate. But I've also left the ivars public since for
124 // different ways of running the interpreter you might want to force
125 // different defaults... In that case, just grab the LazyBool ivars directly
126 // and do what you want with eLazyBoolCalculate.
128
129 void SetStopOnContinue(bool stop_on_continue) {
130 m_stop_on_continue = stop_on_continue ? eLazyBoolYes : eLazyBoolNo;
131 }
132
134
135 void SetStopOnError(bool stop_on_error) {
136 m_stop_on_error = stop_on_error ? eLazyBoolYes : eLazyBoolNo;
137 }
138
140
141 void SetStopOnCrash(bool stop_on_crash) {
142 m_stop_on_crash = stop_on_crash ? eLazyBoolYes : eLazyBoolNo;
143 }
144
146
147 void SetEchoCommands(bool echo_commands) {
148 m_echo_commands = echo_commands ? eLazyBoolYes : eLazyBoolNo;
149 }
150
154
155 void SetEchoCommentCommands(bool echo_comments) {
157 }
158
160
161 void SetPrintResults(bool print_results) {
162 m_print_results = print_results ? eLazyBoolYes : eLazyBoolNo;
163 }
164
166
167 void SetPrintErrors(bool print_errors) {
168 m_print_errors = print_errors ? eLazyBoolYes : eLazyBoolNo;
169 }
170
172
173 void SetAddToHistory(bool add_to_history) {
174 m_add_to_history = add_to_history ? eLazyBoolYes : eLazyBoolNo;
175 }
176
177 bool GetAutoHandleEvents() const {
179 }
180
181 void SetAutoHandleEvents(bool auto_handle_events) {
182 m_auto_handle_events = auto_handle_events ? eLazyBoolYes : eLazyBoolNo;
183 }
184
185 bool GetSpawnThread() const { return DefaultToNo(m_spawn_thread); }
186
187 void SetSpawnThread(bool spawn_thread) {
188 m_spawn_thread = spawn_thread ? eLazyBoolYes : eLazyBoolNo;
189 }
190
192
193 void SetAllowRepeats(bool allow_repeats) {
194 m_allow_repeats = allow_repeats ? eLazyBoolYes : eLazyBoolNo;
195 }
196
208
209private:
210 static bool DefaultToYes(LazyBool flag) {
211 switch (flag) {
212 case eLazyBoolNo:
213 return false;
214 default:
215 return true;
216 }
217 }
218
219 static bool DefaultToNo(LazyBool flag) {
220 switch (flag) {
221 case eLazyBoolYes:
222 return true;
223 default:
224 return false;
225 }
226 }
227};
228
230 public Properties,
231 public IOHandlerDelegate {
232public:
233 enum {
236 eBroadcastBitQuitCommandReceived = (1 << 2), // User entered quit
239 };
240
241 /// Tristate boolean to manage children omission warnings.
243 eNoOmission = 0, ///< No children were omitted.
244 eUnwarnedOmission = 1, ///< Children omitted, and not yet notified.
245 eWarnedOmission = 2 ///< Children omitted and notified.
246 };
247
249 eCommandTypesBuiltin = 0x0001, ///< native commands such as "frame"
250 eCommandTypesUserDef = 0x0002, ///< scripted commands
251 eCommandTypesUserMW = 0x0004, ///< multiword commands (command containers)
252 eCommandTypesAliases = 0x0008, ///< aliases such as "po"
253 eCommandTypesHidden = 0x0010, ///< commands prefixed with an underscore
254 eCommandTypesAllThem = 0xFFFF ///< all commands
255 };
256
260
261 // The CommandAlias and CommandInterpreter both have a hand in
262 // substituting for alias commands. They work by writing special tokens
263 // in the template form of the Alias command, and then detecting them when the
264 // command is executed. These are the special tokens:
265 static const char *g_no_argument;
266 static const char *g_need_argument;
267 static const char *g_argument;
268
269 CommandInterpreter(Debugger &debugger, bool synchronous_execution);
270
271 ~CommandInterpreter() override = default;
272
273 // These two functions fill out the Broadcaster interface:
274
275 static llvm::StringRef GetStaticBroadcasterClass();
276
277 llvm::StringRef GetBroadcasterClass() const override {
279 }
280
282 void SourceInitFileHome(CommandReturnObject &result, bool is_repl);
284
285 bool AddCommand(llvm::StringRef name, const lldb::CommandObjectSP &cmd_sp,
286 bool can_replace);
287
288 Status AddUserCommand(llvm::StringRef name,
289 const lldb::CommandObjectSP &cmd_sp, bool can_replace);
290
291 lldb::CommandObjectSP GetCommandSPExact(llvm::StringRef cmd,
292 bool include_aliases = false) const;
293
294 CommandObject *GetCommandObject(llvm::StringRef cmd,
295 StringList *matches = nullptr,
296 StringList *descriptions = nullptr) const;
297
298 CommandObject *GetUserCommandObject(llvm::StringRef cmd,
299 StringList *matches = nullptr,
300 StringList *descriptions = nullptr) const;
301
303 GetAliasCommandObject(llvm::StringRef cmd, StringList *matches = nullptr,
304 StringList *descriptions = nullptr) const;
305
306 /// Determine whether a root level, built-in command with this name exists.
307 bool CommandExists(llvm::StringRef cmd) const;
308
309 /// Determine whether an alias command with this name exists
310 bool AliasExists(llvm::StringRef cmd) const;
311
312 /// Determine whether a root-level user command with this name exists.
313 bool UserCommandExists(llvm::StringRef cmd) const;
314
315 /// Determine whether a root-level user multiword command with this name
316 /// exists.
317 bool UserMultiwordCommandExists(llvm::StringRef cmd) const;
318
319 /// Look up the command pointed to by path encoded in the arguments of
320 /// the incoming command object. If all the path components exist
321 /// and are all actual commands - not aliases, and the leaf command is a
322 /// multiword command, return the command. Otherwise return nullptr, and put
323 /// a useful diagnostic in the Status object.
324 ///
325 /// \param[in] path
326 /// An Args object holding the path in its arguments
327 /// \param[in] leaf_is_command
328 /// If true, return the container of the leaf name rather than looking up
329 /// the whole path as a leaf command. The leaf needn't exist in this case.
330 /// \param[in,out] result
331 /// If the path is not found, this error shows where we got off track.
332 /// \return
333 /// If found, a pointer to the CommandObjectMultiword pointed to by path,
334 /// or to the container of the leaf element is is_leaf_command.
335 /// Returns nullptr under two circumstances:
336 /// 1) The command in not found (check error.Fail)
337 /// 2) is_leaf is true and the path has only a leaf. We don't have a
338 /// dummy "contains everything MWC, so we return null here, but
339 /// in this case error.Success is true.
340
342 VerifyUserMultiwordCmdPath(Args &path, bool leaf_is_command, Status &result);
343
344 CommandAlias *AddAlias(llvm::StringRef alias_name,
345 lldb::CommandObjectSP &command_obj_sp,
346 llvm::StringRef args_string = llvm::StringRef());
347
348 /// Remove a command if it is removable (python or regex command). If \b force
349 /// is provided, the command is removed regardless of its removable status.
350 bool RemoveCommand(llvm::StringRef cmd, bool force = false);
351
352 bool RemoveAlias(llvm::StringRef alias_name);
353
354 bool GetAliasFullName(llvm::StringRef cmd, std::string &full_name) const;
355
356 bool RemoveUserMultiword(llvm::StringRef multiword_name);
357
358 // Do we want to allow top-level user multiword commands to be deleted?
360
361 bool RemoveUser(llvm::StringRef alias_name);
362
363 void RemoveAllUser() { m_user_dict.clear(); }
364
365 const CommandAlias *GetAlias(llvm::StringRef alias_name) const;
366
367 CommandObject *BuildAliasResult(llvm::StringRef alias_name,
368 std::string &raw_input_string,
369 std::string &alias_result,
370 CommandReturnObject &result);
371
372 bool HandleCommand(const char *command_line, LazyBool add_to_history,
373 const ExecutionContext &override_context,
374 CommandReturnObject &result);
375
376 bool HandleCommand(const char *command_line, LazyBool add_to_history,
377 CommandReturnObject &result,
378 bool force_repeat_command = false);
379
380 bool InterruptCommand();
381
382 /// Execute a list of commands in sequence.
383 ///
384 /// \param[in] commands
385 /// The list of commands to execute.
386 /// \param[in,out] context
387 /// The execution context in which to run the commands.
388 /// \param[in] options
389 /// This object holds the options used to control when to stop, whether to
390 /// execute commands,
391 /// etc.
392 /// \param[out] result
393 /// This is marked as succeeding with no output if all commands execute
394 /// safely,
395 /// and failed with some explanation if we aborted executing the commands
396 /// at some point.
397 void HandleCommands(const StringList &commands,
398 const ExecutionContext &context,
399 const CommandInterpreterRunOptions &options,
400 CommandReturnObject &result);
401
402 void HandleCommands(const StringList &commands,
403 const CommandInterpreterRunOptions &options,
404 CommandReturnObject &result);
405
406 /// Execute a list of commands from a file.
407 ///
408 /// \param[in] file
409 /// The file from which to read in commands.
410 /// \param[in,out] context
411 /// The execution context in which to run the commands.
412 /// \param[in] options
413 /// This object holds the options used to control when to stop, whether to
414 /// execute commands,
415 /// etc.
416 /// \param[out] result
417 /// This is marked as succeeding with no output if all commands execute
418 /// safely,
419 /// and failed with some explanation if we aborted executing the commands
420 /// at some point.
421 void HandleCommandsFromFile(FileSpec &file, const ExecutionContext &context,
422 const CommandInterpreterRunOptions &options,
423 CommandReturnObject &result);
424
426 const CommandInterpreterRunOptions &options,
427 CommandReturnObject &result);
428
429 CommandObject *GetCommandObjectForCommand(llvm::StringRef &command_line);
430
431 /// Returns the auto-suggestion string that should be added to the given
432 /// command line.
433 std::optional<std::string> GetAutoSuggestionForCommand(llvm::StringRef line);
434
435 // This handles command line completion.
436 void HandleCompletion(CompletionRequest &request);
437
438 // This version just returns matches, and doesn't compute the substring. It
439 // is here so the Help command can call it for the first argument.
441
442 int GetCommandNamesMatchingPartialString(const char *cmd_cstr,
443 bool include_aliases,
444 StringList &matches,
445 StringList &descriptions);
446
447 void GetHelp(CommandReturnObject &result,
448 uint32_t types = eCommandTypesAllThem);
449
450 void GetAliasHelp(const char *alias_name, StreamString &help_string);
451
453 Stream &strm, llvm::StringRef prefix, llvm::StringRef help_text,
454 std::optional<Stream::HighlightSettings> highlight = std::nullopt);
455
457 Stream &stream, llvm::StringRef command_word, llvm::StringRef separator,
458 llvm::StringRef help_text, size_t max_word_len,
459 std::optional<Stream::HighlightSettings> highlight = std::nullopt);
460
461 // this mimics OutputFormattedHelpText but it does perform a much simpler
462 // formatting, basically ensuring line alignment. This is only good if you
463 // have some complicated layout for your help text and want as little help as
464 // reasonable in properly displaying it. Most of the times, you simply want
465 // to type some text and have it printed in a reasonable way on screen. If
466 // so, use OutputFormattedHelpText
467 void OutputHelpText(Stream &stream, llvm::StringRef command_word,
468 llvm::StringRef separator, llvm::StringRef help_text,
469 uint32_t max_word_len);
470
472
473 /// Get the target selected by the user at the command line. All commands
474 /// should prefer this over any other notion of a "current" target, so that
475 /// the user's explicit `target select` stays authoritative within the
476 /// command layer. Non-command code should use the execution context instead.
478 return m_debugger.GetTargetList().GetSelectedTarget();
479 }
480
481 /// Returns the execution context the interpreter should run a command in.
482 /// If `adopt_dummy_target` is true and no real target is selected, the
483 /// dummy target is substituted in. Pass false from CommandObject paths
484 /// where the command hasn't opted into the dummy via
485 /// eCommandAllowsDummyTarget, so callers can't inadvertently end up
486 /// operating on the dummy.
487 ExecutionContext GetExecutionContext(bool adopt_dummy_target = true) const;
488
489 lldb::PlatformSP GetPlatform(bool prefer_target_platform);
490
491 const char *ProcessEmbeddedScriptCommands(const char *arg);
492
493 void UpdatePrompt(llvm::StringRef prompt);
494
495 void UpdateUseColor(bool use_color);
496
497 bool Confirm(llvm::StringRef message, bool default_answer);
498
500
501 void Initialize();
502
503 void Clear();
504
505 bool HasCommands() const;
506
507 bool HasAliases() const;
508
509 bool HasUserCommands() const;
510
511 bool HasUserMultiwordCommands() const;
512
513 bool HasAliasOptions() const;
514
515 void BuildAliasCommandArgs(CommandObject *alias_cmd_obj,
516 const char *alias_name, Args &cmd_args,
517 std::string &raw_input_string,
518 CommandReturnObject &result);
519
520 /// Picks the number out of a string of the form "%NNN", otherwise return 0.
521 int GetOptionArgumentPosition(const char *in_string);
522
523 void SkipLLDBInitFiles(bool skip_lldbinit_files) {
524 m_skip_lldbinit_files = skip_lldbinit_files;
525 }
526
527 void SkipAppInitFiles(bool skip_app_init_files) {
528 m_skip_app_init_files = skip_app_init_files;
529 }
530
531 bool GetSynchronous();
532
533 void FindCommandsForApropos(llvm::StringRef word, StringList &commands_found,
534 StringList &commands_help,
535 bool search_builtin_commands,
536 bool search_user_commands,
537 bool search_alias_commands,
538 bool search_user_mw_commands);
539
541
542 bool SetBatchCommandMode(bool value) {
543 const bool old_value = m_batch_command_mode;
544 m_batch_command_mode = value;
545 return old_value;
546 }
547
552
557
558 void PrintWarningsIfNecessary(Stream &s, const std::string &cmd_name) {
560 s.Printf("*** Some of the displayed variables have more members than the "
561 "debugger will show by default. To show all of them, you can "
562 "either use the --show-all-children option to %s or raise the "
563 "limit by changing the target.max-children-count setting.\n",
564 cmd_name.c_str());
566 }
567
569 s.Printf("*** Some of the displayed variables have a greater depth of "
570 "members than the debugger will show by default. To increase "
571 "the limit, use the --depth option to %s, or raise the limit by "
572 "changing the target.max-children-depth setting.\n",
573 cmd_name.c_str());
575 }
576 }
577
579
580 bool IsActive();
581
584
585 void GetLLDBCommandsFromIOHandler(const char *prompt,
586 IOHandlerDelegate &delegate,
587 void *baton = nullptr);
588
589 void GetPythonCommandsFromIOHandler(const char *prompt,
590 IOHandlerDelegate &delegate,
591 void *baton = nullptr);
592
593 const char *GetCommandPrefix();
594
595 // Properties
596 bool GetExpandRegexAliases() const;
597
598 bool GetPromptOnQuit() const;
599 void SetPromptOnQuit(bool enable);
600
601 bool GetSaveTranscript() const;
602 void SetSaveTranscript(bool enable);
603
604 bool GetSaveSessionOnQuit() const;
605 void SetSaveSessionOnQuit(bool enable);
606
607 bool GetOpenTranscriptInEditor() const;
608 void SetOpenTranscriptInEditor(bool enable);
609
611 void SetSaveSessionDirectory(llvm::StringRef path);
612
613 bool GetEchoCommands() const;
614 void SetEchoCommands(bool enable);
615
616 bool GetEchoCommentCommands() const;
617 void SetEchoCommentCommands(bool enable);
618
619 bool GetRepeatPreviousCommand() const;
620
621 bool GetRequireCommandOverwrite() const;
622
624 return m_user_dict;
625 }
626
630
632 return m_command_dict;
633 }
634
636
637 /// Specify if the command interpreter should allow that the user can
638 /// specify a custom exit code when calling 'quit'.
639 void AllowExitCodeOnQuit(bool allow);
640
641 /// Sets the exit code for the quit command.
642 /// \param[in] exit_code
643 /// The exit code that the driver should return on exit.
644 /// \return True if the exit code was successfully set; false if the
645 /// interpreter doesn't allow custom exit codes.
646 /// \see AllowExitCodeOnQuit
647 [[nodiscard]] bool SetQuitExitCode(int exit_code);
648
649 /// Returns the exit code that the user has specified when running the
650 /// 'quit' command.
651 /// \param[out] exited
652 /// Set to true if the user has called quit with a custom exit code.
653 int GetQuitExitCode(bool &exited) const;
654
655 void ResolveCommand(const char *command_line, CommandReturnObject &result);
656
657 bool GetStopCmdSourceOnError() const;
658
660 GetIOHandler(bool force_create = false,
661 CommandInterpreterRunOptions *options = nullptr);
662
663 bool GetSpaceReplPrompts() const;
664
665 /// Save the current debugger session transcript to a file on disk.
666 /// \param output_file
667 /// The file path to which the session transcript will be written. Since
668 /// the argument is optional, an arbitrary temporary file will be create
669 /// when no argument is passed.
670 /// \param result
671 /// This is used to pass function output and error messages.
672 /// \return \b true if the session transcript was successfully written to
673 /// disk, \b false otherwise.
675 std::optional<std::string> output_file = std::nullopt);
676
678
679 bool IsInteractive();
680
681 bool IOHandlerInterrupt(IOHandler &io_handler) override;
682
683 Status PreprocessCommand(std::string &command);
684 Status PreprocessToken(std::string &token);
685
686 void IncreaseCommandUsage(const CommandObject &cmd_obj) {
687 ++m_command_usages[cmd_obj.GetCommandName()];
688 }
689
691
692 llvm::json::Value GetStatistics();
694
695protected:
696 friend class Debugger;
697
698 // This checks just the RunCommandInterpreter interruption state. It is only
699 // meant to be used in Debugger::InterruptRequested
700 bool WasInterrupted() const;
701
702 // IOHandlerDelegate functions
703 void IOHandlerInputComplete(IOHandler &io_handler,
704 std::string &line) override;
705
706 llvm::StringRef IOHandlerGetControlSequence(char ch) override {
707 static constexpr llvm::StringLiteral control_sequence("quit\n");
708 if (ch == 'd')
709 return control_sequence;
710 return {};
711 }
712
713 void GetProcessOutput();
714
715 bool DidProcessStopAbnormally() const;
716
717 void SetSynchronous(bool value);
718
719 lldb::CommandObjectSP GetCommandSP(llvm::StringRef cmd,
720 bool include_aliases = true,
721 bool exact = true,
722 StringList *matches = nullptr,
723 StringList *descriptions = nullptr) const;
724
725private:
726 void OverrideExecutionContext(const ExecutionContext &override_context);
727
729
730 void SourceInitFile(FileSpec file, CommandReturnObject &result);
731
732 // Completely resolves aliases and abbreviations, returning a pointer to the
733 // final command object and updating command_line to the fully substituted
734 // and translated command.
735 CommandObject *ResolveCommandImpl(std::string &command_line,
736 CommandReturnObject &result);
737
738 void FindCommandsForApropos(llvm::StringRef word, StringList &commands_found,
739 StringList &commands_help,
740 const CommandObject::CommandMap &command_map);
741
742 // An interruptible wrapper around the stream output
743 void PrintCommandOutput(IOHandler &io_handler, llvm::StringRef str,
744 bool is_stdout);
745
746 bool EchoCommandNonInteractive(llvm::StringRef line,
747 const Flags &io_handler_flags) const;
748
749 /// Return the language specific command object for the current frame.
750 ///
751 /// For example, when stopped on a C++ frame, this returns the command object
752 /// for "language cplusplus" (`CommandObjectMultiwordItaniumABI`).
754
755 // A very simple state machine which models the command handling transitions
761
762 std::atomic<CommandHandlingState> m_command_state{
764
766
769
770 Debugger &m_debugger; // The debugger session that this interpreter is
771 // associated with
772 // Execution contexts that were temporarily set by some of HandleCommand*
773 // overloads.
774 std::stack<ExecutionContext> m_overriden_exe_contexts;
778 CommandObject::CommandMap m_command_dict; // Stores basic built-in commands
779 // (they cannot be deleted, removed
780 // or overwritten).
782 m_alias_dict; // Stores user aliases/abbreviations for commands
783 CommandObject::CommandMap m_user_dict; // Stores user-defined commands
785 m_user_mw_dict; // Stores user-defined multiword commands
787 std::string m_repeat_command; // Stores the command that will be executed for
788 // an empty command string.
792 /// Whether we truncated a value's list of children and whether the user has
793 /// been told.
795 /// Whether we reached the maximum child nesting depth and whether the user
796 /// has been told.
798
799 // FIXME: Stop using this to control adding to the history and then replace
800 // this with m_command_source_dirs.size().
802 /// A stack of directory paths. When not empty, the last one is the directory
803 /// of the file that's currently sourced.
804 std::vector<FileSpec> m_command_source_dirs;
805 std::vector<uint32_t> m_command_source_flags;
807
808 /// An optional callback to handle printing the CommandReturnObject.
810
811 // The exit code the user has requested when calling the 'quit' command.
812 // No value means the user hasn't set a custom exit code so far.
813 std::optional<int> m_quit_exit_code;
814 // If the driver is accepts custom exit codes for the 'quit' command.
815 bool m_allow_exit_code = false;
816
817 /// Command usage statistics.
818 typedef llvm::StringMap<uint64_t> CommandUsageMap;
820
821 /// Turn on settings `interpreter.save-transcript` for LLDB to populate
822 /// this stream. Otherwise this stream is empty.
824
825 /// Contains a list of handled commands and their details. Each element in
826 /// the list is a dictionary with the following keys/values:
827 /// - "command" (string): The command that was given by the user.
828 /// - "commandName" (string): The name of the executed command.
829 /// - "commandArguments" (string): The arguments of the executed command.
830 /// - "output" (string): The output of the command. Empty ("") if no output.
831 /// - "error" (string): The error of the command. Empty ("") if no error.
832 /// - "durationInSeconds" (float): The time it took to execute the command.
833 /// - "timestampInEpochSeconds" (int): The timestamp when the command is
834 /// executed.
835 ///
836 /// Turn on settings `interpreter.save-transcript` for LLDB to populate
837 /// this list. Otherwise this list is empty.
839};
840
841} // namespace lldb_private
842
843#endif // LLDB_INTERPRETER_COMMANDINTERPRETER_H
A command line argument class.
Definition Args.h:33
Broadcaster(lldb::BroadcasterManagerSP manager_sp, std::string name)
Construct with a broadcaster with a name.
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, LazyBool handle_repeats)
Construct a CommandInterpreterRunOptions object.
void SetAutoHandleEvents(bool auto_handle_events)
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 OutputFormattedHelpText(Stream &strm, llvm::StringRef prefix, llvm::StringRef help_text, std::optional< Stream::HighlightSettings > highlight=std::nullopt)
lldb::CommandObjectSP GetFrameLanguageCommand() const
Return the language specific command object for the current frame.
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.
CommandReturnObjectCallback m_print_callback
An optional callback to handle printing the CommandReturnObject.
lldb::TargetSP GetSelectedTarget()
Get the target selected by the user at the command line.
std::stack< ExecutionContext > m_overriden_exe_contexts
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)
CommandObject * GetAliasCommandObject(llvm::StringRef cmd, StringList *matches=nullptr, StringList *descriptions=nullptr) const
bool RemoveAlias(llvm::StringRef alias_name)
void SetSaveSessionDirectory(llvm::StringRef path)
std::function< lldb::CommandReturnObjectCallbackResult( CommandReturnObject &)> CommandReturnObjectCallback
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
@ eCommandTypesBuiltin
native commands such as "frame"
@ eCommandTypesHidden
commands prefixed with an underscore
@ eCommandTypesUserMW
multiword commands (command containers)
@ eCommandTypesAliases
aliases such as "po"
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
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
CommandInterpreter(Debugger &debugger, bool synchronous_execution)
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)
ExecutionContext GetExecutionContext(bool adopt_dummy_target=true) const
Returns the execution context the interpreter should run a command in.
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 SetPrintCallback(CommandReturnObjectCallback callback)
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, std::less<> > CommandMap
"lldb/Utility/ArgCompletionRequest.h"
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file utility class.
Definition FileSpec.h:57
A class to manage flags.
Definition Flags.h:22
A delegate class for use with IOHandler subclasses.
Definition IOHandler.h:184
IOHandlerDelegate(Completion completion=Completion::None)
Definition IOHandler.h:188
An error handling class.
Definition Status.h:118
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
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
CommandInterpreterResult
The result from a command interpreter run.
@ eCommandInterpreterResultSuccess
Command interpreter finished successfully.
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::Target > TargetSP
CommandReturnObjectCallbackResult
Callback return value, indicating whether it handled printing the CommandReturnObject or deferred doi...