@@ -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,54 @@ 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+ return_name = "(Return Value)"
674+ verify_locals = {
675+ return_name : {"equals" : {"type" : "int" , "value" : "300" }},
676+ "argc" : {},
677+ "argv" : {},
678+ "pt" : {},
679+ "x" : {},
680+ "return_result" : {"equals" : {"type" : "int" }},
681+ }
682+
683+ function_name = "test_return_variable"
684+ breakpoint_ids = self .set_function_breakpoints ([function_name ])
685+
686+ self .assertEqual (len (breakpoint_ids ), 1 )
687+ self .continue_to_breakpoints (breakpoint_ids )
688+
689+ threads = self .dap_server .get_threads ()
690+ for thread in threads :
691+ if thread .get ("reason" ) == "breakpoint" :
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+
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+
711+ self .verify_variables (verify_locals , local_variables , varref_dict )
712+ break
713+
666714 @skipIfWindows
667715 def test_indexedVariables (self ):
668716 self .do_test_indexedVariables (enableSyntheticChildDebugging = False )
0 commit comments