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