Skip to content

Commit c5dda32

Browse files
committed
[lldb-dap] Add Tests: Show children for return values
1 parent 038731c commit c5dda32

File tree

4 files changed

+122
-11
lines changed

4 files changed

+122
-11
lines changed

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

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ def do_test_scopes_variables_setVariable_evaluate(
341341

342342
verify_locals["argc"]["equals"]["value"] = "123"
343343
verify_locals["pt"]["children"]["x"]["equals"]["value"] = "111"
344-
verify_locals["x @ main.cpp:17"] = {"equals": {"type": "int", "value": "89"}}
345-
verify_locals["x @ main.cpp:19"] = {"equals": {"type": "int", "value": "42"}}
346-
verify_locals["x @ main.cpp:21"] = {"equals": {"type": "int", "value": "72"}}
344+
verify_locals["x @ main.cpp:19"] = {"equals": {"type": "int", "value": "89"}}
345+
verify_locals["x @ main.cpp:21"] = {"equals": {"type": "int", "value": "42"}}
346+
verify_locals["x @ main.cpp:23"] = {"equals": {"type": "int", "value": "72"}}
347347

348348
self.verify_variables(verify_locals, self.dap_server.get_local_variables())
349349

@@ -353,32 +353,32 @@ def do_test_scopes_variables_setVariable_evaluate(
353353
self.dap_server.request_setVariable(1, "x @ main.cpp:0", 9)["success"]
354354
)
355355

356-
self.assertTrue(
357-
self.dap_server.request_setVariable(1, "x @ main.cpp:17", 17)["success"]
358-
)
359356
self.assertTrue(
360357
self.dap_server.request_setVariable(1, "x @ main.cpp:19", 19)["success"]
361358
)
362359
self.assertTrue(
363360
self.dap_server.request_setVariable(1, "x @ main.cpp:21", 21)["success"]
364361
)
362+
self.assertTrue(
363+
self.dap_server.request_setVariable(1, "x @ main.cpp:23", 23)["success"]
364+
)
365365

366366
# The following should have no effect
367367
self.assertFalse(
368-
self.dap_server.request_setVariable(1, "x @ main.cpp:21", "invalid")[
368+
self.dap_server.request_setVariable(1, "x @ main.cpp:23", "invalid")[
369369
"success"
370370
]
371371
)
372372

373-
verify_locals["x @ main.cpp:17"]["equals"]["value"] = "17"
374373
verify_locals["x @ main.cpp:19"]["equals"]["value"] = "19"
375374
verify_locals["x @ main.cpp:21"]["equals"]["value"] = "21"
375+
verify_locals["x @ main.cpp:23"]["equals"]["value"] = "23"
376376

377377
self.verify_variables(verify_locals, self.dap_server.get_local_variables())
378378

379379
# The plain x variable shold refer to the innermost x
380380
self.assertTrue(self.dap_server.request_setVariable(1, "x", 22)["success"])
381-
verify_locals["x @ main.cpp:21"]["equals"]["value"] = "22"
381+
verify_locals["x @ main.cpp:23"]["equals"]["value"] = "22"
382382

383383
self.verify_variables(verify_locals, self.dap_server.get_local_variables())
384384

@@ -394,10 +394,10 @@ def do_test_scopes_variables_setVariable_evaluate(
394394
locals = self.dap_server.get_local_variables()
395395
names = [var["name"] for var in locals]
396396
# The first shadowed x shouldn't have a suffix anymore
397-
verify_locals["x"] = {"equals": {"type": "int", "value": "17"}}
398-
self.assertNotIn("x @ main.cpp:17", names)
397+
verify_locals["x"] = {"equals": {"type": "int", "value": "19"}}
399398
self.assertNotIn("x @ main.cpp:19", names)
400399
self.assertNotIn("x @ main.cpp:21", names)
400+
self.assertNotIn("x @ main.cpp:23", names)
401401

402402
self.verify_variables(verify_locals, locals)
403403

@@ -663,6 +663,41 @@ def do_test_indexedVariables(self, enableSyntheticChildDebugging: bool):
663663
]["variables"]
664664
self.verify_variables(verify_children, children)
665665

666+
def test_return_variables(self):
667+
"""
668+
Test the stepping out of a function with return value show the variable correctly.
669+
"""
670+
program = self.getBuildArtifact("a.out")
671+
self.build_and_launch(program)
672+
673+
verify_locals = {
674+
"(Return Value)": {"equals": {"type": "int", "value": "300"}},
675+
"argc": {},
676+
"argv": {},
677+
"pt": {},
678+
"x": {},
679+
"return_result": {"equals": {"type": "int"}},
680+
}
681+
682+
function_name = "test_return_variable"
683+
breakpoint_ids = self.set_function_breakpoints([function_name])
684+
685+
self.assertEqual(len(breakpoint_ids), 1)
686+
self.continue_to_breakpoints(breakpoint_ids)
687+
688+
threads = self.dap_server.get_threads()
689+
for thread in threads:
690+
if thread.get("reason") == "breakpoint":
691+
# We have a thread that
692+
thread_id = thread["id"]
693+
694+
self.stepOut(threadId=thread_id)
695+
696+
local_variables = self.dap_server.get_local_variables()
697+
varref_dict = {}
698+
self.verify_variables(verify_locals, local_variables, varref_dict)
699+
break
700+
666701
@skipIfWindows
667702
def test_indexedVariables(self):
668703
self.do_test_indexedVariables(enableSyntheticChildDebugging=False)

lldb/test/API/tools/lldb-dap/variables/children/TestDAP_variables_children.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,58 @@ def test_get_num_children(self):
4040
"`script formatter.num_children_calls", context="repl"
4141
)["body"]["result"],
4242
)
43+
44+
def test_return_variable_with_children(self):
45+
"""
46+
Test the stepping out of a function with return value show the children correctly
47+
"""
48+
program = self.getBuildArtifact("a.out")
49+
self.build_and_launch(program)
50+
51+
function_name = "test_return_variable_with_children"
52+
breakpoint_ids = self.set_function_breakpoints([function_name])
53+
54+
self.assertEqual(len(breakpoint_ids), 1)
55+
self.continue_to_breakpoints(breakpoint_ids)
56+
57+
threads = self.dap_server.get_threads()
58+
for thread in threads:
59+
if thread.get("reason") == "breakpoint":
60+
thread_id = thread.get("id")
61+
self.assertIsNot(thread_id, None)
62+
63+
self.stepOut(threadId=thread_id)
64+
65+
local_variables = self.dap_server.get_local_variables()
66+
67+
# verify has return variable as local
68+
result_variable = list(
69+
filter(
70+
lambda val: val.get("name") == "(Return Value)", local_variables
71+
)
72+
)
73+
self.assertEqual(len(result_variable), 1)
74+
result_variable = result_variable[0]
75+
76+
result_var_ref = result_variable.get("variablesReference")
77+
self.assertIsNot(result_var_ref, None, "There is no result value")
78+
79+
result_value = self.dap_server.request_variables(result_var_ref)
80+
result_children = result_value["body"]["variables"]
81+
self.assertNotEqual(
82+
result_children, None, "The result does not have children"
83+
)
84+
85+
verify_children = {"buffer": '"hello world!"', "x": "10", "y": "20"}
86+
for child in result_children:
87+
actual_name = child["name"]
88+
actual_value = child["value"]
89+
verify_value = verify_children.get(actual_name)
90+
self.assertNotEqual(verify_value, None)
91+
self.assertEqual(
92+
actual_value,
93+
verify_value,
94+
"Expected child value does not match",
95+
)
96+
97+
break
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
struct Indexed {};
22
struct NotIndexed {};
33

