xref: /llvm-project/lldb/test/API/functionalities/thread/multi_break/TestMultipleBreakpoints.py (revision 9c2468821ec51defd09c246fea4a47886fff8c01)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest number of threads.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprecht
699451b44SJordan Rupprechtimport lldb
799451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
999451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprechtclass MultipleBreakpointTestCase(TestBase):
1399451b44SJordan Rupprecht    def setUp(self):
1499451b44SJordan Rupprecht        # Call super's setUp().
1599451b44SJordan Rupprecht        TestBase.setUp(self)
1699451b44SJordan Rupprecht        # Find the line number for our breakpoint.
172238dcc3SJonas Devlieghere        self.breakpoint = line_number("main.cpp", "// Set breakpoint here")
1899451b44SJordan Rupprecht
1999451b44SJordan Rupprecht    @expectedFailureAll(
2099451b44SJordan Rupprecht        oslist=["linux"],
212238dcc3SJonas Devlieghere        bugnumber="llvm.org/pr15824 thread states not properly maintained",
222238dcc3SJonas Devlieghere    )
2399451b44SJordan Rupprecht    @expectedFailureAll(
2499451b44SJordan Rupprecht        oslist=lldbplatformutil.getDarwinOSTriples(),
252238dcc3SJonas Devlieghere        bugnumber="llvm.org/pr15824 thread states not properly maintained and <rdar://problem/28557237>",
262238dcc3SJonas Devlieghere    )
2799451b44SJordan Rupprecht    @expectedFailureAll(
2899451b44SJordan Rupprecht        oslist=["freebsd"],
292238dcc3SJonas Devlieghere        bugnumber="llvm.org/pr18190 thread states not properly maintained",
302238dcc3SJonas Devlieghere    )
3199451b44SJordan Rupprecht    @skipIfWindows  # This is flakey on Windows: llvm.org/pr24668, llvm.org/pr38373
3299451b44SJordan Rupprecht    @expectedFailureNetBSD
3399451b44SJordan Rupprecht    def test(self):
3499451b44SJordan Rupprecht        """Test simultaneous breakpoints in multiple threads."""
35d7dbe2c4SPavel Labath        self.build()
3699451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
3799451b44SJordan Rupprecht        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
3899451b44SJordan Rupprecht
3999451b44SJordan Rupprecht        # This should create a breakpoint in the main thread.
4099451b44SJordan Rupprecht        lldbutil.run_break_set_by_file_and_line(
412238dcc3SJonas Devlieghere            self, "main.cpp", self.breakpoint, num_expected_locations=1
422238dcc3SJonas Devlieghere        )
4399451b44SJordan Rupprecht
4499451b44SJordan Rupprecht        # Run the program.
4599451b44SJordan Rupprecht        self.runCmd("run", RUN_SUCCEEDED)
4699451b44SJordan Rupprecht
4799451b44SJordan Rupprecht        # The stop reason of the thread should be breakpoint.
4899451b44SJordan Rupprecht        # The breakpoint may be hit in either thread 2 or thread 3.
492238dcc3SJonas Devlieghere        self.expect(
502238dcc3SJonas Devlieghere            "thread list",
512238dcc3SJonas Devlieghere            STOPPED_DUE_TO_BREAKPOINT,
522238dcc3SJonas Devlieghere            substrs=["stopped", "stop reason = breakpoint"],
532238dcc3SJonas Devlieghere        )
5499451b44SJordan Rupprecht
5599451b44SJordan Rupprecht        # Get the target process
5699451b44SJordan Rupprecht        target = self.dbg.GetSelectedTarget()
5799451b44SJordan Rupprecht        process = target.GetProcess()
5899451b44SJordan Rupprecht
5999451b44SJordan Rupprecht        # Get the number of threads
6099451b44SJordan Rupprecht        num_threads = process.GetNumThreads()
6199451b44SJordan Rupprecht
6299451b44SJordan Rupprecht        # Make sure we see all three threads
63*9c246882SJordan Rupprecht        self.assertGreaterEqual(
64*9c246882SJordan Rupprecht            num_threads,
65*9c246882SJordan Rupprecht            3,
662238dcc3SJonas Devlieghere            "Number of expected threads and actual threads do not match.",
672238dcc3SJonas Devlieghere        )
6899451b44SJordan Rupprecht
6999451b44SJordan Rupprecht        # Get the thread objects
7099451b44SJordan Rupprecht        thread1 = process.GetThreadAtIndex(0)
7199451b44SJordan Rupprecht        thread2 = process.GetThreadAtIndex(1)
7299451b44SJordan Rupprecht        thread3 = process.GetThreadAtIndex(2)
7399451b44SJordan Rupprecht
7499451b44SJordan Rupprecht        # Make sure both threads are stopped
7599451b44SJordan Rupprecht        self.assertTrue(
762238dcc3SJonas Devlieghere            thread1.IsStopped(), "Primary thread didn't stop during breakpoint"
772238dcc3SJonas Devlieghere        )
7899451b44SJordan Rupprecht        self.assertTrue(
792238dcc3SJonas Devlieghere            thread2.IsStopped(), "Secondary thread didn't stop during breakpoint"
802238dcc3SJonas Devlieghere        )
8199451b44SJordan Rupprecht        self.assertTrue(
822238dcc3SJonas Devlieghere            thread3.IsStopped(), "Tertiary thread didn't stop during breakpoint"
832238dcc3SJonas Devlieghere        )
8499451b44SJordan Rupprecht
8599451b44SJordan Rupprecht        # Delete the first breakpoint then continue
8699451b44SJordan Rupprecht        self.runCmd("breakpoint delete 1")
8799451b44SJordan Rupprecht
8899451b44SJordan Rupprecht        # Run to completion
8999451b44SJordan Rupprecht        self.runCmd("continue")
9099451b44SJordan Rupprecht
9199451b44SJordan Rupprecht        # At this point, the inferior process should have exited.
922238dcc3SJonas Devlieghere        self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
93