Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test thread states. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | import lldbutil |
| 10 | |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 11 | class ThreadStateTestCase(TestBase): |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 12 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 13 | mydir = TestBase.compute_mydir(__file__) |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 14 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 15 | @skipUnlessDarwin |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 16 | @dsym_test |
Enrico Granata | 03e474b | 2013-11-01 00:57:53 +0000 | [diff] [blame] | 17 | @expectedFailureDarwin("rdar://15367566") |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 18 | def test_state_after_breakpoint_with_dsym(self): |
| 19 | """Test thread state after breakpoint.""" |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 20 | self.buildDsym(dictionary=self.getBuildFlags(use_cpp11=False)) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 21 | self.thread_state_after_breakpoint_test() |
| 22 | |
Enrico Granata | 03e474b | 2013-11-01 00:57:53 +0000 | [diff] [blame] | 23 | @expectedFailureDarwin("rdar://15367566") |
Chaoren Lin | 72b8f05 | 2015-02-03 01:51:18 +0000 | [diff] [blame] | 24 | @expectedFailureFreeBSD('llvm.org/pr15824') |
Pavel Labath | b36f917 | 2015-06-24 14:43:20 +0000 | [diff] [blame^] | 25 | @expectedFailureLinux("llvm.org/pr15824") # thread states not properly maintained |
Chaoren Lin | 72b8f05 | 2015-02-03 01:51:18 +0000 | [diff] [blame] | 26 | @dwarf_test |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 27 | def test_state_after_breakpoint_with_dwarf(self): |
| 28 | """Test thread state after breakpoint.""" |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 29 | self.buildDwarf(dictionary=self.getBuildFlags(use_cpp11=False)) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 30 | self.thread_state_after_breakpoint_test() |
| 31 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 32 | @skipUnlessDarwin |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 33 | @dsym_test |
| 34 | def test_state_after_continue_with_dsym(self): |
| 35 | """Test thread state after continue.""" |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 36 | self.buildDsym(dictionary=self.getBuildFlags(use_cpp11=False)) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 37 | self.thread_state_after_continue_test() |
| 38 | |
| 39 | @dwarf_test |
Ying Chen | 1135e70 | 2015-05-28 21:03:26 +0000 | [diff] [blame] | 40 | @skipIfDarwin # 'llvm.org/pr23669', cause Python crash randomly |
| 41 | @expectedFailureDarwin('llvm.org/pr23669') |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 42 | def test_state_after_continue_with_dwarf(self): |
| 43 | """Test thread state after continue.""" |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 44 | self.buildDwarf(dictionary=self.getBuildFlags(use_cpp11=False)) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 45 | self.thread_state_after_continue_test() |
| 46 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 47 | @skipUnlessDarwin |
Ying Chen | 1135e70 | 2015-05-28 21:03:26 +0000 | [diff] [blame] | 48 | @skipIfDarwin # 'llvm.org/pr23669', cause Python crash randomly |
| 49 | @expectedFailureDarwin('llvm.org/pr23669') |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 50 | @dsym_test |
| 51 | def test_state_after_expression_with_dsym(self): |
| 52 | """Test thread state after expression.""" |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 53 | self.buildDsym(dictionary=self.getBuildFlags(use_cpp11=False)) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 54 | self.thread_state_after_continue_test() |
| 55 | |
Ying Chen | 1135e70 | 2015-05-28 21:03:26 +0000 | [diff] [blame] | 56 | @skipIfDarwin # 'llvm.org/pr23669', cause Python crash randomly |
| 57 | @expectedFailureDarwin('llvm.org/pr23669') |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 58 | @dwarf_test |
| 59 | def test_state_after_expression_with_dwarf(self): |
| 60 | """Test thread state after expression.""" |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 61 | self.buildDwarf(dictionary=self.getBuildFlags(use_cpp11=False)) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 62 | self.thread_state_after_continue_test() |
| 63 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 64 | @skipUnlessDarwin |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 65 | @dsym_test |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 66 | @unittest2.expectedFailure("llvm.org/pr16172") # thread states not properly maintained |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 67 | def test_process_interrupt_with_dsym(self): |
| 68 | """Test process interrupt.""" |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 69 | self.buildDsym(dictionary=self.getBuildFlags(use_cpp11=False)) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 70 | self.process_interrupt_test() |
| 71 | |
| 72 | @dwarf_test |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 73 | @unittest2.expectedFailure("llvm.org/pr16712") # thread states not properly maintained |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 74 | def test_process_interrupt_with_dwarf(self): |
| 75 | """Test process interrupt.""" |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 76 | self.buildDwarf(dictionary=self.getBuildFlags(use_cpp11=False)) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 77 | self.process_interrupt_test() |
| 78 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 79 | @skipUnlessDarwin |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 80 | @dsym_test |
Daniel Malea | e8bdd1f | 2013-05-15 18:48:32 +0000 | [diff] [blame] | 81 | @unittest2.expectedFailure("llvm.org/pr15824") # thread states not properly maintained |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 82 | def test_process_state_with_dsym(self): |
| 83 | """Test thread states (comprehensive).""" |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 84 | self.buildDsym(dictionary=self.getBuildFlags(use_cpp11=False)) |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 85 | self.thread_states_test() |
| 86 | |
| 87 | @dwarf_test |
Daniel Malea | e8bdd1f | 2013-05-15 18:48:32 +0000 | [diff] [blame] | 88 | @unittest2.expectedFailure("llvm.org/pr15824") # thread states not properly maintained |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 89 | def test_process_state_with_dwarf(self): |
| 90 | """Test thread states (comprehensive).""" |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 91 | self.buildDwarf(dictionary=self.getBuildFlags(use_cpp11=False)) |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 92 | self.thread_states_test() |
| 93 | |
| 94 | def setUp(self): |
| 95 | # Call super's setUp(). |
| 96 | TestBase.setUp(self) |
| 97 | # Find the line numbers for our breakpoints. |
| 98 | self.break_1 = line_number('main.c', '// Set first breakpoint here') |
| 99 | self.break_2 = line_number('main.c', '// Set second breakpoint here') |
| 100 | |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 101 | def thread_state_after_breakpoint_test(self): |
| 102 | """Test thread state after breakpoint.""" |
| 103 | exe = os.path.join(os.getcwd(), "a.out") |
| 104 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 105 | |
| 106 | # This should create a breakpoint in the main thread. |
| 107 | lldbutil.run_break_set_by_file_and_line (self, "main.c", self.break_1, num_expected_locations=1) |
| 108 | |
| 109 | # The breakpoint list should show 1 breakpoint with 1 location. |
| 110 | self.expect("breakpoint list -f", "Breakpoint location shown correctly", |
Matt Kopec | 36e5a7d | 2013-06-17 19:00:31 +0000 | [diff] [blame] | 111 | substrs = ["1: file = 'main.c', line = %d, locations = 1" % self.break_1]) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 112 | |
| 113 | # Run the program. |
Siva Chandra | 3154aa2 | 2015-05-27 22:27:41 +0000 | [diff] [blame] | 114 | self.runCmd("run", RUN_FAILED) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 115 | |
| 116 | # The stop reason of the thread should be breakpoint. |
| 117 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
| 118 | substrs = ['stopped', |
| 119 | '* thread #1', |
| 120 | 'stop reason = breakpoint']) |
| 121 | |
| 122 | # Get the target process |
| 123 | target = self.dbg.GetSelectedTarget() |
| 124 | process = target.GetProcess() |
| 125 | |
| 126 | # Get the number of threads |
| 127 | num_threads = process.GetNumThreads() |
| 128 | |
| 129 | self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.') |
| 130 | |
| 131 | # Get the thread object |
| 132 | thread = process.GetThreadAtIndex(0) |
| 133 | |
| 134 | # Make sure the thread is in the stopped state. |
| 135 | self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' during breakpoint 1.") |
| 136 | self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' during breakpoint 1.") |
| 137 | |
| 138 | # Kill the process |
| 139 | self.runCmd("process kill") |
| 140 | |
| 141 | def thread_state_after_continue_test(self): |
| 142 | """Test thread state after continue.""" |
| 143 | exe = os.path.join(os.getcwd(), "a.out") |
| 144 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 145 | |
| 146 | # This should create a breakpoint in the main thread. |
| 147 | lldbutil.run_break_set_by_file_and_line (self, "main.c", self.break_1, num_expected_locations=1) |
| 148 | lldbutil.run_break_set_by_file_and_line (self, "main.c", self.break_2, num_expected_locations=1) |
| 149 | |
| 150 | # The breakpoint list should show 1 breakpoints with 1 location. |
| 151 | self.expect("breakpoint list -f", "Breakpoint location shown correctly", |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 152 | substrs = ["1: file = 'main.c', line = %d, exact_match = 0, locations = 1" % self.break_1]) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 153 | |
| 154 | # Run the program. |
Siva Chandra | 3154aa2 | 2015-05-27 22:27:41 +0000 | [diff] [blame] | 155 | self.runCmd("run", RUN_FAILED) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 156 | |
| 157 | # The stop reason of the thread should be breakpoint. |
| 158 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
| 159 | substrs = ['stopped', |
| 160 | '* thread #1', |
| 161 | 'stop reason = breakpoint']) |
| 162 | |
| 163 | # Get the target process |
| 164 | target = self.dbg.GetSelectedTarget() |
| 165 | process = target.GetProcess() |
| 166 | |
| 167 | # Get the number of threads |
| 168 | num_threads = process.GetNumThreads() |
| 169 | |
| 170 | self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.') |
| 171 | |
| 172 | # Get the thread object |
| 173 | thread = process.GetThreadAtIndex(0) |
| 174 | |
| 175 | # Continue, the inferior will go into an infinite loop waiting for 'g_test' to change. |
| 176 | self.dbg.SetAsync(True) |
| 177 | self.runCmd("continue") |
| 178 | time.sleep(1) |
| 179 | |
| 180 | # Check the thread state. It should be running. |
| 181 | self.assertFalse(thread.IsStopped(), "Thread state is \'stopped\' when it should be running.") |
| 182 | self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' when it should be running.") |
| 183 | |
| 184 | # Go back to synchronous interactions |
| 185 | self.dbg.SetAsync(False) |
| 186 | |
| 187 | # Kill the process |
| 188 | self.runCmd("process kill") |
| 189 | |
| 190 | def thread_state_after_expression_test(self): |
| 191 | """Test thread state after expression.""" |
| 192 | exe = os.path.join(os.getcwd(), "a.out") |
| 193 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 194 | |
| 195 | # This should create a breakpoint in the main thread. |
| 196 | lldbutil.run_break_set_by_file_and_line (self, "main.c", self.break_1, num_expected_locations=1) |
| 197 | lldbutil.run_break_set_by_file_and_line (self, "main.c", self.break_2, num_expected_locations=1) |
| 198 | |
| 199 | # The breakpoint list should show 1 breakpoints with 1 location. |
| 200 | self.expect("breakpoint list -f", "Breakpoint location shown correctly", |
Matt Kopec | 36e5a7d | 2013-06-17 19:00:31 +0000 | [diff] [blame] | 201 | substrs = ["1: file = 'main.c', line = %d, locations = 1" % self.break_1]) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 202 | |
| 203 | # Run the program. |
Siva Chandra | 3154aa2 | 2015-05-27 22:27:41 +0000 | [diff] [blame] | 204 | self.runCmd("run", RUN_FAILED) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 205 | |
| 206 | # The stop reason of the thread should be breakpoint. |
| 207 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
| 208 | substrs = ['stopped', |
| 209 | '* thread #1', |
| 210 | 'stop reason = breakpoint']) |
| 211 | |
| 212 | # Get the target process |
| 213 | target = self.dbg.GetSelectedTarget() |
| 214 | process = target.GetProcess() |
| 215 | |
| 216 | # Get the number of threads |
| 217 | num_threads = process.GetNumThreads() |
| 218 | |
| 219 | self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.') |
| 220 | |
| 221 | # Get the thread object |
| 222 | thread = process.GetThreadAtIndex(0) |
| 223 | |
| 224 | # Get the inferior out of its loop |
| 225 | self.runCmd("expression g_test = 1") |
| 226 | |
| 227 | # Check the thread state |
| 228 | self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' after expression evaluation.") |
| 229 | self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' after expression evaluation.") |
| 230 | |
| 231 | # Let the process run to completion |
| 232 | self.runCmd("process continue") |
| 233 | |
| 234 | |
| 235 | def process_interrupt_test(self): |
| 236 | """Test process interrupt and continue.""" |
| 237 | exe = os.path.join(os.getcwd(), "a.out") |
| 238 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 239 | |
| 240 | # This should create a breakpoint in the main thread. |
| 241 | lldbutil.run_break_set_by_file_and_line (self, "main.c", self.break_1, num_expected_locations=1) |
| 242 | |
| 243 | # The breakpoint list should show 1 breakpoints with 1 location. |
| 244 | self.expect("breakpoint list -f", "Breakpoint location shown correctly", |
Matt Kopec | 36e5a7d | 2013-06-17 19:00:31 +0000 | [diff] [blame] | 245 | substrs = ["1: file = 'main.c', line = %d, locations = 1" % self.break_1]) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 246 | |
| 247 | # Run the program. |
Siva Chandra | 3154aa2 | 2015-05-27 22:27:41 +0000 | [diff] [blame] | 248 | self.runCmd("run", RUN_FAILED) |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 249 | |
| 250 | # The stop reason of the thread should be breakpoint. |
| 251 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
| 252 | substrs = ['stopped', |
| 253 | '* thread #1', |
| 254 | 'stop reason = breakpoint']) |
| 255 | |
| 256 | # Get the target process |
| 257 | target = self.dbg.GetSelectedTarget() |
| 258 | process = target.GetProcess() |
| 259 | |
| 260 | # Get the number of threads |
| 261 | num_threads = process.GetNumThreads() |
| 262 | |
| 263 | self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.') |
| 264 | |
| 265 | # Continue, the inferior will go into an infinite loop waiting for 'g_test' to change. |
| 266 | self.dbg.SetAsync(True) |
| 267 | self.runCmd("continue") |
| 268 | time.sleep(1) |
| 269 | |
| 270 | # Go back to synchronous interactions |
| 271 | self.dbg.SetAsync(False) |
| 272 | |
| 273 | # Stop the process |
| 274 | self.runCmd("process interrupt") |
| 275 | |
| 276 | # The stop reason of the thread should be signal. |
| 277 | self.expect("process status", STOPPED_DUE_TO_SIGNAL, |
| 278 | substrs = ['stopped', |
| 279 | '* thread #1', |
| 280 | 'stop reason = signal']) |
| 281 | |
| 282 | # Get the inferior out of its loop |
| 283 | self.runCmd("expression g_test = 1") |
| 284 | |
| 285 | # Run to completion |
| 286 | self.runCmd("continue") |
| 287 | |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 288 | def thread_states_test(self): |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 289 | """Test thread states (comprehensive).""" |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 290 | exe = os.path.join(os.getcwd(), "a.out") |
| 291 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 292 | |
| 293 | # This should create a breakpoint in the main thread. |
| 294 | lldbutil.run_break_set_by_file_and_line (self, "main.c", self.break_1, num_expected_locations=1) |
| 295 | lldbutil.run_break_set_by_file_and_line (self, "main.c", self.break_2, num_expected_locations=1) |
| 296 | |
| 297 | # The breakpoint list should show 2 breakpoints with 1 location each. |
| 298 | self.expect("breakpoint list -f", "Breakpoint location shown correctly", |
Matt Kopec | 36e5a7d | 2013-06-17 19:00:31 +0000 | [diff] [blame] | 299 | substrs = ["1: file = 'main.c', line = %d, locations = 1" % self.break_1, |
| 300 | "2: file = 'main.c', line = %d, locations = 1" % self.break_2]) |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 301 | |
| 302 | # Run the program. |
Siva Chandra | 3154aa2 | 2015-05-27 22:27:41 +0000 | [diff] [blame] | 303 | self.runCmd("run", RUN_FAILED) |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 304 | |
| 305 | # The stop reason of the thread should be breakpoint. |
| 306 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
| 307 | substrs = ['stopped', |
| 308 | '* thread #1', |
| 309 | 'stop reason = breakpoint']) |
| 310 | |
| 311 | # Get the target process |
| 312 | target = self.dbg.GetSelectedTarget() |
| 313 | process = target.GetProcess() |
| 314 | |
| 315 | # Get the number of threads |
| 316 | num_threads = process.GetNumThreads() |
| 317 | |
| 318 | self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.') |
| 319 | |
| 320 | # Get the thread object |
| 321 | thread = process.GetThreadAtIndex(0) |
| 322 | |
| 323 | # Make sure the thread is in the stopped state. |
| 324 | self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' during breakpoint 1.") |
| 325 | self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' during breakpoint 1.") |
| 326 | |
| 327 | # Continue, the inferior will go into an infinite loop waiting for 'g_test' to change. |
| 328 | self.dbg.SetAsync(True) |
| 329 | self.runCmd("continue") |
| 330 | time.sleep(1) |
| 331 | |
| 332 | # Check the thread state. It should be running. |
| 333 | self.assertFalse(thread.IsStopped(), "Thread state is \'stopped\' when it should be running.") |
| 334 | self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' when it should be running.") |
| 335 | |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 336 | # Go back to synchronous interactions |
| 337 | self.dbg.SetAsync(False) |
| 338 | |
| 339 | # Stop the process |
| 340 | self.runCmd("process interrupt") |
| 341 | |
| 342 | # The stop reason of the thread should be signal. |
| 343 | self.expect("process status", STOPPED_DUE_TO_SIGNAL, |
| 344 | substrs = ['stopped', |
| 345 | '* thread #1', |
| 346 | 'stop reason = signal']) |
| 347 | |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 348 | # Check the thread state |
| 349 | self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' after process stop.") |
| 350 | self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' after process stop.") |
| 351 | |
| 352 | # Get the inferior out of its loop |
| 353 | self.runCmd("expression g_test = 1") |
| 354 | |
| 355 | # Check the thread state |
| 356 | self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' after expression evaluation.") |
| 357 | self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' after expression evaluation.") |
| 358 | |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 359 | # The stop reason of the thread should be signal. |
| 360 | self.expect("process status", STOPPED_DUE_TO_SIGNAL, |
| 361 | substrs = ['stopped', |
| 362 | '* thread #1', |
| 363 | 'stop reason = signal']) |
| 364 | |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 365 | # Run to breakpoint 2 |
| 366 | self.runCmd("continue") |
| 367 | |
Andrew Kaylor | 9f6c535 | 2013-04-30 23:39:14 +0000 | [diff] [blame] | 368 | # The stop reason of the thread should be breakpoint. |
| 369 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
| 370 | substrs = ['stopped', |
| 371 | '* thread #1', |
| 372 | 'stop reason = breakpoint']) |
| 373 | |
Andrew Kaylor | dbbe36b | 2013-04-23 21:42:03 +0000 | [diff] [blame] | 374 | # Make sure both threads are stopped |
| 375 | self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' during breakpoint 2.") |
| 376 | self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' during breakpoint 2.") |
| 377 | |
| 378 | # Run to completion |
| 379 | self.runCmd("continue") |
| 380 | |
| 381 | # At this point, the inferior process should have exited. |
| 382 | self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED) |
| 383 | |
| 384 | if __name__ == '__main__': |
| 385 | import atexit |
| 386 | lldb.SBDebugger.Initialize() |
| 387 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 388 | unittest2.main() |