Skip to content

[lldb-dap] Improving 'variables' hover requests. #146773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test lldb-dap disconnect request
"""


import dap_server
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lldb/test/API/tools/lldb-dap/locations/TestDAP_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
2 changes: 1 addition & 1 deletion lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading