1""" 2Make sure the stop reason of a thread that did not run 3during an expression is not changed by running the expression 4""" 5 6 7 8import lldb 9import lldbsuite.test.lldbutil as lldbutil 10from lldbsuite.test.lldbtest import * 11from lldbsuite.test.decorators import * 12 13class TestStopReasonAfterExpression(TestBase): 14 15 mydir = TestBase.compute_mydir(__file__) 16 17 @skipIfWindows 18 def test_thread_state_after_expr(self): 19 self.build() 20 self.main_source_file = lldb.SBFileSpec("main.cpp") 21 self.do_test() 22 23 def do_test(self): 24 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, 25 "Set a breakpoint here", self.main_source_file) 26 27 self.assertEqual(bkpt.GetNumLocations(), 2, "Got two locations") 28 29 # So now thread holds the main thread. Continue to hit the 30 # breakpoint again on the spawned thread: 31 32 threads = lldbutil.continue_to_breakpoint(process, bkpt) 33 self.assertEqual(len(threads), 1, "Hit the breakpoint the second time") 34 other_thread = threads[0] 35 36 self.assertNotEqual(thread.GetThreadID(), other_thread.GetThreadID(), 37 "A different thread") 38 # Run an expression ONLY on other_thread. Don't let thread run: 39 options = lldb.SBExpressionOptions() 40 options.SetTryAllThreads(False) 41 options.SetStopOthers(True) 42 43 result = thread.frames[0].EvaluateExpression('(int) printf("Hello\\n")', options) 44 self.assertTrue(result.GetError().Success(), 45 "Expression failed: '%s'"%(result.GetError().GetCString())) 46 47 stop_reason = other_thread.GetStopReason() 48 49 self.assertEqual(stop_reason, lldb.eStopReasonBreakpoint, 50 "Still records stopped at breakpoint: %s" 51 %(lldbutil.stop_reason_to_str(stop_reason))) 52 self.assertEqual(other_thread.GetStopReasonDataAtIndex(0), 1, 53 "Still records stopped at right breakpoint") 54 55