2 Test number of threads.
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
10 from lldbsuite.test import lldbutil
13 class ExitDuringStepTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
17 @skipIfFreeBSD # llvm.org/pr21411: test is hanging
18 @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
20 """Test thread exit during step handling."""
21 self.build(dictionary=self.getBuildFlags())
22 self.exit_during_step_base(
23 "thread step-inst -m all-threads",
24 'stop reason = instruction step',
27 @skipIfFreeBSD # llvm.org/pr21411: test is hanging
28 @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
29 def test_step_over(self):
30 """Test thread exit during step-over handling."""
31 self.build(dictionary=self.getBuildFlags())
32 self.exit_during_step_base(
33 "thread step-over -m all-threads",
34 'stop reason = step over',
37 @skipIfFreeBSD # llvm.org/pr21411: test is hanging
38 @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
39 def test_step_in(self):
40 """Test thread exit during step-in handling."""
41 self.build(dictionary=self.getBuildFlags())
42 self.exit_during_step_base(
43 "thread step-in -m all-threads",
44 'stop reason = step in',
48 # Call super's setUp().
50 # Find the line numbers to break and continue.
51 self.breakpoint = line_number('main.cpp', '// Set breakpoint here')
52 self.continuepoint = line_number('main.cpp', '// Continue from here')
54 def exit_during_step_base(self, step_cmd, step_stop_reason, by_instruction):
55 """Test thread exit during step handling."""
56 exe = self.getBuildArtifact("a.out")
57 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
59 # This should create a breakpoint in the main thread.
60 self.bp_num = lldbutil.run_break_set_by_file_and_line(
61 self, "main.cpp", self.breakpoint, num_expected_locations=1)
63 # The breakpoint list should show 1 location.
66 "Breakpoint location shown correctly",
68 "1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" %
72 self.runCmd("run", RUN_SUCCEEDED)
74 # The stop reason of the thread should be breakpoint.
75 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
77 'stop reason = breakpoint'])
79 # Get the target process
80 target = self.dbg.GetSelectedTarget()
81 process = target.GetProcess()
83 num_threads = process.GetNumThreads()
84 # Make sure we see all three threads
85 self.assertGreaterEqual(
88 'Number of expected threads and actual threads do not match.')
90 stepping_thread = lldbutil.get_one_thread_stopped_at_breakpoint_id(
94 "Could not find a thread stopped at the breakpoint")
96 current_line = self.breakpoint
97 stepping_frame = stepping_thread.GetFrameAtIndex(0)
100 stepping_frame.GetLineEntry().GetLine(),
101 "Starting line for stepping doesn't match breakpoint line.")
103 # Keep stepping until we've reached our designated continue point
104 while current_line != self.continuepoint:
105 # Since we're using the command interpreter to issue the thread command
106 # (on the selected thread) we need to ensure the selected thread is the
108 if stepping_thread != process.GetSelectedThread():
109 process.SetSelectedThread(stepping_thread)
111 self.runCmd(step_cmd)
113 frame = stepping_thread.GetFrameAtIndex(0)
115 current_line = frame.GetLineEntry().GetLine()
117 if by_instruction and current_line == 0:
120 self.assertGreaterEqual(
123 "Stepped to unexpected line, " +
125 self.assertLessEqual(
128 "Stepped to unexpected line, " +
131 self.runCmd("thread list")
133 # Update the number of threads
134 new_num_threads = process.GetNumThreads()
136 # Check to see that we reduced the number of threads as expected
140 'Number of threads did not reduce by 1 after thread exit.')
142 self.expect("thread list", 'Process state is stopped due to step',
147 self.runCmd("continue")
149 # At this point, the inferior process should have exited.
150 self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)