brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.6 KiB · c61bdc9 Raw
129 lines · python
1"""2Tests imported namespaces in C++.3"""4import lldb5from lldbsuite.test.decorators import *6from lldbsuite.test.lldbtest import *7from lldbsuite.test import lldbutil8 9 10class TestCppNsImport(TestBase):11    def test_with_run_command(self):12        """Tests imported namespaces in C++."""13        self.build()14 15        # Get main source file16        src_file = os.path.join(self.getSourceDir(), "main.cpp")17        src_file_spec = lldb.SBFileSpec(src_file)18        self.assertTrue(src_file_spec.IsValid(), "Main source file")19 20        # Get the path of the executable21        exe_path = self.getBuildArtifact("a.out")22 23        # Load the executable24        target = self.dbg.CreateTarget(exe_path)25        self.assertTrue(target.IsValid(), VALID_TARGET)26 27        # Break on main function28        break_0 = target.BreakpointCreateBySourceRegex("// break 0", src_file_spec)29        self.assertTrue(30            break_0.IsValid() and break_0.GetNumLocations() >= 1, VALID_BREAKPOINT31        )32        break_1 = target.BreakpointCreateBySourceRegex("// break 1", src_file_spec)33        self.assertTrue(34            break_1.IsValid() and break_1.GetNumLocations() >= 1, VALID_BREAKPOINT35        )36 37        # Launch the process38        args = None39        env = None40        process = target.LaunchSimple(args, env, self.get_process_working_directory())41        self.assertTrue(process.IsValid(), PROCESS_IS_VALID)42 43        # Get the thread of the process44        self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)45        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)46 47        # Get current fream of the thread at the breakpoint48        frame = thread.GetSelectedFrame()49 50        # Test imported namespaces51        test_result = frame.EvaluateExpression("n")52        self.assertTrue(53            test_result.IsValid() and test_result.GetValueAsSigned() == 1, "n = 1"54        )55 56        test_result = frame.EvaluateExpression("N::n")57        self.assertTrue(58            test_result.IsValid() and test_result.GetValueAsSigned() == 1, "N::n = 1"59        )60 61        test_result = frame.EvaluateExpression("nested")62        self.assertTrue(63            test_result.IsValid() and test_result.GetValueAsSigned() == 3, "nested = 3"64        )65 66        test_result = frame.EvaluateExpression("anon")67        self.assertTrue(68            test_result.IsValid() and test_result.GetValueAsSigned() == 2, "anon = 2"69        )70 71        test_result = frame.EvaluateExpression("global")72        self.assertTrue(73            test_result.IsValid() and test_result.GetValueAsSigned() == 4, "global = 4"74        )75 76        test_result = frame.EvaluateExpression("fun_var")77        self.assertTrue(78            test_result.IsValid() and test_result.GetValueAsSigned() == 9, "fun_var = 9"79        )80 81        test_result = frame.EvaluateExpression("Fun::fun_var")82        self.assertTrue(83            test_result.IsValid() and test_result.GetValueAsSigned() == 0,84            "Fun::fun_var = 0",85        )86 87        test_result = frame.EvaluateExpression("not_imported")88        self.assertTrue(89            test_result.IsValid() and test_result.GetValueAsSigned() == 35,90            "not_imported = 35",91        )92 93        # Currently there is no way to distinguish between "::imported" and "imported" in ClangExpressionDeclMap so this fails94        # test_result = frame.EvaluateExpression("::imported")95        # self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 89, "::imported = 89")96 97        test_result = frame.EvaluateExpression("Imported::imported")98        self.assertTrue(99            test_result.IsValid() and test_result.GetValueAsSigned() == 99,100            "Imported::imported = 99",101        )102 103        test_result = frame.EvaluateExpression("imported")104        self.assertTrue(105            test_result.IsValid() and test_result.GetValueAsSigned() == 99,106            "imported = 99",107        )108 109        test_result = frame.EvaluateExpression("single")110        self.assertTrue(111            test_result.IsValid() and test_result.GetValueAsSigned() == 3, "single = 3"112        )113 114        # Continue to second breakpoint115        process.Continue()116 117        # Get the thread of the process118        self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)119        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)120 121        # Get current fream of the thread at the breakpoint122        frame = thread.GetSelectedFrame()123 124        # Test function inside namespace125        test_result = frame.EvaluateExpression("fun_var")126        self.assertTrue(127            test_result.IsValid() and test_result.GetValueAsSigned() == 5, "fun_var = 5"128        )129