[Lldb-commits] [lldb] r258432 - Remove assumptions that thread 0 is always the main thread.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 21 13:07:31 PST 2016


Author: zturner
Date: Thu Jan 21 15:07:30 2016
New Revision: 258432

URL: http://llvm.org/viewvc/llvm-project?rev=258432&view=rev
Log:
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

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

Modified: lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/test/TestExprs.py Thu Jan 21 15:07:30 2016
@@ -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],

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoins/TestConsecutiveBreakpoints.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoins/TestConsecutiveBreakpoints.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoins/TestConsecutiveBreakpoints.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/consecutive_breakpoins/TestConsecutiveBreakpoints.py Thu Jan 21 15:07:30 2016
@@ -27,7 +27,7 @@ class ConsecutiveBreakpoitsTestCase(Test
         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(Test
         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(Test
         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()

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/conditional_break/TestConditionalBreak.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/conditional_break/TestConditionalBreak.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/conditional_break/TestConditionalBreak.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/conditional_break/TestConditionalBreak.py Thu Jan 21 15:07:30 2016
@@ -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)

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/crash_during_step/TestCrashDuringStep.py Thu Jan 21 15:07:30 2016
@@ -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):

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/multi_break/TestMultipleBreakpoints.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/multi_break/TestMultipleBreakpoints.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/multi_break/TestMultipleBreakpoints.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/multi_break/TestMultipleBreakpoints.py Thu Jan 21 15:07:30 2016
@@ -55,7 +55,7 @@ class MultipleBreakpointTestCase(TestBas
         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)

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/state/TestThreadStates.py Thu Jan 21 15:07:30 2016
@@ -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)

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/c/array_types/TestArrayTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/array_types/TestArrayTypes.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/array_types/TestArrayTypes.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/array_types/TestArrayTypes.py Thu Jan 21 15:07:30 2016
@@ -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)

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py Thu Jan 21 15:07:30 2016
@@ -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)

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class_static/TestStaticVariables.py Thu Jan 21 15:07:30 2016
@@ -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)

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypes.py Thu Jan 21 15:07:30 2016
@@ -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.")

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py Thu Jan 21 15:07:30 2016
@@ -46,7 +46,8 @@ class IterateFrameAndDisassembleTestCase
         # 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)

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/diamond/TestDiamond.py Thu Jan 21 15:07:30 2016
@@ -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)

Modified: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/stl/TestStdCXXDisassembly.py Thu Jan 21 15:07:30 2016
@@ -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)

Modified: lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py Thu Jan 21 15:07:30 2016
@@ -566,6 +566,15 @@ def get_threads_stopped_at_breakpoint (p
 
     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."""

Modified: lldb/trunk/packages/Python/lldbsuite/test/python_api/frame/TestFrames.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/python_api/frame/TestFrames.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/python_api/frame/TestFrames.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/python_api/frame/TestFrames.py Thu Jan 21 15:07:30 2016
@@ -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():

Modified: lldb/trunk/packages/Python/lldbsuite/test/python_api/frame/inlines/TestInlinedFrame.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/python_api/frame/inlines/TestInlinedFrame.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/python_api/frame/inlines/TestInlinedFrame.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/python_api/frame/inlines/TestInlinedFrame.py Thu Jan 21 15:07:30 2016
@@ -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)

Modified: lldb/trunk/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py Thu Jan 21 15:07:30 2016
@@ -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")

Modified: lldb/trunk/packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py?rev=258432&r1=258431&r2=258432&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/python_api/sbdata/TestSBData.py Thu Jan 21 15:07:30 2016
@@ -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():




More information about the lldb-commits mailing list