LLDB mainline
lldb_private::REPL Class Referenceabstract

#include <REPL.h>

Inheritance diagram for lldb_private::REPL:
[legend]

Public Member Functions

 REPL (Target &target)
 ~REPL () override
void SetFormatOptions (const OptionGroupFormat &options)
void SetValueObjectDisplayOptions (const OptionGroupValueObjectDisplay &options)
void SetEvaluateOptions (const EvaluateExpressionOptions &options)
void SetCompilerOptions (const char *options)
lldb::IOHandlerSP GetIOHandler ()
Status RunLoop ()
void IOHandlerActivated (IOHandler &io_handler, bool interactive) override
bool IOHandlerInterrupt (IOHandler &io_handler) override
void IOHandlerInputInterrupted (IOHandler &io_handler, std::string &line) override
const char * IOHandlerGetFixIndentationCharacters () override
llvm::StringRef IOHandlerGetControlSequence (char ch) override
const char * IOHandlerGetCommandPrefix () override
const char * IOHandlerGetHelpPrologue () override
bool IOHandlerIsInputComplete (IOHandler &io_handler, StringList &lines) override
 Called to determine whether typing enter after the last line in lines should end input.
int IOHandlerFixIndentation (IOHandler &io_handler, const StringList &lines, int cursor_position) override
 Called when a new line is created or one of an identified set of indentation characters is typed.
void IOHandlerInputComplete (IOHandler &io_handler, std::string &line) override
 Called when a line or lines have been retrieved.
void IOHandlerComplete (IOHandler &io_handler, CompletionRequest &request) override
Public Member Functions inherited from lldb_private::IOHandlerDelegate
 IOHandlerDelegate (Completion completion=Completion::None)
virtual ~IOHandlerDelegate ()=default
virtual void IOHandlerDeactivated (IOHandler &io_handler)
virtual std::optional< std::string > IOHandlerSuggestion (IOHandler &io_handler, llvm::StringRef line)

Static Public Member Functions

static lldb::REPLSP Create (Status &Status, lldb::LanguageType language, Debugger *debugger, Target *target, const char *repl_options)
 Get a REPL with an existing target (or, failing that, a debugger to use), and (optional) extra arguments for the compiler.

Static Public Attributes

static char ID
 LLVM RTTI support.

Protected Member Functions

virtual llvm::Error OnExpressionEvaluated (const ExecutionContext &exe_ctx, llvm::StringRef code, const EvaluateExpressionOptions &expr_options, lldb::ExpressionResults execution_results, const lldb::ValueObjectSP &result_valobj_sp, const Status &error)
 Method that can be optionally overriden by subclasses to get notified whenever an expression has been evaluated.
virtual Status DoInitialization ()=0
virtual llvm::StringRef GetSourceFileBasename ()=0
virtual const char * GetAutoIndentCharacters ()=0
virtual bool SourceIsComplete (const std::string &source)=0
virtual lldb::offset_t GetDesiredIndentation (const StringList &lines, int cursor_position, int tab_size)=0
virtual lldb::LanguageType GetLanguage ()=0
virtual bool PrintOneVariable (Debugger &debugger, lldb::StreamFileSP &output_sp, lldb::ValueObjectSP &valobj_sp, ExpressionVariable *var=nullptr)=0
virtual void CompleteCode (const std::string &current_code, CompletionRequest &request)=0

Static Protected Member Functions

static int CalculateActualIndentation (const StringList &lines)

Protected Attributes

OptionGroupFormat m_format_options = OptionGroupFormat(lldb::eFormatDefault)
OptionGroupValueObjectDisplay m_varobj_options
EvaluateExpressionOptions m_expr_options
std::string m_compiler_options
bool m_enable_auto_indent = true
std::string m_indent_str
std::string m_current_indent_str
uint32_t m_current_indent_level = 0
std::string m_repl_source_path
bool m_dedicated_repl_mode = false
StringList m_code
Targetm_target
lldb::IOHandlerSP m_io_handler_sp
Protected Attributes inherited from lldb_private::IOHandlerDelegate
Completion m_completion

Private Member Functions

std::string GetSourcePath ()

Additional Inherited Members

Public Types inherited from lldb_private::IOHandlerDelegate
enum class  Completion { None , LLDBCommand , Expression }

Detailed Description

Definition at line 22 of file REPL.h.

Constructor & Destructor Documentation

◆ REPL()

◆ ~REPL()

REPL::~REPL ( )
overridedefault

Member Function Documentation

◆ CalculateActualIndentation()

int REPL::CalculateActualIndentation ( const StringList & lines)
staticprotected

Definition at line 155 of file REPL.cpp.

References lldb_private::StringList::GetSize().

Referenced by IOHandlerFixIndentation().

◆ CompleteCode()

