1 //===-- CommandObjectExpression.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_SOURCE_COMMANDS_COMMANDOBJECTEXPRESSION_H 10 #define LLDB_SOURCE_COMMANDS_COMMANDOBJECTEXPRESSION_H 11 12 #include "lldb/Core/IOHandler.h" 13 #include "lldb/Interpreter/CommandObject.h" 14 #include "lldb/Interpreter/OptionGroupBoolean.h" 15 #include "lldb/Interpreter/OptionGroupFormat.h" 16 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" 17 #include "lldb/Target/Target.h" 18 #include "lldb/lldb-private-enumerations.h" 19 20 namespace lldb_private { 21 22 class CommandObjectExpression : public CommandObjectRaw, 23 public IOHandlerDelegate { 24 public: 25 class CommandOptions : public OptionGroup { 26 public: 27 CommandOptions(); 28 29 ~CommandOptions() override; 30 31 llvm::ArrayRef<OptionDefinition> GetDefinitions() override; 32 33 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, 34 ExecutionContext *execution_context) override; 35 36 void OptionParsingStarting(ExecutionContext *execution_context) override; 37 38 /// Return the appropriate expression options used for evaluating the 39 /// expression in the given target. 40 EvaluateExpressionOptions GetEvaluateExpressionOptions( 41 const Target &target, 42 const OptionGroupValueObjectDisplay &display_opts); 43 44 bool top_level; 45 bool unwind_on_error; 46 bool ignore_breakpoints; 47 bool allow_jit; 48 bool show_types; 49 bool show_summary; 50 bool debug; 51 uint32_t timeout; 52 bool try_all_threads; 53 lldb::LanguageType language; 54 LanguageRuntimeDescriptionDisplayVerbosity m_verbosity; 55 LazyBool auto_apply_fixits; 56 bool suppress_persistent_result; 57 }; 58 59 CommandObjectExpression(CommandInterpreter &interpreter); 60 61 ~CommandObjectExpression() override; 62 63 Options *GetOptions() override; 64 65 void HandleCompletion(CompletionRequest &request) override; 66 67 protected: 68 // IOHandler::Delegate functions 69 void IOHandlerInputComplete(IOHandler &io_handler, 70 std::string &line) override; 71 72 bool IOHandlerIsInputComplete(IOHandler &io_handler, 73 StringList &lines) override; 74 75 bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override; 76 77 /// Evaluates the given expression. 78 /// \param output_stream The stream to which the evaluation result will be 79 /// printed. 80 /// \param error_stream Contains error messages that should be displayed to 81 /// the user in case the evaluation fails. 82 /// \param result A CommandReturnObject which status will be set to the 83 /// appropriate value depending on evaluation success and 84 /// whether the expression produced any result. 85 /// \return Returns true iff the expression was successfully evaluated, 86 /// executed and the result could be printed to the output stream. 87 bool EvaluateExpression(llvm::StringRef expr, Stream &output_stream, 88 Stream &error_stream, CommandReturnObject &result); 89 90 void GetMultilineExpression(); 91 92 OptionGroupOptions m_option_group; 93 OptionGroupFormat m_format_options; 94 OptionGroupValueObjectDisplay m_varobj_options; 95 OptionGroupBoolean m_repl_option; 96 CommandOptions m_command_options; 97 uint32_t m_expr_line_count; 98 std::string m_expr_lines; // Multi-line expression support 99 std::string m_fixed_expression; // Holds the current expression's fixed text. 100 }; 101 102 } // namespace lldb_private 103 104 #endif // LLDB_SOURCE_COMMANDS_COMMANDOBJECTEXPRESSION_H 105