Skip to content

Commit 3da6fd0

Browse files
committed
Only trim leading '&*' characters on context='hover' and ensure we only evaluate expressions when we're in the repl specifically.
1 parent 2674e5a commit 3da6fd0

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

lldb/test/API/tools/lldb-dap/disconnect/TestDAP_disconnect.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Test lldb-dap disconnect request
33
"""
44

5-
65
import dap_server
76
from lldbsuite.test.decorators import *
87
from lldbsuite.test.lldbtest import *
@@ -71,7 +70,9 @@ def test_attach(self):
7170
lldbutil.wait_for_file_on_target(self, sync_file_path)
7271

7372
self.attach(pid=self.process.pid, disconnectAutomatically=False)
74-
response = self.dap_server.request_evaluate("wait_for_attach = false;")
73+
response = self.dap_server.request_evaluate(
74+
"`expr -- wait_for_attach = false;", context="repl"
75+
)
7576
self.assertTrue(response["success"])
7677

7778
# verify we haven't produced the side effect file yet

lldb/test/API/tools/lldb-dap/locations/TestDAP_locations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ def test_locations(self):
7676
self.assertEqual(val_loc_func_ref["body"]["line"], 3)
7777

7878
# `evaluate` responses for function pointers also have locations associated
79-
eval_res = self.dap_server.request_evaluate("greet")
80-
self.assertTrue(eval_res["success"])
79+
eval_res = self.dap_server.request_evaluate("greet", context="repl")
80+
self.assertTrue(eval_res["success"], f"evaluate failed: {eval_res}")
8181
self.assertIn("valueLocationReference", eval_res["body"].keys())

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,14 @@ 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
184+
} else if (context == "hover") {
185+
// If we're in the hover context trim leading pointer/reference characters
186186
// to ensure we return the actual value of the expression.
187187
// This can come up if you hover over a pointer or reference declaration
188188
// 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.
189+
// the hover request sending '*foo' or `&arg`. Trim these characters to
190+
// get to the actual variable, which should have the proper type encoded
191+
// by the compiler.
192192
expression = llvm::StringRef(expression).ltrim("*&").str();
193193
}
194194

@@ -205,7 +205,10 @@ void EvaluateRequestHandler::operator()(
205205
if (value.GetError().Success() && context == "repl")
206206
value = value.Persist();
207207

208-
if (value.GetError().Fail() && context != "hover")
208+
// Only the repl should evaluate expressions, which can mutate application
209+
// state. Other contexts are used for observing debuggee state only, not
210+
// mutating state.
211+
if (value.GetError().Fail() && context == "repl")
209212
value = frame.EvaluateExpression(expression.data());
210213

211214
if (value.GetError().Fail()) {

0 commit comments

Comments
 (0)