virtual void lldb_private::REPL::CompleteCode ( const std::string & current_code,
CompletionRequest & request )
protectedpure virtual

Referenced by IOHandlerComplete().

◆ Create()

lldb::REPLSP REPL::Create ( Status & Status,
lldb::LanguageType language,
Debugger * debugger,
Target * target,
const char * repl_options )
static

Get a REPL with an existing target (or, failing that, a debugger to use), and (optional) extra arguments for the compiler.

Parameters
[out]StatusIf this language is supported but the REPL couldn't be created, this error is populated with the reason.
[in]languageThe language to create a REPL for.
[in]debuggerIf provided, and target is nullptr, the debugger to use when setting up a top-level REPL.
[in]targetIf provided, the target to put the REPL inside.
[in]repl_optionsIf provided, additional options for the compiler when parsing REPL expressions.
Returns
The range of the containing object in the target process.

Definition at line 38 of file REPL.cpp.

References lldb_private::PluginManager::GetREPLCreateCallbackAtIndex(), and lldb_private::PluginManager::GetREPLSupportedLanguagesAtIndex().

Referenced by lldb_private::Target::GetREPL(), and lldb_private::Debugger::RunREPL().

◆ DoInitialization()

virtual Status lldb_private::REPL::DoInitialization ( )
protectedpure virtual

Referenced by RunLoop().

◆ GetAutoIndentCharacters()

virtual const char * lldb_private::REPL::GetAutoIndentCharacters ( )
protectedpure virtual

◆ GetDesiredIndentation()

virtual lldb::offset_t lldb_private::REPL::GetDesiredIndentation ( const StringList & lines,
int cursor_position,
int tab_size )
protectedpure virtual

Referenced by IOHandlerFixIndentation().

◆ GetIOHandler()

◆ GetLanguage()

virtual lldb::LanguageType lldb_private::REPL::GetLanguage ( )
protectedpure virtual

Referenced by IOHandlerInputComplete().

◆ GetSourceFileBasename()

virtual llvm::StringRef lldb_private::REPL::GetSourceFileBasename ( )
protectedpure virtual

Referenced by GetSourcePath().

◆ GetSourcePath()

◆ IOHandlerActivated()

void REPL::IOHandlerActivated ( IOHandler & io_handler,
bool interactive )
overridevirtual

◆ IOHandlerComplete()

◆ IOHandlerFixIndentation()

int REPL::IOHandlerFixIndentation ( IOHandler & io_handler,
const StringList & lines,
int cursor_position )
overridevirtual

Called when a new line is created or one of an identified set of indentation characters is typed.

This function determines how much indentation should be added or removed to match the recommended amount for the final line.

Parameters
[in]io_handlerThe IOHandler that responsible for input.
[in]linesThe current input up to the line to be corrected. Lines following the line containing the cursor are not included.
[in]cursor_positionThe number of characters preceding the cursor on the final line at the time.
Returns
Returns an integer describing the number of spaces needed to correct the indentation level. Positive values indicate that spaces should be added, while negative values represent spaces that should be removed.

Reimplemented from lldb_private::IOHandlerDelegate.

Definition at line 168 of file REPL.cpp.

References CalculateActualIndentation(), lldb_private::IOHandler::GetDebugger(), GetDesiredIndentation(), lldb_private::StringList::GetSize(), lldb_private::Debugger::GetTabSize(), LLDB_INVALID_OFFSET, and m_enable_auto_indent.

◆ IOHandlerGetCommandPrefix()

const char * REPL::IOHandlerGetCommandPrefix ( )
overridevirtual

Reimplemented from lldb_private::IOHandlerDelegate.

Definition at line 127 of file REPL.cpp.

◆ IOHandlerGetControlSequence()

llvm::StringRef REPL::IOHandlerGetControlSequence ( char ch)
overridevirtual

Reimplemented from lldb_private::IOHandlerDelegate.

Definition at line 120 of file REPL.cpp.

◆ IOHandlerGetFixIndentationCharacters()

const char * REPL::IOHandlerGetFixIndentationCharacters ( )
overridevirtual

Reimplemented from lldb_private::IOHandlerDelegate.

Definition at line 116 of file REPL.cpp.

References GetAutoIndentCharacters(), and m_enable_auto_indent.

◆ IOHandlerGetHelpPrologue()

const char * REPL::IOHandlerGetHelpPrologue ( )
overridevirtual

Reimplemented from lldb_private::IOHandlerDelegate.

Definition at line 129 of file REPL.cpp.

◆ IOHandlerInputComplete()

void REPL::IOHandlerInputComplete ( IOHandler & io_handler,
std::string & data )
overridevirtual

Called when a line or lines have been retrieved.

