2 Test lldb breakpoint setting by source regular expression.
3 This test just tests the source file & function restrictions.
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
13 class TestSourceRegexBreakpoints(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
17 def test_location(self):
19 self.source_regex_locations()
21 def test_restrictions(self):
23 self.source_regex_restrictions()
25 def source_regex_locations(self):
26 """ Test that restricting source expressions to files & to functions. """
27 # Create a target by the debugger.
28 exe = self.getBuildArtifact("a.out")
29 target = self.dbg.CreateTarget(exe)
30 self.assertTrue(target, VALID_TARGET)
32 # First look just in main:
33 target_files = lldb.SBFileSpecList()
34 target_files.Append(lldb.SBFileSpec("a.c"))
36 func_names = lldb.SBStringList()
37 func_names.AppendString("a_func")
39 source_regex = "Set . breakpoint here"
40 main_break = target.BreakpointCreateBySourceRegex(
41 source_regex, lldb.SBFileSpecList(), target_files, func_names)
42 num_locations = main_break.GetNumLocations()
45 "a.c in a_func should give one breakpoint, got %d." %
48 loc = main_break.GetLocationAtIndex(0)
49 self.assertTrue(loc.IsValid(), "Got a valid location.")
50 address = loc.GetAddress()
53 "Got a valid address from the location.")
55 a_func_line = line_number("a.c", "Set A breakpoint here")
56 line_entry = address.GetLineEntry()
57 self.assertTrue(line_entry.IsValid(), "Got a valid line entry.")
58 self.assertTrue(line_entry.line == a_func_line,
59 "Our line number matches the one lldbtest found.")
61 def source_regex_restrictions(self):
62 """ Test that restricting source expressions to files & to functions. """
63 # Create a target by the debugger.
64 exe = self.getBuildArtifact("a.out")
65 target = self.dbg.CreateTarget(exe)
66 self.assertTrue(target, VALID_TARGET)
68 # First look just in main:
69 target_files = lldb.SBFileSpecList()
70 target_files.Append(lldb.SBFileSpec("main.c"))
71 source_regex = "Set . breakpoint here"
72 main_break = target.BreakpointCreateBySourceRegex(
73 source_regex, lldb.SBFileSpecList(), target_files, lldb.SBStringList())
75 num_locations = main_break.GetNumLocations()
78 "main.c should have 2 matches, got %d." %
81 # Now look in both files:
82 target_files.Append(lldb.SBFileSpec("a.c"))
84 main_break = target.BreakpointCreateBySourceRegex(
85 source_regex, lldb.SBFileSpecList(), target_files, lldb.SBStringList())
87 num_locations = main_break.GetNumLocations()
90 "main.c and a.c should have 4 matches, got %d." %
93 # Now restrict it to functions:
94 func_names = lldb.SBStringList()
95 func_names.AppendString("main_func")
96 main_break = target.BreakpointCreateBySourceRegex(
97 source_regex, lldb.SBFileSpecList(), target_files, func_names)
99 num_locations = main_break.GetNumLocations()
102 "main_func in main.c and a.c should have 2 matches, got %d." %