1"""
2Test lldb breakpoint command for CPP methods & functions in a namespace.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10class CPPBreakpointTestCase(TestBase):
11
12    mydir = os.path.join("lang", "cpp", "breakpoints")
13
14    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
15    @dsym_test
16    def test_with_dsym(self):
17        """Test a sequence of breakpoint command add, list, and delete."""
18        self.buildDsym()
19        self.cpp_breakpoints()
20
21    @dwarf_test
22    def test_with_dwarf(self):
23        """Test a sequence of breakpoint command add, list, and delete."""
24        self.buildDwarf()
25        self.cpp_breakpoints()
26
27    def setUp(self):
28        # Call super's setUp().
29        TestBase.setUp(self)
30
31    def cpp_breakpoints (self):
32        """Test a sequence of breakpoint command add, list, and delete."""
33        exe = os.path.join(os.getcwd(), "a.out")
34
35        # Create a target from the debugger.
36
37        target = self.dbg.CreateTarget (exe)
38        self.assertTrue(target, VALID_TARGET)
39
40        a_out_module = lldb.SBFileSpecList()
41        a_out_module.Append(lldb.SBFileSpec(exe))
42
43        nested_comp_unit = lldb.SBFileSpecList()
44        nested_comp_unit.Append (lldb.SBFileSpec("nested.cpp"))
45
46        # First provide ONLY the method name.  This should get everybody...
47        auto_break = target.BreakpointCreateByName ("Function",
48                                                    lldb.eFunctionNameTypeAuto,
49                                                    a_out_module,
50                                                    nested_comp_unit)
51        self.assertTrue (auto_break.GetNumLocations() == 5)
52
53        # Now add the Baz class specifier.  This should get the version contained in Bar,
54        # AND the one contained in ::
55        auto_break = target.BreakpointCreateByName ("Baz::Function",
56                                                    lldb.eFunctionNameTypeAuto,
57                                                    a_out_module,
58                                                    nested_comp_unit)
59        self.assertTrue (auto_break.GetNumLocations() == 2)
60
61        # Then add the Bar::Baz specifier.  This should get the version contained in Bar only
62        auto_break = target.BreakpointCreateByName ("Bar::Baz::Function",
63                                                    lldb.eFunctionNameTypeAuto,
64                                                    a_out_module,
65                                                    nested_comp_unit)
66        self.assertTrue (auto_break.GetNumLocations() == 1)
67
68        plain_method_break = target.BreakpointCreateByName ("Function",
69                                                            lldb.eFunctionNameTypeMethod,
70                                                            a_out_module,
71                                                            nested_comp_unit)
72        self.assertTrue (plain_method_break.GetNumLocations() == 3)
73
74        plain_method_break = target.BreakpointCreateByName ("Baz::Function",
75                                                            lldb.eFunctionNameTypeMethod,
76                                                            a_out_module,
77                                                            nested_comp_unit)
78        self.assertTrue (plain_method_break.GetNumLocations() == 2)
79
80        plain_method_break = target.BreakpointCreateByName ("Bar::Baz::Function",
81                                                            lldb.eFunctionNameTypeMethod,
82                                                            a_out_module,
83                                                            nested_comp_unit)
84        self.assertTrue (plain_method_break.GetNumLocations() == 1)
85
86        plain_method_break = target.BreakpointCreateByName ("Function",
87                                                            lldb.eFunctionNameTypeBase,
88                                                            a_out_module,
89                                                            nested_comp_unit)
90        self.assertTrue (plain_method_break.GetNumLocations() == 2)
91
92        plain_method_break = target.BreakpointCreateByName ("Bar::Function",
93                                                            lldb.eFunctionNameTypeBase,
94                                                            a_out_module,
95                                                            nested_comp_unit)
96        self.assertTrue (plain_method_break.GetNumLocations() == 1)
97
98
99
100if __name__ == '__main__':
101    import atexit
102    lldb.SBDebugger.Initialize()
103    atexit.register(lambda: lldb.SBDebugger.Terminate())
104    unittest2.main()
105