This function can handle the current line and possibly call IOHandler::SetIsDone(true) when the IO handler is done like when "quit" is entered as a command, of when an empty line is received. It is up to the delegate to determine when a line should cause a IOHandler to exit.

Implements lldb_private::IOHandlerDelegate.

Definition at line 221 of file REPL.cpp.

References ANSI_CTRL_BOLD, ANSI_CTRL_NORMAL, ANSI_ESCAPE1, ANSI_FG_COLOR_RED, lldb_private::Debugger::CheckTopIOHandlerTypes(), lldb_private::IOHandler::CommandInterpreter, DoNoSelectMostRelevantFrame, lldb::eExpressionCompleted, lldb::eExpressionDiscarded, lldb::eExpressionHitBreakpoint, lldb::eExpressionInterrupted, lldb::eExpressionParseError, lldb::eExpressionResultUnavailable, lldb::eExpressionSetupError, lldb::eExpressionStoppedForDebug, lldb::eExpressionThreadVanished, lldb::eExpressionTimedOut, lldb::eFormatVoid, lldb_private::eLazyBoolNo, lldb_private::File::eOpenOptionCanCreate, lldb_private::File::eOpenOptionTruncate, lldb_private::File::eOpenOptionWriteOnly, lldb::eReturnStatusQuit, error(), lldb_private::UserExpression::Evaluate(), lldb_private::Debugger::GetCommandInterpreter(), lldb_private::IOHandler::GetErrorStreamFileSP(), lldb_private::CommandInterpreter::GetIOHandler(), GetLanguage(), lldb_private::Debugger::GetNotifyVoid(), lldb_private::IOHandler::GetOutputStreamFileSP(), lldb_private::Debugger::GetPrintDecls(), lldb_private::ExecutionContext::GetProcessSP(), lldb_private::CommandInterpreter::GetPromptOnQuit(), lldb_private::ExpressionVariableList::GetSize(), lldb_private::CommandInterpreter::GetSpaceReplPrompts(), lldb_private::CommandReturnObject::GetStatus(), lldb_private::ExecutionContext::GetThreadPtr(), lldb_private::Debugger::GetUseColor(), lldb_private::ExpressionVariableList::GetVariableAtIndex(), lldb_private::CommandInterpreter::HandleCommand(), lldb_private::FileSystem::Instance(), lldb_private::UserExpression::kNoResult, m_code, m_dedicated_repl_mode, m_expr_options, m_format_options, m_repl_source_path, m_target, m_varobj_options, OnExpressionEvaluated(), lldb_private::FileSystem::Open(), PrintOneVariable(), ReadCode(), lldb_private::IOHandler::REPL, lldb_private::Debugger::RunIOHandlerAsync(), lldb_private::EvaluateExpressionOptions::SetCoerceToId(), lldb_private::EvaluateExpressionOptions::SetColorizeErrors(), lldb_private::ExecutionContext::SetFrameSP(), lldb_private::EvaluateExpressionOptions::SetGenerateDebugInfo(), lldb_private::CommandReturnObject::SetImmediateErrorStream(), lldb_private::CommandReturnObject::SetImmediateOutputStream(), lldb_private::IOHandler::SetIsDone(), lldb_private::EvaluateExpressionOptions::SetKeepInMemory(), lldb_private::EvaluateExpressionOptions::SetLanguage(), lldb_private::EvaluateExpressionOptions::SetPoundLine(), lldb_private::CommandInterpreter::SetPromptOnQuit(), lldb_private::EvaluateExpressionOptions::SetREPLEnabled(), and lldb_private::EvaluateExpressionOptions::SetUseDynamic().

◆ IOHandlerInputInterrupted()

void REPL::IOHandlerInputInterrupted ( IOHandler & io_handler,
std::string & line )
overridevirtual

Reimplemented from lldb_private::IOHandlerDelegate.

Definition at line 113 of file REPL.cpp.

◆ IOHandlerInterrupt()

bool REPL::IOHandlerInterrupt ( IOHandler & io_handler)
overridevirtual

Reimplemented from lldb_private::IOHandlerDelegate.

Definition at line 111 of file REPL.cpp.

◆ IOHandlerIsInputComplete()

bool REPL::IOHandlerIsInputComplete ( IOHandler & io_handler,
StringList & lines )
overridevirtual

Called to determine whether typing enter after the last line in lines should end input.

This function will not be called on IOHandler objects that are getting single lines.

Parameters
[in]io_handlerThe IOHandler that responsible for updating the lines.
[in]linesThe current multi-line content. May be altered to provide alternative input when complete.
Returns
Return an boolean to indicate whether input is complete, true indicates that no additional input is necessary, while false indicates that more input is required.

Reimplemented from lldb_private::IOHandlerDelegate.

Definition at line 141 of file REPL.cpp.

