1"""
2Test that we obey thread conditioned breakpoints and expression
3conditioned breakpoints simultaneously
4"""
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class ThreadSpecificBreakPlusConditionTestCase(TestBase):
14    # test frequently times out or hangs
15    @skipIfDarwin
16    # hits break in another thread in testrun
17    @add_test_categories(["pyapi"])
18    @expectedFlakeyNetBSD
19    @skipIfWindows  # This test is flaky on Windows
20    def test_python(self):
21        """Test that we obey thread conditioned breakpoints."""
22        self.build()
23        exe = self.getBuildArtifact("a.out")
24
25        target = self.dbg.CreateTarget(exe)
26        self.assertTrue(target, VALID_TARGET)
27
28        main_source_spec = lldb.SBFileSpec("main.cpp")
29
30        # Set a breakpoint in the thread body, and make it active for only the
31        # first thread.
32        break_thread_body = target.BreakpointCreateBySourceRegex(
33            "Break here in thread body.", main_source_spec
34        )
35        self.assertTrue(
36            break_thread_body.IsValid() and break_thread_body.GetNumLocations() > 0,
37            "Failed to set thread body breakpoint.",
38        )
39
40        process = target.LaunchSimple(None, None, self.get_process_working_directory())
41
42        self.assertTrue(process, PROCESS_IS_VALID)
43
44        threads = lldbutil.get_threads_stopped_at_breakpoint(process, break_thread_body)
45
46        victim_thread = threads[0]
47
48        # Pick one of the threads, and change the breakpoint so it ONLY stops for this thread,
49        # but add a condition that it won't stop for this thread's my_value.  The other threads
50        # pass the condition, so they should stop, but if the thread-specification is working
51        # they should not stop.  So nobody should hit the breakpoint anymore, and we should
52        # just exit cleanly.
53
54        frame = victim_thread.GetFrameAtIndex(0)
55        value = frame.FindVariable("my_value").GetValueAsSigned(0)
56        self.assertTrue(
57            value > 0 and value < 11, "Got a reasonable value for my_value."
58        )
59
60        cond_string = "my_value != %d" % (value)
61
62        break_thread_body.SetThreadID(victim_thread.GetThreadID())
63        break_thread_body.SetCondition(cond_string)
64
65        process.Continue()
66
67        next_stop_state = process.GetState()
68        self.assertEqual(
69            next_stop_state,
70            lldb.eStateExited,
71            "We should have not hit the breakpoint again.",
72        )
73