Skip to content

Commit 2674e5a

Browse files
committed
[lldb-dap] Improving 'variables' hover requests.
This partially fixes #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"`.
1 parent 00e071d commit 2674e5a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_readMemory(self):
9292
)
9393
self.continue_to_next_stop()
9494

95-
ptr_deref = self.dap_server.request_evaluate("*rawptr")["body"]
95+
ptr_deref = self.dap_server.request_evaluate("*rawptr", context="repl")["body"]
9696
memref = ptr_deref["memoryReference"]
9797

9898
# We can read the complete string

lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,17 @@ void EvaluateRequestHandler::operator()(
181181
expression = dap.last_nonempty_var_expression;
182182
else
183183
dap.last_nonempty_var_expression = expression;
184+
} else {
185+
// If this isn't a REPL context, trim leading pointer/reference characters
186+
// to ensure we return the actual value of the expression.
187+
// This can come up if you hover over a pointer or reference declaration
188+
// like 'MyType *foo;' or `void fn(std::string &arg)`, which results in
189+
// the hover request sending '*foo' or `&arg`. When we're not in the REPL,
190+
// we should trim these characters to get to the actual variable, which
191+
// should have the proper type encoded by the compiler.
192+
expression = llvm::StringRef(expression).ltrim("*&").str();
184193
}
194+
185195
// Always try to get the answer from the local variables if possible. If
186196
// this fails, then if the context is not "hover", actually evaluate an
187197
// expression using the expression parser.

0 commit comments

Comments
 (0)