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