blob: 851b3430e48254a2cf53ce83937ba648d4b9600d [file] [log] [blame]
Jim Ingham32fc9602011-10-11 01:43:50 +00001"""
2Test lldb breakpoint command for CPP methods & functions in a namespace.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
Zachary Turner11321522015-09-09 18:25:13 +000010class CPPBreakpointCommandsTestCase(TestBase):
Jim Ingham32fc9602011-10-11 01:43:50 +000011
Greg Clayton4570d3e2013-12-10 23:19:29 +000012 mydir = TestBase.compute_mydir(__file__)
Jim Ingham32fc9602011-10-11 01:43:50 +000013
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000014 def test(self):
Jim Ingham32fc9602011-10-11 01:43:50 +000015 """Test a sequence of breakpoint command add, list, and delete."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000016 self.build()
Jim Ingham32fc9602011-10-11 01:43:50 +000017 exe = os.path.join(os.getcwd(), "a.out")
18
19 # Create a target from the debugger.
20
21 target = self.dbg.CreateTarget (exe)
22 self.assertTrue(target, VALID_TARGET)
23
24 a_out_module = lldb.SBFileSpecList()
25 a_out_module.Append(lldb.SBFileSpec(exe))
26
27 nested_comp_unit = lldb.SBFileSpecList()
28 nested_comp_unit.Append (lldb.SBFileSpec("nested.cpp"))
29
30 # First provide ONLY the method name. This should get everybody...
31 auto_break = target.BreakpointCreateByName ("Function",
32 lldb.eFunctionNameTypeAuto,
33 a_out_module,
34 nested_comp_unit)
35 self.assertTrue (auto_break.GetNumLocations() == 5)
36
37 # Now add the Baz class specifier. This should get the version contained in Bar,
38 # AND the one contained in ::
39 auto_break = target.BreakpointCreateByName ("Baz::Function",
40 lldb.eFunctionNameTypeAuto,
41 a_out_module,
42 nested_comp_unit)
43 self.assertTrue (auto_break.GetNumLocations() == 2)
44
45 # Then add the Bar::Baz specifier. This should get the version contained in Bar only
46 auto_break = target.BreakpointCreateByName ("Bar::Baz::Function",
47 lldb.eFunctionNameTypeAuto,
48 a_out_module,
49 nested_comp_unit)
50 self.assertTrue (auto_break.GetNumLocations() == 1)
51
52 plain_method_break = target.BreakpointCreateByName ("Function",
53 lldb.eFunctionNameTypeMethod,
54 a_out_module,
55 nested_comp_unit)
56 self.assertTrue (plain_method_break.GetNumLocations() == 3)
57
58 plain_method_break = target.BreakpointCreateByName ("Baz::Function",
59 lldb.eFunctionNameTypeMethod,
60 a_out_module,
61 nested_comp_unit)
62 self.assertTrue (plain_method_break.GetNumLocations() == 2)
63
64 plain_method_break = target.BreakpointCreateByName ("Bar::Baz::Function",
65 lldb.eFunctionNameTypeMethod,
66 a_out_module,
67 nested_comp_unit)
68 self.assertTrue (plain_method_break.GetNumLocations() == 1)
69
70 plain_method_break = target.BreakpointCreateByName ("Function",
71 lldb.eFunctionNameTypeBase,
72 a_out_module,
73 nested_comp_unit)
74 self.assertTrue (plain_method_break.GetNumLocations() == 2)
75
76 plain_method_break = target.BreakpointCreateByName ("Bar::Function",
77 lldb.eFunctionNameTypeBase,
78 a_out_module,
79 nested_comp_unit)
80 self.assertTrue (plain_method_break.GetNumLocations() == 1)
81
82
83
84if __name__ == '__main__':
85 import atexit
86 lldb.SBDebugger.Initialize()
87 atexit.register(lambda: lldb.SBDebugger.Terminate())
88 unittest2.main()