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 1 commit
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
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
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 this isn't a REPL context, trim leading pointer/reference characters
// to ensure we return the actual value of the expression.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this also trigger in way too many other contexts? E.g., also in the watch panel? I think in the watch panel a *x should actually dereference x

Copy link
Collaborator

@jimingham jimingham Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since people have to voluntarily put something in a watch panel, then in that case we should even run it as an expression. If somebody actually puts i++ in a watch window, presumably they meant for it to increment every time they stepped.
We had a silly bug in gdbtk way back in the day where we if you moused over a selection we would run the selection as an expression. But lots of people seem to select expressions so that they can focus on just the part they selected. As you can imagine, that went poorly.
The main thing - for me - is to always have running expressions be a distinct gesture.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we shouldn't run evaluate expressions like i++ in a watch context.

I can fix that as well in this change as well. We're trying the expression with frame.EvaluateExpression if its not 'hover' but that should really be only used if 'context' == 'repl'.

I also updated this to only trim leading &* for 'hover' specifically since watching *x should be supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually removed that part of from this PR and I'll move it into its own PR since it has some other implications.

// 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.
Expand Down
Loading