zturner created this revision.
zturner added a reviewer: jingham.
zturner added a subscriber: lldb-commits.

Even in a single-threaded app, Windows will often create background threads on 
startup and these threads can appear in any order with respect to the actual 
main thread.  So everywhere that is doing something like 
`process.GetThreadAtIndex(0)` in our test suite is broken on Windows.  This 
fixes a large number of these cases, although there are still a few more 
difficult ones remaining that I don't plan to address right now.

http://reviews.llvm.org/D16247

Files:
  packages/Python/lldbsuite/test/expression_command/test/TestExprs.py
  
packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoins/TestConsecutiveBreakpoints.py
  
packages/Python/lldbsuite/test/functionalities/conditional_break/TestConditionalBreak.py
  
packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py
  
packages/Python/lldbsuite/test/functionalities/thread/multi_break/TestMultipleBreakpoints.py
  
packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py
  packages/Python/lldbsuite/test/lang/c/array_types/TestArrayTypes.py
  packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py
  packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py
  packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py
  
packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py
  packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py
  packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py
  packages/Python/lldbsuite/test/python_api/frame/TestFrames.py
  packages/Python/lldbsuite/test/python_api/frame/inlines/TestInlinedFrame.py
  packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py
  packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py

Index: packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py
===================================================================
--- packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py
+++ packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py
@@ -38,8 +38,9 @@
         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():
Index: packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py
===================================================================
--- packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py
+++ packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py
@@ -64,14 +64,11 @@
         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")
Index: packages/Python/lldbsuite/test/python_api/frame/inlines/TestInlinedFrame.py
===================================================================
--- packages/Python/lldbsuite/test/python_api/frame/inlines/TestInlinedFrame.py
+++ packages/Python/lldbsuite/test/python_api/frame/inlines/TestInlinedFrame.py
@@ -60,7 +60,10 @@
         #
         #     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)
Index: packages/Python/lldbsuite/test/python_api/frame/TestFrames.py
===================================================================
--- packages/Python/lldbsuite/test/python_api/frame/TestFrames.py
+++ packages/Python/lldbsuite/test/python_api/frame/TestFrames.py
@@ -49,7 +49,8 @@
         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 @@
         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 @@
         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():
Index: packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py
+++ packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py
@@ -51,7 +51,8 @@
 
         # 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)
Index: packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py
+++ packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py
@@ -20,7 +20,8 @@
         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)
Index: packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py
+++ packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py
@@ -46,7 +46,8 @@
         # 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)
Index: packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py
+++ packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py
@@ -92,11 +92,8 @@
                       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 @@
                       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.")
Index: packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py
===================================================================
--- packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py
+++ packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py
@@ -69,11 +69,8 @@
         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)
Index: packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py
===================================================================
--- packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py
+++ packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py
@@ -112,14 +112,11 @@
         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)
Index: packages/Python/lldbsuite/test/lang/c/array_types/TestArrayTypes.py
===================================================================
--- packages/Python/lldbsuite/test/lang/c/array_types/TestArrayTypes.py
+++ packages/Python/lldbsuite/test/lang/c/array_types/TestArrayTypes.py
@@ -100,11 +100,8 @@
                        "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 @@
             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)
Index: packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py
+++ packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py
@@ -69,28 +69,17 @@
         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 @@
         # 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 @@
         # 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 @@
         # 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 @@
         # 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 @@
         # 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 @@
         # 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 @@
         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 @@
         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)
Index: packages/Python/lldbsuite/test/functionalities/thread/multi_break/TestMultipleBreakpoints.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/thread/multi_break/TestMultipleBreakpoints.py
+++ packages/Python/lldbsuite/test/functionalities/thread/multi_break/TestMultipleBreakpoints.py
@@ -55,7 +55,7 @@
         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)
Index: packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py
+++ packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py
@@ -38,11 +38,8 @@
 
         # 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):
Index: packages/Python/lldbsuite/test/functionalities/conditional_break/TestConditionalBreak.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/conditional_break/TestConditionalBreak.py
+++ packages/Python/lldbsuite/test/functionalities/conditional_break/TestConditionalBreak.py
@@ -64,7 +64,8 @@
         for j in range(10):
             if self.TraceOn():
                 print("j is: ", j)
-            thread = process.GetThreadAtIndex(0)
+            thread = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint)
+            self.assertIsNotNone(thread)
             
             if thread.GetNumFrames() >= 2:
                 frame0 = thread.GetFrameAtIndex(0)
Index: packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoins/TestConsecutiveBreakpoints.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoins/TestConsecutiveBreakpoints.py
+++ packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoins/TestConsecutiveBreakpoints.py
@@ -27,7 +27,7 @@
         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,7 @@
         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_threads_stopped_at_breakpoint(process, breakpoint)
 
         # Set breakpoint to the next instruction
         frame = thread.GetFrameAtIndex(0)
@@ -48,12 +47,12 @@
         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_threads_stopped_at_breakpoint(process, breakpoint2)
+        self.assertIsNotNone(thread)
 
         # Run the process until termination
         process.Continue()
Index: packages/Python/lldbsuite/test/expression_command/test/TestExprs.py
===================================================================
--- packages/Python/lldbsuite/test/expression_command/test/TestExprs.py
+++ packages/Python/lldbsuite/test/expression_command/test/TestExprs.py
@@ -130,12 +130,8 @@
                       "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_threads_stopped_at_breakpoint(process, breakpoint)
+        self.assertIsNotNone(thread, "Could not find thread stopped at breakpoint")
 
         # The filename of frame #0 should be 'main.cpp' and function is main.
         self.expect(lldbutil.get_filenames(thread)[0],
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to