Skip to content

Commit 4453e42

Browse files
committed
[lldb-dap] Add: Show return values
Explicitly check for the return value variable
1 parent 528bb54 commit 4453e42

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,9 @@ def test_return_variables(self):
670670
program = self.getBuildArtifact("a.out")
671671
self.build_and_launch(program)
672672

673+
return_name = "(Return Value)"
673674
verify_locals = {
674-
"(Return Value)": {"equals": {"type": "int", "value": "300"}},
675+
return_name: {"equals": {"type": "int", "value": "300"}},
675676
"argc": {},
676677
"argv": {},
677678
"pt": {},
@@ -694,6 +695,19 @@ def test_return_variables(self):
694695

695696
local_variables = self.dap_server.get_local_variables()
696697
varref_dict = {}
698+
699+
# `verify_variable` function only checks if the local variables
700+
# are in the `verify_dict` passed this will cause this test to pass
701+
# even if there is no return value.
702+
local_variable_names = [
703+
variable["name"] for variable in local_variables
704+
]
705+
self.assertIn(
706+
return_name,
707+
local_variable_names,
708+
"return variable is not in local variables",
709+
)
710+
697711
self.verify_variables(verify_locals, local_variables, varref_dict)
698712
break
699713

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,29 @@ void VariablesRequestHandler::operator()(
164164
variable_name_counts[GetNonNullVariableName(variable)]++;
165165
}
166166

167+
// Show return value if there is any ( in the local top frame )
168+
if (variablesReference == VARREF_LOCALS) {
169+
auto process = dap.target.GetProcess();
170+
auto selected_thread = process.GetSelectedThread();
171+
lldb::SBValue stop_return_value = selected_thread.GetStopReturnValue();
172+
173+
if (stop_return_value.IsValid() &&
174+
(selected_thread.GetSelectedFrame().GetFrameID() == 0)) {
175+
auto renamed_return_value = stop_return_value.Clone("(Return Value)");
176+
int64_t return_var_ref = 0;
177+
178+
if (stop_return_value.MightHaveChildren() ||
179+
stop_return_value.IsSynthetic()) {
180+
return_var_ref = dap.variables.InsertVariable(stop_return_value,
181+
/*is_permanent=*/false);
182+
}
183+
variables.emplace_back(
184+
CreateVariable(renamed_return_value, return_var_ref, hex,
185+
dap.enable_auto_variable_summaries,
186+
dap.enable_synthetic_child_debugging, false));
187+
}
188+
}
189+
167190
// Now we construct the result with unique display variable names
168191
for (auto i = start_idx; i < end_idx; ++i) {
169192
lldb::SBValue variable = top_scope->GetValueAtIndex(i);

0 commit comments

Comments
 (0)