diff --git a/lldb/test/API/tools/lldb-dap/disconnect/TestDAP_disconnect.py b/lldb/test/API/tools/lldb-dap/disconnect/TestDAP_disconnect.py index 09e3f62f0eead..952cbe57901c4 100644 --- a/lldb/test/API/tools/lldb-dap/disconnect/TestDAP_disconnect.py +++ b/lldb/test/API/tools/lldb-dap/disconnect/TestDAP_disconnect.py @@ -2,7 +2,6 @@ Test lldb-dap disconnect request """ - import dap_server from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * @@ -71,7 +70,9 @@ def test_attach(self): lldbutil.wait_for_file_on_target(self, sync_file_path) self.attach(pid=self.process.pid, disconnectAutomatically=False) - response = self.dap_server.request_evaluate("wait_for_attach = false;") + response = self.dap_server.request_evaluate( + "`expr -- wait_for_attach = false;", context="repl" + ) self.assertTrue(response["success"]) # verify we haven't produced the side effect file yet diff --git a/lldb/test/API/tools/lldb-dap/locations/TestDAP_locations.py b/lldb/test/API/tools/lldb-dap/locations/TestDAP_locations.py index 45f836a2fa3c3..1355f02af7341 100644 --- a/lldb/test/API/tools/lldb-dap/locations/TestDAP_locations.py +++ b/lldb/test/API/tools/lldb-dap/locations/TestDAP_locations.py @@ -76,6 +76,6 @@ def test_locations(self): self.assertEqual(val_loc_func_ref["body"]["line"], 3) # `evaluate` responses for function pointers also have locations associated - eval_res = self.dap_server.request_evaluate("greet") - self.assertTrue(eval_res["success"]) + eval_res = self.dap_server.request_evaluate("greet", context="repl") + self.assertTrue(eval_res["success"], f"evaluate failed: {eval_res}") self.assertIn("valueLocationReference", eval_res["body"].keys()) 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/test/API/tools/lldb-dap/variables/TestDAP_variables.py b/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py index 340be0b39010d..a9574e78f10f2 100644 --- a/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py +++ b/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py @@ -738,7 +738,7 @@ def test_indexedVariables_with_raw_child_for_synthetics(self): self.do_test_indexedVariables(enableSyntheticChildDebugging=True) @skipIfWindows - @skipIfAsan # FIXME this fails with a non-asan issue on green dragon. + @skipIfAsan # FIXME this fails with a non-asan issue on green dragon. def test_registers(self): """ Test that registers whose byte size is the size of a pointer on diff --git a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp index e1556846dff19..90cd795b107e9 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 (context == "hover") { + // If we're in the hover 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`. 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.