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 @skipIfWindows 16 @expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr48415") 17 @expectedFlakeyNetBSD 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.assertSuccess(result.GetError(), "Expression failed") 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