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