[Lldb-commits] [lldb] [lldb-dap] Improving 'variables' hover requests. (PR #146773)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 2 13:39:07 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: John Harrison (ashgti)
<details>
<summary>Changes</summary>
This partially fixes https://github.com/llvm/llvm-project/issues/146559.
When hovering over variables while debugging with lldb-dap we are receiving hover requests that include symbols.
For example, if you have:
```
MyClass *foo;
```
and hover over 'foo', the request will contain the expression `expression="*foo"` and we're evaluating the dereference, so you end up with different hover results vs the variables view.
A more complete solution would be to implement an
[EvaluatableExpressionProvider](https://code.visualstudio.com/api/references/vscode-api#EvaluatableExpressionProvider) in the VS Code extension.
For example, if you have a declaration without any whitespace like
```c
char*foo = "bar";
```
And try to hover over 'foo', the request will be `expression="char*foo"`, which won't evaluate correctly in lldb.
---
Full diff: https://github.com/llvm/llvm-project/pull/146773.diff
2 Files Affected:
- (modified) lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py (+1-1)
- (modified) lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp (+10)
``````````diff
diff --git a/lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py b/lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py
index 55fb4a961e783..30ee7a1631e29 100644
--- a/lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py
+++ b/lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py
@@ -92,7 +92,7 @@ def test_readMemory(self):
)
self.continue_to_next_stop()
- ptr_deref = self.dap_server.request_evaluate("*rawptr")["body"]
+ ptr_deref = self.dap_server.request_evaluate("*rawptr", context="repl")["body"]
memref = ptr_deref["memoryReference"]
# We can read the complete string
diff --git a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
index e1556846dff19..e2161eb999e82 100644
--- a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
@@ -181,7 +181,17 @@ void EvaluateRequestHandler::operator()(
expression = dap.last_nonempty_var_expression;
else
dap.last_nonempty_var_expression = expression;
+ } else {
+ // If this isn't a REPL context, trim leading pointer/reference characters
+ // to ensure we return the actual value of the expression.
+ // This can come up if you hover over a pointer or reference declaration
+ // like 'MyType *foo;' or `void fn(std::string &arg)`, which results in
+ // the hover request sending '*foo' or `&arg`. When we're not in the REPL,
+ // we should trim these characters to get to the actual variable, which
+ // should have the proper type encoded by the compiler.
+ expression = llvm::StringRef(expression).ltrim("*&").str();
}
+
// Always try to get the answer from the local variables if possible. If
// this fails, then if the context is not "hover", actually evaluate an
// expression using the expression parser.
``````````
</details>
https://github.com/llvm/llvm-project/pull/146773
More information about the lldb-commits
mailing list