CommandInterpreter.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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. #ifndef LLDB_INTERPRETER_COMMANDINTERPRETER_H
  9. #define LLDB_INTERPRETER_COMMANDINTERPRETER_H
  10. #include "lldb/Core/Debugger.h"
  11. #include "lldb/Core/IOHandler.h"
  12. #include "lldb/Interpreter/CommandAlias.h"
  13. #include "lldb/Interpreter/CommandHistory.h"
  14. #include "lldb/Interpreter/CommandObject.h"
  15. #include "lldb/Interpreter/ScriptInterpreter.h"
  16. #include "lldb/Utility/Args.h"
  17. #include "lldb/Utility/Broadcaster.h"
  18. #include "lldb/Utility/CompletionRequest.h"
  19. #include "lldb/Utility/Event.h"
  20. #include "lldb/Utility/Log.h"
  21. #include "lldb/Utility/StreamString.h"
  22. #include "lldb/Utility/StringList.h"
  23. #include "lldb/lldb-forward.h"
  24. #include "lldb/lldb-private.h"
  25. #include <mutex>
  26. #include <stack>
  27. namespace lldb_private {
  28. class CommandInterpreter;
  29. class CommandInterpreterRunResult {
  30. public:
  31. CommandInterpreterRunResult()
  32. : m_num_errors(0), m_result(lldb::eCommandInterpreterResultSuccess) {}
  33. uint32_t GetNumErrors() const { return m_num_errors; }
  34. lldb::CommandInterpreterResult GetResult() const { return m_result; }
  35. bool IsResult(lldb::CommandInterpreterResult result) {
  36. return m_result == result;
  37. }
  38. protected:
  39. friend CommandInterpreter;
  40. void IncrementNumberOfErrors() { m_num_errors++; }
  41. void SetResult(lldb::CommandInterpreterResult result) { m_result = result; }
  42. private:
  43. int m_num_errors;
  44. lldb::CommandInterpreterResult m_result;
  45. };
  46. class CommandInterpreterRunOptions {
  47. public:
  48. /// Construct a CommandInterpreterRunOptions object. This class is used to
  49. /// control all the instances where we run multiple commands, e.g.
  50. /// HandleCommands, HandleCommandsFromFile, RunCommandInterpreter.
  51. ///
  52. /// The meanings of the options in this object are:
  53. ///
  54. /// \param[in] stop_on_continue
  55. /// If \b true, execution will end on the first command that causes the
  56. /// process in the execution context to continue. If \b false, we won't
  57. /// check the execution status.
  58. /// \param[in] stop_on_error
  59. /// If \b true, execution will end on the first command that causes an
  60. /// error.
  61. /// \param[in] stop_on_crash
  62. /// If \b true, when a command causes the target to run, and the end of the
  63. /// run is a signal or exception, stop executing the commands.
  64. /// \param[in] echo_commands
  65. /// If \b true, echo the command before executing it. If \b false, execute
  66. /// silently.
  67. /// \param[in] echo_comments
  68. /// If \b true, echo command even if it is a pure comment line. If
  69. /// \b false, print no ouput in this case. This setting has an effect only
  70. /// if echo_commands is \b true.
  71. /// \param[in] print_results
  72. /// If \b true and the command succeeds, print the results of the command
  73. /// after executing it. If \b false, execute silently.
  74. /// \param[in] print_errors
  75. /// If \b true and the command fails, print the results of the command
  76. /// after executing it. If \b false, execute silently.
  77. /// \param[in] add_to_history
  78. /// If \b true add the commands to the command history. If \b false, don't
  79. /// add them.
  80. CommandInterpreterRunOptions(LazyBool stop_on_continue,
  81. LazyBool stop_on_error, LazyBool stop_on_crash,
  82. LazyBool echo_commands, LazyBool echo_comments,
  83. LazyBool print_results, LazyBool print_errors,
  84. LazyBool add_to_history)
  85. : m_stop_on_continue(stop_on_continue), m_stop_on_error(stop_on_error),
  86. m_stop_on_crash(stop_on_crash), m_echo_commands(echo_commands),
  87. m_echo_comment_commands(echo_comments), m_print_results(print_results),
  88. m_print_errors(print_errors), m_add_to_history(add_to_history) {}
  89. CommandInterpreterRunOptions()
  90. : m_stop_on_continue(eLazyBoolCalculate),
  91. m_stop_on_error(eLazyBoolCalculate),
  92. m_stop_on_crash(eLazyBoolCalculate),
  93. m_echo_commands(eLazyBoolCalculate),
  94. m_echo_comment_commands(eLazyBoolCalculate),
  95. m_print_results(eLazyBoolCalculate), m_print_errors(eLazyBoolCalculate),
  96. m_add_to_history(eLazyBoolCalculate) {}
  97. void SetSilent(bool silent) {
  98. LazyBool value = silent ? eLazyBoolNo : eLazyBoolYes;
  99. m_print_results = value;
  100. m_print_errors = value;
  101. m_echo_commands = value;
  102. m_echo_comment_commands = value;
  103. m_add_to_history = value;
  104. }
  105. // These return the default behaviors if the behavior is not
  106. // eLazyBoolCalculate. But I've also left the ivars public since for
  107. // different ways of running the interpreter you might want to force
  108. // different defaults... In that case, just grab the LazyBool ivars directly
  109. // and do what you want with eLazyBoolCalculate.
  110. bool GetStopOnContinue() const { return DefaultToNo(m_stop_on_continue); }
  111. void SetStopOnContinue(bool stop_on_continue) {
  112. m_stop_on_continue = stop_on_continue ? eLazyBoolYes : eLazyBoolNo;
  113. }
  114. bool GetStopOnError() const { return DefaultToNo(m_stop_on_error); }
  115. void SetStopOnError(bool stop_on_error) {
  116. m_stop_on_error = stop_on_error ? eLazyBoolYes : eLazyBoolNo;
  117. }
  118. bool GetStopOnCrash() const { return DefaultToNo(m_stop_on_crash); }
  119. void SetStopOnCrash(bool stop_on_crash) {
  120. m_stop_on_crash = stop_on_crash ? eLazyBoolYes : eLazyBoolNo;
  121. }
  122. bool GetEchoCommands() const { return DefaultToYes(m_echo_commands); }
  123. void SetEchoCommands(bool echo_commands) {
  124. m_echo_commands = echo_commands ? eLazyBoolYes : eLazyBoolNo;
  125. }
  126. bool GetEchoCommentCommands() const {
  127. return DefaultToYes(m_echo_comment_commands);
  128. }
  129. void SetEchoCommentCommands(bool echo_comments) {
  130. m_echo_comment_commands = echo_comments ? eLazyBoolYes : eLazyBoolNo;
  131. }
  132. bool GetPrintResults() const { return DefaultToYes(m_print_results); }
  133. void SetPrintResults(bool print_results) {
  134. m_print_results = print_results ? eLazyBoolYes : eLazyBoolNo;
  135. }
  136. bool GetPrintErrors() const { return DefaultToYes(m_print_errors); }
  137. void SetPrintErrors(bool print_errors) {
  138. m_print_errors = print_errors ? eLazyBoolYes : eLazyBoolNo;
  139. }
  140. bool GetAddToHistory() const { return DefaultToYes(m_add_to_history); }
  141. void SetAddToHistory(bool add_to_history) {
  142. m_add_to_history = add_to_history ? eLazyBoolYes : eLazyBoolNo;
  143. }
  144. bool GetAutoHandleEvents() const {
  145. return DefaultToYes(m_auto_handle_events);
  146. }
  147. void SetAutoHandleEvents(bool auto_handle_events) {
  148. m_auto_handle_events = auto_handle_events ? eLazyBoolYes : eLazyBoolNo;
  149. }
  150. bool GetSpawnThread() const { return DefaultToNo(m_spawn_thread); }
  151. void SetSpawnThread(bool spawn_thread) {
  152. m_spawn_thread = spawn_thread ? eLazyBoolYes : eLazyBoolNo;
  153. }
  154. LazyBool m_stop_on_continue;
  155. LazyBool m_stop_on_error;
  156. LazyBool m_stop_on_crash;
  157. LazyBool m_echo_commands;
  158. LazyBool m_echo_comment_commands;
  159. LazyBool m_print_results;
  160. LazyBool m_print_errors;
  161. LazyBool m_add_to_history;
  162. LazyBool m_auto_handle_events;
  163. LazyBool m_spawn_thread;
  164. private:
  165. static bool DefaultToYes(LazyBool flag) {
  166. switch (flag) {
  167. case eLazyBoolNo:
  168. return false;
  169. default:
  170. return true;
  171. }
  172. }
  173. static bool DefaultToNo(LazyBool flag) {
  174. switch (flag) {
  175. case eLazyBoolYes:
  176. return true;
  177. default:
  178. return false;
  179. }
  180. }
  181. };
  182. class CommandInterpreter : public Broadcaster,
  183. public Properties,
  184. public IOHandlerDelegate {
  185. public:
  186. enum {
  187. eBroadcastBitThreadShouldExit = (1 << 0),
  188. eBroadcastBitResetPrompt = (1 << 1),
  189. eBroadcastBitQuitCommandReceived = (1 << 2), // User entered quit
  190. eBroadcastBitAsynchronousOutputData = (1 << 3),
  191. eBroadcastBitAsynchronousErrorData = (1 << 4)
  192. };
  193. enum ChildrenTruncatedWarningStatus // tristate boolean to manage children
  194. // truncation warning
  195. { eNoTruncation = 0, // never truncated
  196. eUnwarnedTruncation = 1, // truncated but did not notify
  197. eWarnedTruncation = 2 // truncated and notified
  198. };
  199. enum CommandTypes {
  200. eCommandTypesBuiltin = 0x0001, // native commands such as "frame"
  201. eCommandTypesUserDef = 0x0002, // scripted commands
  202. eCommandTypesAliases = 0x0004, // aliases such as "po"
  203. eCommandTypesHidden = 0x0008, // commands prefixed with an underscore
  204. eCommandTypesAllThem = 0xFFFF // all commands
  205. };
  206. CommandInterpreter(Debugger &debugger, bool synchronous_execution);
  207. ~CommandInterpreter() override = default;
  208. // These two functions fill out the Broadcaster interface:
  209. static ConstString &GetStaticBroadcasterClass();
  210. ConstString &GetBroadcasterClass() const override {
  211. return GetStaticBroadcasterClass();
  212. }
  213. void SourceInitFileCwd(CommandReturnObject &result);
  214. void SourceInitFileHome(CommandReturnObject &result, bool is_repl = false);
  215. bool AddCommand(llvm::StringRef name, const lldb::CommandObjectSP &cmd_sp,
  216. bool can_replace);
  217. bool AddUserCommand(llvm::StringRef name, const lldb::CommandObjectSP &cmd_sp,
  218. bool can_replace);
  219. lldb::CommandObjectSP GetCommandSPExact(llvm::StringRef cmd,
  220. bool include_aliases = false) const;
  221. CommandObject *GetCommandObject(llvm::StringRef cmd,
  222. StringList *matches = nullptr,
  223. StringList *descriptions = nullptr) const;
  224. bool CommandExists(llvm::StringRef cmd) const;
  225. bool AliasExists(llvm::StringRef cmd) const;
  226. bool UserCommandExists(llvm::StringRef cmd) const;
  227. CommandAlias *AddAlias(llvm::StringRef alias_name,
  228. lldb::CommandObjectSP &command_obj_sp,
  229. llvm::StringRef args_string = llvm::StringRef());
  230. // Remove a command if it is removable (python or regex command)
  231. bool RemoveCommand(llvm::StringRef cmd);
  232. bool RemoveAlias(llvm::StringRef alias_name);
  233. bool GetAliasFullName(llvm::StringRef cmd, std::string &full_name) const;
  234. bool RemoveUser(llvm::StringRef alias_name);
  235. void RemoveAllUser() { m_user_dict.clear(); }
  236. const CommandAlias *GetAlias(llvm::StringRef alias_name) const;
  237. CommandObject *BuildAliasResult(llvm::StringRef alias_name,
  238. std::string &raw_input_string,
  239. std::string &alias_result,
  240. CommandReturnObject &result);
  241. bool HandleCommand(const char *command_line, LazyBool add_to_history,
  242. const ExecutionContext &override_context,
  243. CommandReturnObject &result);
  244. bool HandleCommand(const char *command_line, LazyBool add_to_history,
  245. CommandReturnObject &result);
  246. bool WasInterrupted() const;
  247. /// Execute a list of commands in sequence.
  248. ///
  249. /// \param[in] commands
  250. /// The list of commands to execute.
  251. /// \param[in,out] context
  252. /// The execution context in which to run the commands.
  253. /// \param[in] options
  254. /// This object holds the options used to control when to stop, whether to
  255. /// execute commands,
  256. /// etc.
  257. /// \param[out] result
  258. /// This is marked as succeeding with no output if all commands execute
  259. /// safely,
  260. /// and failed with some explanation if we aborted executing the commands
  261. /// at some point.
  262. void HandleCommands(const StringList &commands,
  263. const ExecutionContext &context,
  264. const CommandInterpreterRunOptions &options,
  265. CommandReturnObject &result);
  266. void HandleCommands(const StringList &commands,
  267. const CommandInterpreterRunOptions &options,
  268. CommandReturnObject &result);
  269. /// Execute a list of commands from a file.
  270. ///
  271. /// \param[in] file
  272. /// The file from which to read in commands.
  273. /// \param[in,out] context
  274. /// The execution context in which to run the commands.
  275. /// \param[in] options
  276. /// This object holds the options used to control when to stop, whether to
  277. /// execute commands,
  278. /// etc.
  279. /// \param[out] result
  280. /// This is marked as succeeding with no output if all commands execute
  281. /// safely,
  282. /// and failed with some explanation if we aborted executing the commands
  283. /// at some point.
  284. void HandleCommandsFromFile(FileSpec &file, const ExecutionContext &context,
  285. const CommandInterpreterRunOptions &options,
  286. CommandReturnObject &result);
  287. void HandleCommandsFromFile(FileSpec &file,
  288. const CommandInterpreterRunOptions &options,
  289. CommandReturnObject &result);
  290. CommandObject *GetCommandObjectForCommand(llvm::StringRef &command_line);
  291. /// Returns the auto-suggestion string that should be added to the given
  292. /// command line.
  293. llvm::Optional<std::string> GetAutoSuggestionForCommand(llvm::StringRef line);
  294. // This handles command line completion.
  295. void HandleCompletion(CompletionRequest &request);
  296. // This version just returns matches, and doesn't compute the substring. It
  297. // is here so the Help command can call it for the first argument.
  298. void HandleCompletionMatches(CompletionRequest &request);
  299. int GetCommandNamesMatchingPartialString(const char *cmd_cstr,
  300. bool include_aliases,
  301. StringList &matches,
  302. StringList &descriptions);
  303. void GetHelp(CommandReturnObject &result,
  304. uint32_t types = eCommandTypesAllThem);
  305. void GetAliasHelp(const char *alias_name, StreamString &help_string);
  306. void OutputFormattedHelpText(Stream &strm, llvm::StringRef prefix,
  307. llvm::StringRef help_text);
  308. void OutputFormattedHelpText(Stream &stream, llvm::StringRef command_word,
  309. llvm::StringRef separator,
  310. llvm::StringRef help_text, size_t max_word_len);
  311. // this mimics OutputFormattedHelpText but it does perform a much simpler
  312. // formatting, basically ensuring line alignment. This is only good if you
  313. // have some complicated layout for your help text and want as little help as
  314. // reasonable in properly displaying it. Most of the times, you simply want
  315. // to type some text and have it printed in a reasonable way on screen. If
  316. // so, use OutputFormattedHelpText
  317. void OutputHelpText(Stream &stream, llvm::StringRef command_word,
  318. llvm::StringRef separator, llvm::StringRef help_text,
  319. uint32_t max_word_len);
  320. Debugger &GetDebugger() { return m_debugger; }
  321. ExecutionContext GetExecutionContext() const;
  322. lldb::PlatformSP GetPlatform(bool prefer_target_platform);
  323. const char *ProcessEmbeddedScriptCommands(const char *arg);
  324. void UpdatePrompt(llvm::StringRef prompt);
  325. bool Confirm(llvm::StringRef message, bool default_answer);
  326. void LoadCommandDictionary();
  327. void Initialize();
  328. void Clear();
  329. bool HasCommands() const;
  330. bool HasAliases() const;
  331. bool HasUserCommands() const;
  332. bool HasAliasOptions() const;
  333. void BuildAliasCommandArgs(CommandObject *alias_cmd_obj,
  334. const char *alias_name, Args &cmd_args,
  335. std::string &raw_input_string,
  336. CommandReturnObject &result);
  337. int GetOptionArgumentPosition(const char *in_string);
  338. void SkipLLDBInitFiles(bool skip_lldbinit_files) {
  339. m_skip_lldbinit_files = skip_lldbinit_files;
  340. }
  341. void SkipAppInitFiles(bool skip_app_init_files) {
  342. m_skip_app_init_files = skip_app_init_files;
  343. }
  344. bool GetSynchronous();
  345. void FindCommandsForApropos(llvm::StringRef word, StringList &commands_found,
  346. StringList &commands_help,
  347. bool search_builtin_commands,
  348. bool search_user_commands,
  349. bool search_alias_commands);
  350. bool GetBatchCommandMode() { return m_batch_command_mode; }
  351. bool SetBatchCommandMode(bool value) {
  352. const bool old_value = m_batch_command_mode;
  353. m_batch_command_mode = value;
  354. return old_value;
  355. }
  356. void ChildrenTruncated() {
  357. if (m_truncation_warning == eNoTruncation)
  358. m_truncation_warning = eUnwarnedTruncation;
  359. }
  360. bool TruncationWarningNecessary() {
  361. return (m_truncation_warning == eUnwarnedTruncation);
  362. }
  363. void TruncationWarningGiven() { m_truncation_warning = eWarnedTruncation; }
  364. const char *TruncationWarningText() {
  365. return "*** Some of your variables have more members than the debugger "
  366. "will show by default. To show all of them, you can either use the "
  367. "--show-all-children option to %s or raise the limit by changing "
  368. "the target.max-children-count setting.\n";
  369. }
  370. CommandHistory &GetCommandHistory() { return m_command_history; }
  371. bool IsActive();
  372. CommandInterpreterRunResult
  373. RunCommandInterpreter(CommandInterpreterRunOptions &options);
  374. void GetLLDBCommandsFromIOHandler(const char *prompt,
  375. IOHandlerDelegate &delegate,
  376. void *baton = nullptr);
  377. void GetPythonCommandsFromIOHandler(const char *prompt,
  378. IOHandlerDelegate &delegate,
  379. void *baton = nullptr);
  380. const char *GetCommandPrefix();
  381. // Properties
  382. bool GetExpandRegexAliases() const;
  383. bool GetPromptOnQuit() const;
  384. void SetPromptOnQuit(bool enable);
  385. bool GetSaveSessionOnQuit() const;
  386. void SetSaveSessionOnQuit(bool enable);
  387. bool GetEchoCommands() const;
  388. void SetEchoCommands(bool enable);
  389. bool GetEchoCommentCommands() const;
  390. void SetEchoCommentCommands(bool enable);
  391. bool GetRepeatPreviousCommand() const;
  392. const CommandObject::CommandMap &GetUserCommands() const {
  393. return m_user_dict;
  394. }
  395. const CommandObject::CommandMap &GetCommands() const {
  396. return m_command_dict;
  397. }
  398. const CommandObject::CommandMap &GetAliases() const { return m_alias_dict; }
  399. /// Specify if the command interpreter should allow that the user can
  400. /// specify a custom exit code when calling 'quit'.
  401. void AllowExitCodeOnQuit(bool allow);
  402. /// Sets the exit code for the quit command.
  403. /// \param[in] exit_code
  404. /// The exit code that the driver should return on exit.
  405. /// \return True if the exit code was successfully set; false if the
  406. /// interpreter doesn't allow custom exit codes.
  407. /// \see AllowExitCodeOnQuit
  408. LLVM_NODISCARD bool SetQuitExitCode(int exit_code);
  409. /// Returns the exit code that the user has specified when running the
  410. /// 'quit' command.
  411. /// \param[out] exited
  412. /// Set to true if the user has called quit with a custom exit code.
  413. int GetQuitExitCode(bool &exited) const;
  414. void ResolveCommand(const char *command_line, CommandReturnObject &result);
  415. bool GetStopCmdSourceOnError() const;
  416. lldb::IOHandlerSP
  417. GetIOHandler(bool force_create = false,
  418. CommandInterpreterRunOptions *options = nullptr);
  419. bool GetSpaceReplPrompts() const;
  420. /// Save the current debugger session transcript to a file on disk.
  421. /// \param output_file
  422. /// The file path to which the session transcript will be written. Since
  423. /// the argument is optional, an arbitrary temporary file will be create
  424. /// when no argument is passed.
  425. /// \param result
  426. /// This is used to pass function output and error messages.
  427. /// \return \b true if the session transcript was successfully written to
  428. /// disk, \b false otherwise.
  429. bool SaveTranscript(CommandReturnObject &result,
  430. llvm::Optional<std::string> output_file = llvm::None);
  431. FileSpec GetCurrentSourceDir();
  432. protected:
  433. friend class Debugger;
  434. // IOHandlerDelegate functions
  435. void IOHandlerInputComplete(IOHandler &io_handler,
  436. std::string &line) override;
  437. ConstString IOHandlerGetControlSequence(char ch) override {
  438. if (ch == 'd')
  439. return ConstString("quit\n");
  440. return ConstString();
  441. }
  442. bool IOHandlerInterrupt(IOHandler &io_handler) override;
  443. void GetProcessOutput();
  444. bool DidProcessStopAbnormally() const;
  445. void SetSynchronous(bool value);
  446. lldb::CommandObjectSP GetCommandSP(llvm::StringRef cmd,
  447. bool include_aliases = true,
  448. bool exact = true,
  449. StringList *matches = nullptr,
  450. StringList *descriptions = nullptr) const;
  451. private:
  452. void OverrideExecutionContext(const ExecutionContext &override_context);
  453. void RestoreExecutionContext();
  454. Status PreprocessCommand(std::string &command);
  455. void SourceInitFile(FileSpec file, CommandReturnObject &result);
  456. // Completely resolves aliases and abbreviations, returning a pointer to the
  457. // final command object and updating command_line to the fully substituted
  458. // and translated command.
  459. CommandObject *ResolveCommandImpl(std::string &command_line,
  460. CommandReturnObject &result);
  461. void FindCommandsForApropos(llvm::StringRef word, StringList &commands_found,
  462. StringList &commands_help,
  463. CommandObject::CommandMap &command_map);
  464. // An interruptible wrapper around the stream output
  465. void PrintCommandOutput(Stream &stream, llvm::StringRef str);
  466. bool EchoCommandNonInteractive(llvm::StringRef line,
  467. const Flags &io_handler_flags) const;
  468. // A very simple state machine which models the command handling transitions
  469. enum class CommandHandlingState {
  470. eIdle,
  471. eInProgress,
  472. eInterrupted,
  473. };
  474. std::atomic<CommandHandlingState> m_command_state{
  475. CommandHandlingState::eIdle};
  476. int m_iohandler_nesting_level = 0;
  477. void StartHandlingCommand();
  478. void FinishHandlingCommand();
  479. bool InterruptCommand();
  480. Debugger &m_debugger; // The debugger session that this interpreter is
  481. // associated with
  482. // Execution contexts that were temporarily set by some of HandleCommand*
  483. // overloads.
  484. std::stack<ExecutionContext> m_overriden_exe_contexts;
  485. bool m_synchronous_execution;
  486. bool m_skip_lldbinit_files;
  487. bool m_skip_app_init_files;
  488. CommandObject::CommandMap m_command_dict; // Stores basic built-in commands
  489. // (they cannot be deleted, removed
  490. // or overwritten).
  491. CommandObject::CommandMap
  492. m_alias_dict; // Stores user aliases/abbreviations for commands
  493. CommandObject::CommandMap m_user_dict; // Stores user-defined commands
  494. CommandHistory m_command_history;
  495. std::string m_repeat_command; // Stores the command that will be executed for
  496. // an empty command string.
  497. lldb::IOHandlerSP m_command_io_handler_sp;
  498. char m_comment_char;
  499. bool m_batch_command_mode;
  500. ChildrenTruncatedWarningStatus m_truncation_warning; // Whether we truncated
  501. // children and whether
  502. // the user has been told
  503. // FIXME: Stop using this to control adding to the history and then replace
  504. // this with m_command_source_dirs.size().
  505. uint32_t m_command_source_depth;
  506. /// A stack of directory paths. When not empty, the last one is the directory
  507. /// of the file that's currently sourced.
  508. std::vector<FileSpec> m_command_source_dirs;
  509. std::vector<uint32_t> m_command_source_flags;
  510. CommandInterpreterRunResult m_result;
  511. // The exit code the user has requested when calling the 'quit' command.
  512. // No value means the user hasn't set a custom exit code so far.
  513. llvm::Optional<int> m_quit_exit_code;
  514. // If the driver is accepts custom exit codes for the 'quit' command.
  515. bool m_allow_exit_code = false;
  516. StreamString m_transcript_stream;
  517. };
  518. } // namespace lldb_private
  519. #endif // LLDB_INTERPRETER_COMMANDINTERPRETER_H