brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · 45f836a Raw
82 lines · python
1"""2Test lldb-dap locations request3"""4 5 6import dap_server7from lldbsuite.test.decorators import *8from lldbsuite.test.lldbtest import *9from lldbsuite.test import lldbutil10import lldbdap_testcase11import os12 13 14class TestDAP_locations(lldbdap_testcase.DAPTestCaseBase):15    @skipIfWindows16    def test_locations(self):17        """18        Tests the 'locations' request.19        """20        program = self.getBuildArtifact("a.out")21        self.build_and_launch(program)22        source = "main.cpp"23        self.source_path = os.path.join(os.getcwd(), source)24        self.set_source_breakpoints(25            source,26            [line_number(source, "break here")],27        )28        self.continue_to_next_stop()29 30        locals = {l["name"]: l for l in self.dap_server.get_local_variables()}31 32        # var1 has a declarationLocation but no valueLocation33        self.assertIn("declarationLocationReference", locals["var1"].keys())34        self.assertNotIn("valueLocationReference", locals["var1"].keys())35        loc_var1 = self.dap_server.request_locations(36            locals["var1"]["declarationLocationReference"]37        )38        self.assertTrue(loc_var1["success"])39        self.assertTrue(loc_var1["body"]["source"]["path"].endswith("main.cpp"))40        self.assertEqual(loc_var1["body"]["line"], 6)41 42        # func_ptr has both a declaration and a valueLocation43        self.assertIn("declarationLocationReference", locals["func_ptr"].keys())44        self.assertIn("valueLocationReference", locals["func_ptr"].keys())45        decl_loc_func_ptr = self.dap_server.request_locations(46            locals["func_ptr"]["declarationLocationReference"]47        )48        self.assertTrue(decl_loc_func_ptr["success"])49        self.assertTrue(50            decl_loc_func_ptr["body"]["source"]["path"].endswith("main.cpp")51        )52        self.assertEqual(decl_loc_func_ptr["body"]["line"], 7)53        val_loc_func_ptr = self.dap_server.request_locations(54            locals["func_ptr"]["valueLocationReference"]55        )56        self.assertTrue(val_loc_func_ptr["success"])57        self.assertTrue(val_loc_func_ptr["body"]["source"]["path"].endswith("main.cpp"))58        self.assertEqual(val_loc_func_ptr["body"]["line"], 3)59 60        # func_ref has both a declaration and a valueLocation61        self.assertIn("declarationLocationReference", locals["func_ref"].keys())62        self.assertIn("valueLocationReference", locals["func_ref"].keys())63        decl_loc_func_ref = self.dap_server.request_locations(64            locals["func_ref"]["declarationLocationReference"]65        )66        self.assertTrue(decl_loc_func_ref["success"])67        self.assertTrue(68            decl_loc_func_ref["body"]["source"]["path"].endswith("main.cpp")69        )70        self.assertEqual(decl_loc_func_ref["body"]["line"], 8)71        val_loc_func_ref = self.dap_server.request_locations(72            locals["func_ref"]["valueLocationReference"]73        )74        self.assertTrue(val_loc_func_ref["success"])75        self.assertTrue(val_loc_func_ref["body"]["source"]["path"].endswith("main.cpp"))76        self.assertEqual(val_loc_func_ref["body"]["line"], 3)77 78        # `evaluate` responses for function pointers also have locations associated79        eval_res = self.dap_server.request_evaluate("greet")80        self.assertTrue(eval_res["success"])81        self.assertIn("valueLocationReference", eval_res["body"].keys())82