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