Skip to content

Commit

Permalink
[LLDB] Add a hook to notify REPLs that an expression was evaluated
Browse files Browse the repository at this point in the history
REPL implementations don't have an easy way to know that an expression has been evaluated, so I'm adding a simple function for that. In the future we can add another hook for meta commands.

Differential Revision: https://reviews.llvm.org/D149719
  • Loading branch information
walter-erquinigo committed May 4, 2023
1 parent db5f745 commit bfb7c99
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
18 changes: 18 additions & 0 deletions lldb/include/lldb/Expression/REPL.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ class REPL : public IOHandlerDelegate {
CompletionRequest &request) override;

protected:
/// 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.
///
/// \return
/// An \a Error object that, if it is a failure, aborts the regular
/// REPL expression result handling.
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) {
return llvm::Error::success();
}

static int CalculateActualIndentation(const StringList &lines);

// Subclasses should override these functions to implement a functional REPL.
Expand Down
8 changes: 5 additions & 3 deletions lldb/source/Expression/REPL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,11 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
expr_prefix, result_valobj_sp, error,
nullptr); // fixed expression

// CommandInterpreter &ci = debugger.GetCommandInterpreter();

if (process_sp && process_sp->IsAlive()) {
if (llvm::Error err = OnExpressionEvaluated(exe_ctx, code, expr_options,
execution_results,
result_valobj_sp, error)) {
*error_sp << llvm::toString(std::move(err)) << "\n";
} else if (process_sp && process_sp->IsAlive()) {
bool add_to_code = true;
bool handled = false;
if (result_valobj_sp) {
Expand Down

0 comments on commit bfb7c99

Please sign in to comment.