[Lldb-commits] [lldb] bfb7c99 - [LLDB] Add a hook to notify REPLs that an expression was evaluated

walter erquinigo via lldb-commits lldb-commits at lists.llvm.org
Thu May 4 12:44:51 PDT 2023


Author: walter erquinigo
Date: 2023-05-04T14:44:03-05:00
New Revision: bfb7c99f3aeab09236adf1f684f7144f384c6dd7

URL: https://github.com/llvm/llvm-project/commit/bfb7c99f3aeab09236adf1f684f7144f384c6dd7
DIFF: https://github.com/llvm/llvm-project/commit/bfb7c99f3aeab09236adf1f684f7144f384c6dd7.diff

LOG: [LLDB] Add a hook to notify REPLs that an expression was evaluated

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

Added: 
    

Modified: 
    lldb/include/lldb/Expression/REPL.h
    lldb/source/Expression/REPL.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Expression/REPL.h b/lldb/include/lldb/Expression/REPL.h
index a0df53eb9b4c1..edfe7c0b341da 100644
--- a/lldb/include/lldb/Expression/REPL.h
+++ b/lldb/include/lldb/Expression/REPL.h
@@ -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.

diff  --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp
index 5b1937245d967..31c9978b24226 100644
--- a/lldb/source/Expression/REPL.cpp
+++ b/lldb/source/Expression/REPL.cpp
@@ -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) {


        


More information about the lldb-commits mailing list