xref: /llvm-project/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest _regexp-break command which uses regular expression matching to dispatch to other built in breakpoint commands.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprecht
699451b44SJordan Rupprechtimport os
799451b44SJordan Rupprechtimport lldb
899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
999451b44SJordan Rupprechtimport lldbsuite.test.lldbutil as lldbutil
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprechtclass RegexpBreakCommandTestCase(TestBase):
1399451b44SJordan Rupprecht    def test(self):
1499451b44SJordan Rupprecht        """Test _regexp-break command."""
1599451b44SJordan Rupprecht        self.build()
1699451b44SJordan Rupprecht        self.regexp_break_command()
1799451b44SJordan Rupprecht
1899451b44SJordan Rupprecht    def setUp(self):
1999451b44SJordan Rupprecht        # Call super's setUp().
2099451b44SJordan Rupprecht        TestBase.setUp(self)
2199451b44SJordan Rupprecht        # Find the line number to break inside main().
22*2238dcc3SJonas Devlieghere        self.source = "main.c"
23*2238dcc3SJonas Devlieghere        self.line = line_number(self.source, "// Set break point at this line.")
2499451b44SJordan Rupprecht
2599451b44SJordan Rupprecht    def regexp_break_command(self):
2699451b44SJordan Rupprecht        """Test the super consie "b" command, which is analias for _regexp-break."""
2799451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
2899451b44SJordan Rupprecht        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
2999451b44SJordan Rupprecht
30*2238dcc3SJonas Devlieghere        break_results = lldbutil.run_break_set_command(self, "b %d" % self.line)
3199451b44SJordan Rupprecht        lldbutil.check_breakpoint_result(
3299451b44SJordan Rupprecht            self,
3399451b44SJordan Rupprecht            break_results,
34*2238dcc3SJonas Devlieghere            file_name="main.c",
3599451b44SJordan Rupprecht            line_number=self.line,
36*2238dcc3SJonas Devlieghere            num_locations=1,
37*2238dcc3SJonas Devlieghere        )
3899451b44SJordan Rupprecht
3999451b44SJordan Rupprecht        break_results = lldbutil.run_break_set_command(
40*2238dcc3SJonas Devlieghere            self, "b %s:%d" % (self.source, self.line)
41*2238dcc3SJonas Devlieghere        )
4299451b44SJordan Rupprecht        lldbutil.check_breakpoint_result(
4399451b44SJordan Rupprecht            self,
4499451b44SJordan Rupprecht            break_results,
45*2238dcc3SJonas Devlieghere            file_name="main.c",
4699451b44SJordan Rupprecht            line_number=self.line,
47*2238dcc3SJonas Devlieghere            num_locations=1,
48*2238dcc3SJonas Devlieghere        )
4999451b44SJordan Rupprecht
5099451b44SJordan Rupprecht        # Check breakpoint with full file path.
5199451b44SJordan Rupprecht        full_path = os.path.join(self.getSourceDir(), self.source)
5299451b44SJordan Rupprecht        break_results = lldbutil.run_break_set_command(
53*2238dcc3SJonas Devlieghere            self, "b %s:%d" % (full_path, self.line)
54*2238dcc3SJonas Devlieghere        )
5599451b44SJordan Rupprecht        lldbutil.check_breakpoint_result(
5699451b44SJordan Rupprecht            self,
5799451b44SJordan Rupprecht            break_results,
58*2238dcc3SJonas Devlieghere            file_name="main.c",
5999451b44SJordan Rupprecht            line_number=self.line,
60*2238dcc3SJonas Devlieghere            num_locations=1,
61*2238dcc3SJonas Devlieghere        )
6299451b44SJordan Rupprecht
6399451b44SJordan Rupprecht        self.runCmd("run", RUN_SUCCEEDED)
6499451b44SJordan Rupprecht
6599451b44SJordan Rupprecht        # The stop reason of the thread should be breakpoint.
66*2238dcc3SJonas Devlieghere        self.expect(
67*2238dcc3SJonas Devlieghere            "thread list",
68*2238dcc3SJonas Devlieghere            STOPPED_DUE_TO_BREAKPOINT,
69*2238dcc3SJonas Devlieghere            substrs=["stopped", "stop reason = breakpoint"],
70*2238dcc3SJonas Devlieghere        )
71