4+
#define BUFFER_SIZE 16
5+
struct NonPrimitive {
6+
char buffer[BUFFER_SIZE];
7+
int x;
8+
long y;
9+
};
10+
11+
NonPrimitive test_return_variable_with_children() {
12+
return NonPrimitive{"hello world!", 10, 20};
13+
}
14+
415
int main() {
516
Indexed indexed;
617
NotIndexed not_indexed;
18+
NonPrimitive non_primitive_result = test_return_variable_with_children();
719
return 0; // break here
820
}

lldb/test/API/tools/lldb-dap/variables/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ struct PointType {
99
int g_global = 123;
1010
static int s_global = 234;
1111
int test_indexedVariables();
12+
int test_return_variable();
13+
1214
int main(int argc, char const *argv[]) {
1315
static float s_local = 2.25;
1416
PointType pt = {11, 22, {0}};
@@ -22,6 +24,9 @@ int main(int argc, char const *argv[]) {
2224
s_global = x; // breakpoint 2
2325
}
2426
}
27+
{
28+
int return_result = test_return_variable();
29+
}
2530
return test_indexedVariables(); // breakpoint 3
2631
}
2732

@@ -34,3 +39,7 @@ int test_indexedVariables() {
3439
large_vector.assign(200, 0);
3540
return 0; // breakpoint 4
3641
}
42+
43+
int test_return_variable() {
44+
return 300; // breakpoint 5
45+
}

0 commit comments

Comments
 (0)