1"""
2Test number of threads.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class ExitDuringBreakpointTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    def setUp(self):
18        # Call super's setUp().
19        TestBase.setUp(self)
20        # Find the line number for our breakpoint.
21        self.breakpoint = line_number('main.cpp', '// Set breakpoint here')
22
23    def test(self):
24        """Test thread exit during breakpoint handling."""
25        self.build(dictionary=self.getBuildFlags())
26        exe = self.getBuildArtifact("a.out")
27        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
28
29        # This should create a breakpoint in the main thread.
30        lldbutil.run_break_set_by_file_and_line(
31            self, "main.cpp", self.breakpoint, num_expected_locations=1)
32
33        # Run the program.
34        self.runCmd("run", RUN_SUCCEEDED)
35
36        # The stop reason of the thread should be breakpoint.
37        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
38                    substrs=['stopped',
39                             'stop reason = breakpoint'])
40
41        # Get the target process
42        target = self.dbg.GetSelectedTarget()
43        process = target.GetProcess()
44
45        # The exit probably occurred during breakpoint handling, but it isn't
46        # guaranteed.  The main thing we're testing here is that the debugger
47        # handles this cleanly is some way.
48
49        # Get the number of threads
50        num_threads = process.GetNumThreads()
51
52        # Make sure we see at least five threads
53        self.assertTrue(
54            num_threads >= 5,
55            'Number of expected threads and actual threads do not match.')
56
57        # Run to completion
58        self.runCmd("continue")
59
60        # At this point, the inferior process should have exited.
61        self.assertTrue(
62            process.GetState() == lldb.eStateExited,
63            PROCESS_EXITED)
64