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