1"""
2Test breakpoint command for different options.
3"""
4
5
6
7import lldb
8from lldbsuite.test.lldbtest import *
9import lldbsuite.test.lldbutil as lldbutil
10
11
12class BreakpointOptionsTestCase(TestBase):
13
14    def test(self):
15        """Test breakpoint command for different options."""
16        self.build()
17        self.breakpoint_options_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.cpp', '// Set break point at this line.')
24
25    def breakpoint_options_test(self):
26        """Test breakpoint command for different options."""
27        exe = self.getBuildArtifact("a.out")
28        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
29
30        # This should create a breakpoint with 1 locations.
31        lldbutil.run_break_set_by_file_and_line(
32            self,
33            "main.cpp",
34            self.line,
35            extra_options="-K 1",
36            num_expected_locations=1)
37        lldbutil.run_break_set_by_file_and_line(
38            self,
39            "main.cpp",
40            self.line,
41            extra_options="-K 0",
42            num_expected_locations=1)
43
44        # Run the program.
45        self.runCmd("run", RUN_SUCCEEDED)
46
47        # Stopped once.
48        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
49                    substrs=["stop reason = breakpoint 2."])
50
51        # Check the list of breakpoint.
52        self.expect(
53            "breakpoint list -f",
54            "Breakpoint locations shown correctly",
55            substrs=[
56                "1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" %
57                self.line,
58                "2: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" %
59                self.line])
60
61        # Continue the program, there should be another stop.
62        self.runCmd("process continue")
63
64        # Stopped again.
65        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
66                    substrs=["stop reason = breakpoint 1."])
67
68        # Continue the program, we should exit.
69        self.runCmd("process continue")
70
71        # We should exit.
72        self.expect("process status", "Process exited successfully",
73                    patterns=["^Process [0-9]+ exited with status = 0"])
74
75    def breakpoint_options_language_test(self):
76        """Test breakpoint command for language option."""
77        exe = self.getBuildArtifact("a.out")
78        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
79
80        # This should create a breakpoint with 1 locations.
81        lldbutil.run_break_set_by_symbol(
82            self,
83            'ns::func',
84            sym_exact=False,
85            extra_options="-L c++",
86            num_expected_locations=1)
87
88        # This should create a breakpoint with 0 locations.
89        lldbutil.run_break_set_by_symbol(
90            self,
91            'ns::func',
92            sym_exact=False,
93            extra_options="-L c",
94            num_expected_locations=0)
95        self.runCmd("settings set target.language c")
96        lldbutil.run_break_set_by_symbol(
97            self, 'ns::func', sym_exact=False, num_expected_locations=0)
98
99        # Run the program.
100        self.runCmd("run", RUN_SUCCEEDED)
101
102        # Stopped once.
103        self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
104                    substrs=["stop reason = breakpoint 1."])
105
106        # Continue the program, we should exit.
107        self.runCmd("process continue")
108
109        # We should exit.
110        self.expect("process status", "Process exited successfully",
111                    patterns=["^Process [0-9]+ exited with status = 0"])
112