1"""
2Test breakpoint commands set before we have a target
3"""
4
5
6
7import lldb
8from lldbsuite.test.lldbtest import *
9import lldbsuite.test.lldbutil as lldbutil
10
11
12class BreakpointInDummyTarget (TestBase):
13
14    def test(self):
15        """Test breakpoint set before we have a target. """
16        self.build()
17        self.dummy_breakpoint_test()
18
19    def setUp(self):
20        # Call super's setUp().
21        TestBase.setUp(self)
22        # Find the line number to break inside main().
23        self.line = line_number('main.c', 'Set a breakpoint on this line.')
24        self.line2 = line_number('main.c', 'Set another on this line.')
25
26    def dummy_breakpoint_test(self):
27        """Test breakpoint set before we have a target. """
28
29        # This should create a breakpoint with 3 locations.
30        lldbutil.run_break_set_by_file_and_line(
31            self, "main.c", self.line, num_expected_locations=0)
32        lldbutil.run_break_set_by_file_and_line(
33            self, "main.c", self.line2, num_expected_locations=0)
34
35        # This is the function to remove breakpoints from the dummy target
36        # to get a clean slate for the next test case.
37        def cleanup():
38            self.runCmd('breakpoint delete -D -f', check=False)
39            self.runCmd('breakpoint list', check=False)
40
41        # Execute the cleanup function during test case tear down.
42        self.addTearDownHook(cleanup)
43
44        exe = self.getBuildArtifact("a.out")
45        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
46
47        # The breakpoint list should show 3 locations.
48        self.expect(
49            "breakpoint list -f",
50            "Breakpoint locations shown correctly",
51            substrs=[
52                "1: file = 'main.c', line = %d, exact_match = 0, locations = 1" %
53                self.line,
54                "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" %
55                self.line2])
56
57        # Run the program.
58        self.runCmd("run", RUN_SUCCEEDED)
59
60        # Stopped once.
61        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
62                    substrs=["stop reason = breakpoint 1."])
63
64        # Continue the program, there should be another stop.
65        self.runCmd("process continue")
66
67        # Stopped again.
68        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
69                    substrs=["stop reason = breakpoint 2."])
70