1"""
2Test _regexp-break command which uses regular expression matching to dispatch to other built in breakpoint commands.
3"""
4
5
6
7import os
8import lldb
9from lldbsuite.test.lldbtest import *
10import lldbsuite.test.lldbutil as lldbutil
11
12
13class RegexpBreakCommandTestCase(TestBase):
14
15    def test(self):
16        """Test _regexp-break command."""
17        self.build()
18        self.regexp_break_command()
19
20    def setUp(self):
21        # Call super's setUp().
22        TestBase.setUp(self)
23        # Find the line number to break inside main().
24        self.source = 'main.c'
25        self.line = line_number(
26            self.source, '// Set break point at this line.')
27
28    def regexp_break_command(self):
29        """Test the super consie "b" command, which is analias for _regexp-break."""
30        exe = self.getBuildArtifact("a.out")
31        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
32
33        break_results = lldbutil.run_break_set_command(
34            self, "b %d" %
35            self.line)
36        lldbutil.check_breakpoint_result(
37            self,
38            break_results,
39            file_name='main.c',
40            line_number=self.line,
41            num_locations=1)
42
43        break_results = lldbutil.run_break_set_command(
44            self, "b %s:%d" % (self.source, self.line))
45        lldbutil.check_breakpoint_result(
46            self,
47            break_results,
48            file_name='main.c',
49            line_number=self.line,
50            num_locations=1)
51
52        # Check breakpoint with full file path.
53        full_path = os.path.join(self.getSourceDir(), self.source)
54        break_results = lldbutil.run_break_set_command(
55            self, "b %s:%d" % (full_path, self.line))
56        lldbutil.check_breakpoint_result(
57            self,
58            break_results,
59            file_name='main.c',
60            line_number=self.line,
61            num_locations=1)
62
63        self.runCmd("run", RUN_SUCCEEDED)
64
65        # The stop reason of the thread should be breakpoint.
66        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
67                    substrs=['stopped',
68                             'stop reason = breakpoint'])
69