2 Test that the language option for breakpoints works correctly
9 from lldbsuite.test.lldbtest import *
10 import lldbsuite.test.lldbutil as lldbutil
13 class TestBreakpointLanguage(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
17 def check_location_file(self, bp, loc, test_name):
18 bp_loc = bp.GetLocationAtIndex(loc)
19 addr = bp_loc.GetAddress()
20 comp_unit = addr.GetCompileUnit()
21 comp_name = comp_unit.GetFileSpec().GetFilename()
22 return comp_name == test_name
24 def test_regex_breakpoint_language(self):
25 """Test that the name regex breakpoint commands obey the language filter."""
28 # Create a target by the debugger.
29 exe = self.getBuildArtifact("a.out")
30 error = lldb.SBError()
31 # Don't read in dependencies so we don't come across false matches that
32 # add unwanted breakpoint hits.
33 self.target = self.dbg.CreateTarget(exe, None, None, False, error)
34 self.assertTrue(self.target, VALID_TARGET)
36 cpp_bp = self.target.BreakpointCreateByRegex(
38 lldb.eLanguageTypeC_plus_plus,
39 lldb.SBFileSpecList(),
40 lldb.SBFileSpecList())
42 cpp_bp.GetNumLocations() == 1,
43 "Only one C++ symbol matches")
44 self.assertTrue(self.check_location_file(cpp_bp, 0, "b.cpp"))
46 c_bp = self.target.BreakpointCreateByRegex(
49 lldb.SBFileSpecList(),
50 lldb.SBFileSpecList())
52 c_bp.GetNumLocations() == 1,
53 "Only one C symbol matches")
54 self.assertTrue(self.check_location_file(c_bp, 0, "a.c"))
56 objc_bp = self.target.BreakpointCreateByRegex(
58 lldb.eLanguageTypeObjC,
59 lldb.SBFileSpecList(),
60 lldb.SBFileSpecList())
62 objc_bp.GetNumLocations() == 0,
63 "No ObjC symbol matches")
65 def test_by_name_breakpoint_language(self):
66 """Test that the name regex breakpoint commands obey the language filter."""
69 # Create a target by the debugger.
70 exe = self.getBuildArtifact("a.out")
71 error = lldb.SBError()
72 # Don't read in dependencies so we don't come across false matches that
73 # add unwanted breakpoint hits.
74 self.target = self.dbg.CreateTarget(exe, None, None, False, error)
75 self.assertTrue(self.target, VALID_TARGET)
77 cpp_bp = self.target.BreakpointCreateByName(
79 lldb.eFunctionNameTypeAuto,
80 lldb.eLanguageTypeC_plus_plus,
81 lldb.SBFileSpecList(),
82 lldb.SBFileSpecList())
84 cpp_bp.GetNumLocations() == 1,
85 "Only one C++ symbol matches")
86 self.assertTrue(self.check_location_file(cpp_bp, 0, "b.cpp"))
88 no_cpp_bp = self.target.BreakpointCreateByName(
90 lldb.eFunctionNameTypeAuto,
91 lldb.eLanguageTypeC_plus_plus,
92 lldb.SBFileSpecList(),
93 lldb.SBFileSpecList())
95 no_cpp_bp.GetNumLocations() == 0,
96 "And the C one doesn't match")
98 c_bp = self.target.BreakpointCreateByName(
100 lldb.eFunctionNameTypeAuto,
102 lldb.SBFileSpecList(),
103 lldb.SBFileSpecList())
105 c_bp.GetNumLocations() == 1,
106 "Only one C symbol matches")
107 self.assertTrue(self.check_location_file(c_bp, 0, "a.c"))
109 no_c_bp = self.target.BreakpointCreateByName(
111 lldb.eFunctionNameTypeAuto,
113 lldb.SBFileSpecList(),
114 lldb.SBFileSpecList())
116 no_c_bp.GetNumLocations() == 0,
117 "And the C++ one doesn't match")
119 objc_bp = self.target.BreakpointCreateByName(
121 lldb.eFunctionNameTypeAuto,
122 lldb.eLanguageTypeObjC,
123 lldb.SBFileSpecList(),
124 lldb.SBFileSpecList())
126 objc_bp.GetNumLocations() == 0,
127 "No ObjC symbol matches")