xref: /llvm-project/lldb/test/API/functionalities/thread/exit_during_break/TestExitDuringBreak.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 ExitDuringBreakpointTestCase(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    def test(self):
2099451b44SJordan Rupprecht        """Test thread exit during breakpoint handling."""
21d7dbe2c4SPavel Labath        self.build()
2299451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
2399451b44SJordan Rupprecht        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
2499451b44SJordan Rupprecht
2599451b44SJordan Rupprecht        # This should create a breakpoint in the main thread.
2699451b44SJordan Rupprecht        lldbutil.run_break_set_by_file_and_line(
272238dcc3SJonas Devlieghere            self, "main.cpp", self.breakpoint, num_expected_locations=1
282238dcc3SJonas Devlieghere        )
2999451b44SJordan Rupprecht
3099451b44SJordan Rupprecht        # Run the program.
3199451b44SJordan Rupprecht        self.runCmd("run", RUN_SUCCEEDED)
3299451b44SJordan Rupprecht
3399451b44SJordan Rupprecht        # The stop reason of the thread should be breakpoint.
342238dcc3SJonas Devlieghere        self.expect(
352238dcc3SJonas Devlieghere            "thread list",
362238dcc3SJonas Devlieghere            STOPPED_DUE_TO_BREAKPOINT,
372238dcc3SJonas Devlieghere            substrs=["stopped", "stop reason = breakpoint"],
382238dcc3SJonas Devlieghere        )
3999451b44SJordan Rupprecht
4099451b44SJordan Rupprecht        # Get the target process
4199451b44SJordan Rupprecht        target = self.dbg.GetSelectedTarget()
4299451b44SJordan Rupprecht        process = target.GetProcess()
4399451b44SJordan Rupprecht
4499451b44SJordan Rupprecht        # The exit probably occurred during breakpoint handling, but it isn't
4599451b44SJordan Rupprecht        # guaranteed.  The main thing we're testing here is that the debugger
4699451b44SJordan Rupprecht        # handles this cleanly is some way.
4799451b44SJordan Rupprecht
4899451b44SJordan Rupprecht        # Get the number of threads
4999451b44SJordan Rupprecht        num_threads = process.GetNumThreads()
5099451b44SJordan Rupprecht
5199451b44SJordan Rupprecht        # Make sure we see at least five threads
52*9c246882SJordan Rupprecht        self.assertGreaterEqual(
53*9c246882SJordan Rupprecht            num_threads,
54*9c246882SJordan Rupprecht            5,
552238dcc3SJonas Devlieghere            "Number of expected threads and actual threads do not match.",
562238dcc3SJonas Devlieghere        )
5799451b44SJordan Rupprecht
5899451b44SJordan Rupprecht        # Run to completion
5999451b44SJordan Rupprecht        self.runCmd("continue")
6099451b44SJordan Rupprecht
6199451b44SJordan Rupprecht        # At this point, the inferior process should have exited.
622238dcc3SJonas Devlieghere        self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
63