File indexing completed on 2026-05-10 08:42:48
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_EXPRESSION_REPL_H
0010 #define LLDB_EXPRESSION_REPL_H
0011
0012 #include <string>
0013
0014 #include "lldb/Core/IOHandler.h"
0015 #include "lldb/Interpreter/OptionGroupFormat.h"
0016 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
0017 #include "lldb/Target/Target.h"
0018 #include "llvm/Support/ExtensibleRTTI.h"
0019
0020 namespace lldb_private {
0021
0022 class REPL : public IOHandlerDelegate,
0023 public llvm::RTTIExtends<REPL, llvm::RTTIRoot> {
0024 public:
0025
0026 static char ID;
0027
0028 REPL(Target &target);
0029
0030 ~REPL() override;
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 static lldb::REPLSP Create(Status &Status, lldb::LanguageType language,
0056 Debugger *debugger, Target *target,
0057 const char *repl_options);
0058
0059 void SetFormatOptions(const OptionGroupFormat &options) {
0060 m_format_options = options;
0061 }
0062
0063 void
0064 SetValueObjectDisplayOptions(const OptionGroupValueObjectDisplay &options) {
0065 m_varobj_options = options;
0066 }
0067
0068 void SetEvaluateOptions(const EvaluateExpressionOptions &options) {
0069 m_expr_options = options;
0070 }
0071
0072 void SetCompilerOptions(const char *options) {
0073 if (options)
0074 m_compiler_options = options;
0075 }
0076
0077 lldb::IOHandlerSP GetIOHandler();
0078
0079 Status RunLoop();
0080
0081
0082 void IOHandlerActivated(IOHandler &io_handler, bool interactive) override;
0083
0084 bool IOHandlerInterrupt(IOHandler &io_handler) override;
0085
0086 void IOHandlerInputInterrupted(IOHandler &io_handler,
0087 std::string &line) override;
0088
0089 const char *IOHandlerGetFixIndentationCharacters() override;
0090
0091 llvm::StringRef IOHandlerGetControlSequence(char ch) override;
0092
0093 const char *IOHandlerGetCommandPrefix() override;
0094
0095 const char *IOHandlerGetHelpPrologue() override;
0096
0097 bool IOHandlerIsInputComplete(IOHandler &io_handler,
0098 StringList &lines) override;
0099
0100 int IOHandlerFixIndentation(IOHandler &io_handler, const StringList &lines,
0101 int cursor_position) override;
0102
0103 void IOHandlerInputComplete(IOHandler &io_handler,
0104 std::string &line) override;
0105
0106 void IOHandlerComplete(IOHandler &io_handler,
0107 CompletionRequest &request) override;
0108
0109 protected:
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 virtual llvm::Error
0120 OnExpressionEvaluated(const ExecutionContext &exe_ctx, llvm::StringRef code,
0121 const EvaluateExpressionOptions &expr_options,
0122 lldb::ExpressionResults execution_results,
0123 const lldb::ValueObjectSP &result_valobj_sp,
0124 const Status &error) {
0125 return llvm::Error::success();
0126 }
0127
0128 static int CalculateActualIndentation(const StringList &lines);
0129
0130
0131
0132 virtual Status DoInitialization() = 0;
0133
0134 virtual llvm::StringRef GetSourceFileBasename() = 0;
0135
0136 virtual const char *GetAutoIndentCharacters() = 0;
0137
0138 virtual bool SourceIsComplete(const std::string &source) = 0;
0139
0140 virtual lldb::offset_t GetDesiredIndentation(
0141 const StringList &lines, int cursor_position,
0142 int tab_size) = 0;
0143
0144 virtual lldb::LanguageType GetLanguage() = 0;
0145
0146 virtual bool PrintOneVariable(Debugger &debugger,
0147 lldb::StreamFileSP &output_sp,
0148 lldb::ValueObjectSP &valobj_sp,
0149 ExpressionVariable *var = nullptr) = 0;
0150
0151 virtual void CompleteCode(const std::string ¤t_code,
0152 CompletionRequest &request) = 0;
0153
0154 OptionGroupFormat m_format_options = OptionGroupFormat(lldb::eFormatDefault);
0155 OptionGroupValueObjectDisplay m_varobj_options;
0156 EvaluateExpressionOptions m_expr_options;
0157 std::string m_compiler_options;
0158
0159 bool m_enable_auto_indent = true;
0160 std::string m_indent_str;
0161 std::string m_current_indent_str;
0162 uint32_t m_current_indent_level = 0;
0163
0164 std::string m_repl_source_path;
0165 bool m_dedicated_repl_mode = false;
0166
0167 StringList m_code;
0168
0169 Target &m_target;
0170 lldb::IOHandlerSP m_io_handler_sp;
0171
0172 private:
0173 std::string GetSourcePath();
0174 };
0175
0176 }
0177
0178 #endif