[Lldb-commits] [lldb] [lldb-dap] Add feature to remember last non-empty expression. (PR #107485)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Sep 5 15:56:07 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: None (cmtice)
<details>
<summary>Changes</summary>
Update lldb-dap so if the user just presses return, which sends an empty expression, it re-evaluates the most recent non-empty expression/command. Also udpated test to test this case.
---
Full diff: https://github.com/llvm/llvm-project/pull/107485.diff
2 Files Affected:
- (modified) lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py (+3)
- (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+8)
``````````diff
diff --git a/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py b/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
index 29548a835c6919..9ed0fc564268a7 100644
--- a/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
+++ b/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
@@ -60,7 +60,10 @@ def run_test_evaluate_expressions(
# Expressions at breakpoint 1, which is in main
self.assertEvaluate("var1", "20")
+ # Empty expression should equate to the previous expression.
+ self.assertEvaluate("", "20")
self.assertEvaluate("var2", "21")
+ self.assertEvaluate("", "21")
self.assertEvaluate("static_int", "42")
self.assertEvaluate("non_static_int", "43")
self.assertEvaluate("struct1.foo", "15")
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index c5c4b09f15622b..a6a701dc2219fa 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -1363,6 +1363,14 @@ void request_evaluate(const llvm::json::Object &request) {
lldb::SBFrame frame = g_dap.GetLLDBFrame(*arguments);
std::string expression = GetString(arguments, "expression").str();
llvm::StringRef context = GetString(arguments, "context");
+ static std::string last_nonempty_expression;
+
+ // Remember the last non-empty expression from the user, and use that if
+ // the current expression is empty (i.e. the user hit plain 'return').
+ if (!expression.empty())
+ last_nonempty_expression = expression;
+ else
+ expression = last_nonempty_expression;
if (context == "repl" && g_dap.DetectExpressionContext(frame, expression) ==
ExpressionContext::Command) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/107485
More information about the lldb-commits
mailing list