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