1""" 2Test lldb breakpoint command for CPP methods & functions in a namespace. 3""" 4 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class CPPBreakpointCommandsTestCase(TestBase): 14 15 def make_breakpoint(self, name, type, expected_num_locations): 16 bkpt = self.target.BreakpointCreateByName(name, 17 type, 18 self.a_out_module, 19 self.nested_comp_unit) 20 num_locations = bkpt.GetNumLocations() 21 self.assertEqual( 22 num_locations, expected_num_locations, 23 "Wrong number of locations for '%s', expected: %d got: %d" % 24 (name, 25 expected_num_locations, 26 num_locations)) 27 return bkpt 28 29 def test_cpp_breakpoint_cmds(self): 30 """Test a sequence of breakpoint command add, list, and delete.""" 31 self.build() 32 33 exe = self.getBuildArtifact("a.out") 34 35 # Create a target from the debugger. 36 37 self.target = self.dbg.CreateTarget(exe) 38 self.assertTrue(self.target, VALID_TARGET) 39 40 self.a_out_module = lldb.SBFileSpecList() 41 self.a_out_module.Append(lldb.SBFileSpec(exe)) 42 43 self.nested_comp_unit = lldb.SBFileSpecList() 44 self.nested_comp_unit.Append(lldb.SBFileSpec("nested.cpp")) 45 46 # First provide ONLY the method name. This should get everybody... 47 self.make_breakpoint("Function", 48 lldb.eFunctionNameTypeAuto, 49 5) 50 51 # Now add the Baz class specifier. This should get the version contained in Bar, 52 # AND the one contained in :: 53 self.make_breakpoint("Baz::Function", 54 lldb.eFunctionNameTypeAuto, 55 2) 56 57 # Then add the Bar::Baz specifier. This should get the version 58 # contained in Bar only 59 self.make_breakpoint("Bar::Baz::Function", 60 lldb.eFunctionNameTypeAuto, 61 1) 62 63 self.make_breakpoint("Function", 64 lldb.eFunctionNameTypeMethod, 65 3) 66 67 self.make_breakpoint("Baz::Function", 68 lldb.eFunctionNameTypeMethod, 69 2) 70 71 self.make_breakpoint("Bar::Baz::Function", 72 lldb.eFunctionNameTypeMethod, 73 1) 74 75 self.make_breakpoint("Function", 76 lldb.eFunctionNameTypeBase, 77 2) 78 79 self.make_breakpoint("Bar::Function", 80 lldb.eFunctionNameTypeBase, 81 1) 82