brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · c99daf0 Raw
116 lines · python
1"""2Test that the language option for breakpoints works correctly3parser.4"""5 6 7import lldb8from lldbsuite.test.lldbtest import *9import lldbsuite.test.lldbutil as lldbutil10 11 12class TestBreakpointLanguage(TestBase):13    def check_location_file(self, bp, loc, test_name):14        bp_loc = bp.GetLocationAtIndex(loc)15        addr = bp_loc.GetAddress()16        comp_unit = addr.GetCompileUnit()17        comp_name = comp_unit.GetFileSpec().GetFilename()18        return comp_name == test_name19 20    def test_regex_breakpoint_language(self):21        """Test that the name regex breakpoint commands obey the language filter."""22 23        self.build()24        # Create a target by the debugger.25        exe = self.getBuildArtifact("a.out")26        error = lldb.SBError()27        # Don't read in dependencies so we don't come across false matches that28        # add unwanted breakpoint hits.29        self.target = self.dbg.CreateTarget(exe, None, None, False, error)30        self.assertTrue(self.target, VALID_TARGET)31 32        cpp_bp = self.target.BreakpointCreateByRegex(33            "func_from",34            lldb.eLanguageTypeC_plus_plus,35            lldb.SBFileSpecList(),36            lldb.SBFileSpecList(),37        )38        self.assertEqual(cpp_bp.GetNumLocations(), 1, "Only one C++ symbol matches")39        self.assertTrue(self.check_location_file(cpp_bp, 0, "b.cpp"))40 41        c_bp = self.target.BreakpointCreateByRegex(42            "func_from",43            lldb.eLanguageTypeC,44            lldb.SBFileSpecList(),45            lldb.SBFileSpecList(),46        )47        self.assertEqual(c_bp.GetNumLocations(), 1, "Only one C symbol matches")48        self.assertTrue(self.check_location_file(c_bp, 0, "a.c"))49 50        objc_bp = self.target.BreakpointCreateByRegex(51            "func_from",52            lldb.eLanguageTypeObjC,53            lldb.SBFileSpecList(),54            lldb.SBFileSpecList(),55        )56        self.assertEqual(objc_bp.GetNumLocations(), 0, "No ObjC symbol matches")57 58    def test_by_name_breakpoint_language(self):59        """Test that the name regex breakpoint commands obey the language filter."""60 61        self.build()62        # Create a target by the debugger.63        exe = self.getBuildArtifact("a.out")64        error = lldb.SBError()65        # Don't read in dependencies so we don't come across false matches that66        # add unwanted breakpoint hits.67        self.target = self.dbg.CreateTarget(exe, None, None, False, error)68        self.assertTrue(self.target, VALID_TARGET)69 70        cpp_bp = self.target.BreakpointCreateByName(71            "func_from_cpp",72            lldb.eFunctionNameTypeAuto,73            lldb.eLanguageTypeC_plus_plus,74            lldb.SBFileSpecList(),75            lldb.SBFileSpecList(),76        )77        self.assertEqual(cpp_bp.GetNumLocations(), 1, "Only one C++ symbol matches")78        self.assertTrue(self.check_location_file(cpp_bp, 0, "b.cpp"))79 80        no_cpp_bp = self.target.BreakpointCreateByName(81            "func_from_c",82            lldb.eFunctionNameTypeAuto,83            lldb.eLanguageTypeC_plus_plus,84            lldb.SBFileSpecList(),85            lldb.SBFileSpecList(),86        )87        self.assertEqual(no_cpp_bp.GetNumLocations(), 0, "And the C one doesn't match")88 89        c_bp = self.target.BreakpointCreateByName(90            "func_from_c",91            lldb.eFunctionNameTypeAuto,92            lldb.eLanguageTypeC,93            lldb.SBFileSpecList(),94            lldb.SBFileSpecList(),95        )96        self.assertEqual(c_bp.GetNumLocations(), 1, "Only one C symbol matches")97        self.assertTrue(self.check_location_file(c_bp, 0, "a.c"))98 99        no_c_bp = self.target.BreakpointCreateByName(100            "func_from_cpp",101            lldb.eFunctionNameTypeAuto,102            lldb.eLanguageTypeC,103            lldb.SBFileSpecList(),104            lldb.SBFileSpecList(),105        )106        self.assertEqual(no_c_bp.GetNumLocations(), 0, "And the C++ one doesn't match")107 108        objc_bp = self.target.BreakpointCreateByName(109            "func_from_cpp",110            lldb.eFunctionNameTypeAuto,111            lldb.eLanguageTypeObjC,112            lldb.SBFileSpecList(),113            lldb.SBFileSpecList(),114        )115        self.assertEqual(objc_bp.GetNumLocations(), 0, "No ObjC symbol matches")116