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