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