References lldb_private::StringList::CopyList(), lldb_private::StringList::GetSize(), lldb_private::StringList::GetStringAtIndex(), and SourceIsComplete().

◆ OnExpressionEvaluated()

virtual llvm::Error lldb_private::REPL::OnExpressionEvaluated ( const ExecutionContext & exe_ctx,
llvm::StringRef code,
const EvaluateExpressionOptions & expr_options,
lldb::ExpressionResults execution_results,
const lldb::ValueObjectSP & result_valobj_sp,
const Status & error )
inlineprotectedvirtual

Method that can be optionally overriden by subclasses to get notified whenever an expression has been evaluated.

The params of this method include the inputs and outputs of the expression evaluation.

Note: meta commands that start with : are not covered by this method.

Returns
An Error object that, if it is a failure, aborts the regular REPL expression result handling.

Definition at line 120 of file REPL.h.

References error().

Referenced by IOHandlerInputComplete().

◆ PrintOneVariable()

virtual bool lldb_private::REPL::PrintOneVariable ( Debugger & debugger,
lldb::StreamFileSP & output_sp,
lldb::ValueObjectSP & valobj_sp,
ExpressionVariable * var = nullptr )
protectedpure virtual

Referenced by IOHandlerInputComplete().

◆ RunLoop()

◆ SetCompilerOptions()

void lldb_private::REPL::SetCompilerOptions ( const char * options)
inline

Definition at line 72 of file REPL.h.

References m_compiler_options.

◆ SetEvaluateOptions()

void lldb_private::REPL::SetEvaluateOptions ( const EvaluateExpressionOptions & options)
inline

Definition at line 68 of file REPL.h.

References m_expr_options.

◆ SetFormatOptions()

void lldb_private::REPL::SetFormatOptions ( const OptionGroupFormat & options)
inline

Definition at line 59 of file REPL.h.

References m_format_options.

◆ SetValueObjectDisplayOptions()

void lldb_private::REPL::SetValueObjectDisplayOptions ( const OptionGroupValueObjectDisplay & options)
inline

Definition at line 64 of file REPL.h.

References m_varobj_options.

◆ SourceIsComplete()

virtual bool lldb_private::REPL::SourceIsComplete ( const std::string & source)
protectedpure virtual

Member Data Documentation

◆ ID

char REPL::ID
static

LLVM RTTI support.

Definition at line 26 of file REPL.h.

◆ m_code

StringList lldb_private::REPL::m_code
protected

Definition at line 167 of file REPL.h.

Referenced by IOHandlerComplete(), and IOHandlerInputComplete().

◆ m_compiler_options

std::string lldb_private::REPL::m_compiler_options
protected

Definition at line 157 of file REPL.h.

Referenced by SetCompilerOptions().

◆ m_current_indent_level

uint32_t lldb_private::REPL::m_current_indent_level = 0
protected

Definition at line 162 of file REPL.h.

◆ m_current_indent_str

std::string lldb_private::REPL::m_current_indent_str
protected

Definition at line 161 of file REPL.h.

◆ m_dedicated_repl_mode

bool lldb_private::REPL::m_dedicated_repl_mode = false
protected

Definition at line 165 of file REPL.h.

Referenced by IOHandlerInputComplete(), and RunLoop().

◆ m_enable_auto_indent

bool lldb_private::REPL::m_enable_auto_indent = true
protected

◆ m_expr_options

EvaluateExpressionOptions lldb_private::REPL::m_expr_options
protected

Definition at line 156 of file REPL.h.

Referenced by IOHandlerInputComplete(), and SetEvaluateOptions().

◆ m_format_options

OptionGroupFormat lldb_private::REPL::m_format_options = OptionGroupFormat(lldb::eFormatDefault)
protected

Definition at line 154 of file REPL.h.

Referenced by IOHandlerInputComplete(), REPL(), and SetFormatOptions().

◆ m_indent_str

std::string lldb_private::REPL::m_indent_str
protected

Definition at line 160 of file REPL.h.

Referenced by GetIOHandler(), and IOHandlerComplete().

◆ m_io_handler_sp

lldb::IOHandlerSP lldb_private::REPL::m_io_handler_sp
protected

Definition at line 170 of file REPL.h.

Referenced by GetIOHandler().

◆ m_repl_source_path

std::string lldb_private::REPL::m_repl_source_path
protected

Definition at line 164 of file REPL.h.

Referenced by GetSourcePath(), IOHandlerInputComplete(), and RunLoop().

◆ m_target

Target& lldb_private::REPL::m_target
protected

◆ m_varobj_options

OptionGroupValueObjectDisplay lldb_private::REPL::m_varobj_options
protected

Definition at line 155 of file REPL.h.

Referenced by IOHandlerInputComplete(), REPL(), and SetValueObjectDisplayOptions().


The documentation for this class was generated from the following files: