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