diff options
author | Zachary Turner <zturner@google.com> | 2016-01-21 21:07:30 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-01-21 21:07:30 +0000 |
commit | 783550be6211b65de45c4c44eac339311f3ae1e2 (patch) | |
tree | 4827f9b6759311267e2f86d95c6426f76d6b6ae6 /lldb/packages/Python/lldbsuite/test | |
parent | bef81f3a70028699965700e6b77dcb8952abcc85 (diff) | |
download | bcm5719-llvm-783550be6211b65de45c4c44eac339311f3ae1e2.tar.gz bcm5719-llvm-783550be6211b65de45c4c44eac339311f3ae1e2.zip |
Remove assumptions that thread 0 is always the main thread.
Starting with Windows 10, the Windows loader is itself multi-threaded,
meaning that the loader spins up a few threads to do process
initialization before it executes main. Windows delivers these
notifications asynchronously and they can come out of order, so
we can't be sure that the first thread we get a notification about
is actually the zero'th thread.
This patch fixes this by requesting the thread stopped at the
breakpoint that was specified, rather than getting thread 0 and
verifying that it is stopped at a breakpoint.
Differential Revision: http://reviews.llvm.org/D16247
llvm-svn: 258432
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
18 files changed, 72 insertions, 147 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py b/lldb/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py index ec3e7f93af2..ad0df7367ee 100644 --- a/lldb/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py +++ b/lldb/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py @@ -130,12 +130,8 @@ class BasicExprCommandsTestCase(TestBase): "instead the actual state is: '%s'" % lldbutil.state_type_to_str(process.GetState())) - # The stop reason of the thread should be breakpoint. - thread = process.GetThreadAtIndex(0) - if thread.GetStopReason() != lldb.eStopReasonBreakpoint: - from lldbsuite.test.lldbutil import stop_reason_to_str - self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % - stop_reason_to_str(thread.GetStopReason())) + thread = lldbutil.get_one_thread_stopped_at_breakpoint(process, breakpoint) + self.assertIsNotNone(thread, "Expected one thread to be stopped at the breakpoint") # The filename of frame #0 should be 'main.cpp' and function is main. self.expect(lldbutil.get_filenames(thread)[0], diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoins/TestConsecutiveBreakpoints.py b/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoins/TestConsecutiveBreakpoints.py index af6df376482..1a3b26f4548 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoins/TestConsecutiveBreakpoints.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoins/TestConsecutiveBreakpoints.py @@ -27,7 +27,7 @@ class ConsecutiveBreakpoitsTestCase(TestBase): target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) - breakpoint = target.BreakpointCreateBySourceRegex("Set breakpoint here", lldb.SBFileSpec("main.cpp")) + breakpoint1 = target.BreakpointCreateBySourceRegex("Set breakpoint here", lldb.SBFileSpec("main.cpp")) self.assertTrue(breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT) @@ -37,8 +37,8 @@ class ConsecutiveBreakpoitsTestCase(TestBase): self.assertTrue(process, PROCESS_IS_VALID) # We should be stopped at the first breakpoint - thread = process.GetThreadAtIndex(0) - self.assertEqual(thread.GetStopReason(), lldb.eStopReasonBreakpoint) + thread = lldbutil.get_one_thread_stopped_at_breakpoint(process, breakpoint1) + self.assertIsNotNone(thread, "Expected one thread to be stopped at breakpoint 1") # Set breakpoint to the next instruction frame = thread.GetFrameAtIndex(0) @@ -48,12 +48,12 @@ class ConsecutiveBreakpoitsTestCase(TestBase): self.assertTrue(len(instructions) == 2) address = instructions[1].GetAddress() - target.BreakpointCreateByAddress(address.GetLoadAddress(target)) + breakpoint2 = target.BreakpointCreateByAddress(address.GetLoadAddress(target)) process.Continue() # We should be stopped at the second breakpoint - thread = process.GetThreadAtIndex(0) - self.assertEqual(thread.GetStopReason(), lldb.eStopReasonBreakpoint) + thread = lldbutil.get_one_thread_stopped_at_breakpoint(process, breakpoint2) + self.assertIsNotNone(thread, "Expected one thread to be stopped at breakpoint 2") # Run the process until termination process.Continue() diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/conditional_break/TestConditionalBreak.py b/lldb/packages/Python/lldbsuite/test/functionalities/conditional_break/TestConditionalBreak.py index 3ae7a20b4c7..cfd20f07323 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/conditional_break/TestConditionalBreak.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/conditional_break/TestConditionalBreak.py @@ -64,7 +64,8 @@ class ConditionalBreakTestCase(TestBase): for j in range(10): if self.TraceOn(): print("j is: ", j) - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_one_thread_stopped_at_breakpoint(process, breakpoint) + self.assertIsNotNone(thread, "Expected one thread to be stopped at the breakpoint") if thread.GetNumFrames() >= 2: frame0 = thread.GetFrameAtIndex(0) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py b/lldb/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py index 24b5bf0dad3..7bb1564e082 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py @@ -38,11 +38,8 @@ class CreateDuringStepTestCase(TestBase): # The stop reason should be breakpoint. self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) - self.assertEqual(lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint).IsValid(), 1, - STOPPED_DUE_TO_BREAKPOINT) - - thread = process.GetThreadAtIndex(0) - self.assertTrue(thread and thread.IsValid(), "Thread is valid") + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid(), STOPPED_DUE_TO_BREAKPOINT) # Keep stepping until the inferior crashes while process.GetState() == lldb.eStateStopped and not lldbutil.is_thread_crashed(self, thread): diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/thread/multi_break/TestMultipleBreakpoints.py b/lldb/packages/Python/lldbsuite/test/functionalities/thread/multi_break/TestMultipleBreakpoints.py index 9dd21241221..65d9bfdb5ca 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/thread/multi_break/TestMultipleBreakpoints.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/thread/multi_break/TestMultipleBreakpoints.py @@ -55,7 +55,7 @@ class MultipleBreakpointTestCase(TestBase): num_threads = process.GetNumThreads() # Make sure we see all three threads - self.assertTrue(num_threads == 3, 'Number of expected threads and actual threads do not match.') + self.assertTrue(num_threads >= 3, 'Number of expected threads and actual threads do not match.') # Get the thread objects thread1 = process.GetThreadAtIndex(0) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py b/lldb/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py index 4938ec50453..11912c67be4 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py @@ -69,28 +69,17 @@ class ThreadStateTestCase(TestBase): self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # This should create a breakpoint in the main thread. - lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_1, num_expected_locations=1) + bp = lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.break_1, num_expected_locations=1) # Run the program. self.runCmd("run", RUN_SUCCEEDED) - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs = ['stopped', - '* thread #1', - 'stop reason = breakpoint']) - # Get the target process target = self.dbg.GetSelectedTarget() process = target.GetProcess() - # Get the number of threads - num_threads = process.GetNumThreads() - - self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.') - - # Get the thread object - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # Make sure the thread is in the stopped state. self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' during breakpoint 1.") @@ -117,23 +106,12 @@ class ThreadStateTestCase(TestBase): # Run the program. self.runCmd("run", RUN_SUCCEEDED) - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs = ['stopped', - '* thread #1', - 'stop reason = breakpoint']) - # Get the target process target = self.dbg.GetSelectedTarget() process = target.GetProcess() - # Get the number of threads - num_threads = process.GetNumThreads() - - self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.') - - # Get the thread object - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # Continue, the inferior will go into an infinite loop waiting for 'g_test' to change. self.dbg.SetAsync(True) @@ -162,23 +140,12 @@ class ThreadStateTestCase(TestBase): # Run the program. self.runCmd("run", RUN_SUCCEEDED) - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs = ['stopped', - '* thread #1', - 'stop reason = breakpoint']) - # Get the target process target = self.dbg.GetSelectedTarget() process = target.GetProcess() - # Get the number of threads - num_threads = process.GetNumThreads() - - self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.') - - # Get the thread object - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # Get the inferior out of its loop self.runCmd("expression g_test = 1") @@ -202,20 +169,12 @@ class ThreadStateTestCase(TestBase): # Run the program. self.runCmd("run", RUN_SUCCEEDED) - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs = ['stopped', - '* thread #1', - 'stop reason = breakpoint']) - # Get the target process target = self.dbg.GetSelectedTarget() process = target.GetProcess() - # Get the number of threads - num_threads = process.GetNumThreads() - - self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.') + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # Continue, the inferior will go into an infinite loop waiting for 'g_test' to change. self.dbg.SetAsync(True) @@ -228,11 +187,7 @@ class ThreadStateTestCase(TestBase): # Stop the process self.runCmd("process interrupt") - # The stop reason of the thread should be signal. - self.expect("process status", STOPPED_DUE_TO_SIGNAL, - substrs = ['stopped', - '* thread #1', - 'stop reason = signal']) + self.assertEqual(thread.GetStopReason(), lldb.eStopReasonSignal) # Get the inferior out of its loop self.runCmd("expression g_test = 1") @@ -252,23 +207,11 @@ class ThreadStateTestCase(TestBase): # Run the program. self.runCmd("run", RUN_SUCCEEDED) - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs = ['stopped', - '* thread #1', - 'stop reason = breakpoint']) - # Get the target process target = self.dbg.GetSelectedTarget() process = target.GetProcess() - - # Get the number of threads - num_threads = process.GetNumThreads() - - self.assertTrue(num_threads == 1, 'Number of expected threads and actual threads do not match.') - - # Get the thread object - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # Make sure the thread is in the stopped state. self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' during breakpoint 1.") @@ -289,11 +232,7 @@ class ThreadStateTestCase(TestBase): # Stop the process self.runCmd("process interrupt") - # The stop reason of the thread should be signal. - self.expect("process status", STOPPED_DUE_TO_SIGNAL, - substrs = ['stopped', - '* thread #1', - 'stop reason = signal']) + self.assertEqual(thread.GetState(), lldb.eStopReasonSignal) # Check the thread state self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' after process stop.") @@ -306,20 +245,12 @@ class ThreadStateTestCase(TestBase): self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' after expression evaluation.") self.assertFalse(thread.IsSuspended(), "Thread state is \'suspended\' after expression evaluation.") - # The stop reason of the thread should be signal. - self.expect("process status", STOPPED_DUE_TO_SIGNAL, - substrs = ['stopped', - '* thread #1', - 'stop reason = signal']) + self.assertEqual(thread.GetState(), lldb.eStopReasonSignal) # Run to breakpoint 2 self.runCmd("continue") - # The stop reason of the thread should be breakpoint. - self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs = ['stopped', - '* thread #1', - 'stop reason = breakpoint']) + self.assertEqual(thread.GetState(), lldb.eStopReasonBreakpoint) # Make sure both threads are stopped self.assertTrue(thread.IsStopped(), "Thread state isn't \'stopped\' during breakpoint 2.") @@ -329,4 +260,4 @@ class ThreadStateTestCase(TestBase): self.runCmd("continue") # At this point, the inferior process should have exited. - self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED) + self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED) diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/array_types/TestArrayTypes.py b/lldb/packages/Python/lldbsuite/test/lang/c/array_types/TestArrayTypes.py index e835fb09649..c8bc3f45f31 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/c/array_types/TestArrayTypes.py +++ b/lldb/packages/Python/lldbsuite/test/lang/c/array_types/TestArrayTypes.py @@ -100,11 +100,8 @@ class ArrayTypesTestCase(TestBase): "executable = a.out"]) # The stop reason of the thread should be breakpoint. - thread = process.GetThreadAtIndex(0) - if thread.GetStopReason() != lldb.eStopReasonBreakpoint: - from lldbsuite.test.lldbutil import stop_reason_to_str - self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % - stop_reason_to_str(thread.GetStopReason())) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # Sanity check the print representation of thread. thr = str(thread) @@ -120,7 +117,7 @@ class ArrayTypesTestCase(TestBase): substrs = [tidstr]) # The breakpoint should have a hit count of 1. - self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE) + self.assertEqual(breakpoint.GetHitCount(), 1, BREAKPOINT_HIT_ONCE) # The breakpoint should be resolved by now. bp = str(breakpoint) diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py b/lldb/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py index de7a333a18f..30ed73b5205 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py +++ b/lldb/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py @@ -112,14 +112,11 @@ class BitfieldsTestCase(TestBase): self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. - thread = target.GetProcess().GetThreadAtIndex(0) - if thread.GetStopReason() != lldb.eStopReasonBreakpoint: - from lldbsuite.test.lldbutil import stop_reason_to_str - self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % - stop_reason_to_str(thread.GetStopReason())) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # The breakpoint should have a hit count of 1. - self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE) + self.assertEqual(breakpoint.GetHitCount(), 1, BREAKPOINT_HIT_ONCE) # Lookup the "bits" variable which contains 8 bitfields. frame = thread.GetFrameAtIndex(0) diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py index d47d1b7dde4..9df6b123fce 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py @@ -69,11 +69,8 @@ class StaticVariableTestCase(TestBase): self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. - thread = process.GetThreadAtIndex(0) - if thread.GetStopReason() != lldb.eStopReasonBreakpoint: - from lldbsuite.test.lldbutil import stop_reason_to_str - self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % - stop_reason_to_str(thread.GetStopReason())) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # Get the SBValue of 'A::g_points' and 'g_points'. frame = thread.GetFrameAtIndex(0) diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py index b67e53c3074..7b89a911e08 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py @@ -92,11 +92,8 @@ class ClassTypesTestCase(TestBase): lldbutil.state_type_to_str(process.GetState())) # The stop reason of the thread should be breakpoint. - thread = process.GetThreadAtIndex(0) - if thread.GetStopReason() != lldb.eStopReasonBreakpoint: - from lldbsuite.test.lldbutil import stop_reason_to_str - self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % - stop_reason_to_str(thread.GetStopReason())) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # The filename of frame #0 should be 'main.cpp' and the line number # should be 93. @@ -203,11 +200,8 @@ class ClassTypesTestCase(TestBase): lldbutil.state_type_to_str(process.GetState())) # The stop reason of the thread should be breakpoint. - thread = process.GetThreadAtIndex(0) - if thread.GetStopReason() != lldb.eStopReasonBreakpoint: - from lldbsuite.test.lldbutil import stop_reason_to_str - self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % - stop_reason_to_str(thread.GetStopReason())) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) frame = thread.frames[0] self.assertTrue (frame.IsValid(), "Got a valid frame.") diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py index 595d075d518..a423ed3b23a 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py @@ -46,7 +46,8 @@ class IterateFrameAndDisassembleTestCase(TestBase): # disassemble it. target = self.dbg.GetSelectedTarget() process = target.GetProcess() - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) depth = thread.GetNumFrames() for i in range(depth - 1): frame = thread.GetFrameAtIndex(i) diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py index 67de03b54b2..d525e12b31e 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py @@ -20,7 +20,8 @@ class CPPTestDiamondInheritance(TestBase): self.set_breakpoint(line_number('main.cpp', '// breakpoint 2')) process = target.LaunchSimple (None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) frame = thread.GetFrameAtIndex(0) j1 = frame.FindVariable("j1") j1_Derived1 = j1.GetChildAtIndex(0) diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py index d7435c46727..865516de4ed 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py @@ -51,7 +51,8 @@ class StdCXXDisassembleTestCase(TestBase): # Disassemble the functions on the call stack. self.runCmd("thread backtrace") - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) depth = thread.GetNumFrames() for i in range(depth - 1): frame = thread.GetFrameAtIndex(i) diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py index 339619dc4f7..a5d5f7356b1 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py @@ -566,6 +566,15 @@ def get_threads_stopped_at_breakpoint (process, bkpt): return threads +def get_one_thread_stopped_at_breakpoint(process, bkpt, require_exactly_one = True): + threads = get_threads_stopped_at_breakpoint(process, bkpt) + if len(threads) == 0: + return None + if require_exactly_one and len(threads) != 1: + return None + + return threads[0] + def is_thread_crashed (test, thread): """In the test suite we dereference a null pointer to simulate a crash. The way this is reported depends on the platform.""" diff --git a/lldb/packages/Python/lldbsuite/test/python_api/frame/TestFrames.py b/lldb/packages/Python/lldbsuite/test/python_api/frame/TestFrames.py index 7cc976fc6aa..d9c81eb7a54 100644 --- a/lldb/packages/Python/lldbsuite/test/python_api/frame/TestFrames.py +++ b/lldb/packages/Python/lldbsuite/test/python_api/frame/TestFrames.py @@ -49,7 +49,8 @@ class FrameAPITestCase(TestBase): from six import StringIO as SixStringIO session = SixStringIO() while process.GetState() == lldb.eStateStopped: - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # Inspect at most 3 frames. numFrames = min(3, thread.GetNumFrames()) for i in range(numFrames): @@ -134,7 +135,8 @@ class FrameAPITestCase(TestBase): self.assertTrue(process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) - thread = process.GetThreadAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) frame = thread.GetFrameAtIndex(0) if self.TraceOn(): print("frame:", frame) @@ -173,8 +175,8 @@ class FrameAPITestCase(TestBase): self.assertTrue(process.GetState() == lldb.eStateStopped, PROCESS_STOPPED) - thread = process.GetThreadAtIndex(0) - self.assertTrue(thread) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) frameEntered = thread.GetFrameAtIndex(0) if self.TraceOn(): diff --git a/lldb/packages/Python/lldbsuite/test/python_api/frame/inlines/TestInlinedFrame.py b/lldb/packages/Python/lldbsuite/test/python_api/frame/inlines/TestInlinedFrame.py index d4cf8fe30cc..f66dcd0389c 100644 --- a/lldb/packages/Python/lldbsuite/test/python_api/frame/inlines/TestInlinedFrame.py +++ b/lldb/packages/Python/lldbsuite/test/python_api/frame/inlines/TestInlinedFrame.py @@ -60,7 +60,10 @@ class InlinedFrameAPITestCase(TestBase): # # outer_inline (argc); # - frame0 = process.GetThreadAtIndex(0).GetFrameAtIndex(0) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) + + frame0 = thread.GetFrameAtIndex(0) if frame0.IsInlined(): filename = frame0.GetLineEntry().GetFileSpec().GetFilename() self.assertTrue(filename == self.source) diff --git a/lldb/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py b/lldb/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py index 31e80d4ab64..1b089a91169 100644 --- a/lldb/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py +++ b/lldb/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py @@ -64,14 +64,11 @@ class HelloWorldTestCase(TestBase): process = target.GetProcess() self.assertTrue(process, PROCESS_IS_VALID) - thread = process.GetThreadAtIndex(0) - if thread.GetStopReason() != lldb.eStopReasonBreakpoint: - from lldbsuite.test.lldbutil import stop_reason_to_str - self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS % - stop_reason_to_str(thread.GetStopReason())) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) # The breakpoint should have a hit count of 1. - self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE) + self.assertEqual(breakpoint.GetHitCount(), 1, BREAKPOINT_HIT_ONCE) @add_test_categories(['pyapi']) @expectedFailureWindows("llvm.org/pr24600") diff --git a/lldb/packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py b/lldb/packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py index 2ff516e10d8..4bb2b3b41be 100644 --- a/lldb/packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py +++ b/lldb/packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py @@ -38,8 +38,9 @@ class SBDataAPICase(TestBase): target = self.dbg.GetSelectedTarget() process = target.GetProcess() - - thread = process.GetThreadAtIndex(0) + + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertIsNotNone(thread) frame = thread.GetSelectedFrame() if self.TraceOn(): |