2 Test that we obey thread conditioned breakpoints.
5 from __future__ import print_function
12 from lldbsuite.test.decorators import *
13 from lldbsuite.test.lldbtest import *
14 from lldbsuite.test import lldbutil
16 class ThreadSpecificBreakTestCase(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
20 @add_test_categories(['pyapi'])
21 @expectedFailureAll(oslist=["windows"])
22 def test_python(self):
23 """Test that we obey thread conditioned breakpoints."""
25 exe = os.path.join(os.getcwd(), "a.out")
27 target = self.dbg.CreateTarget(exe)
28 self.assertTrue(target, VALID_TARGET)
30 # This test works by setting a breakpoint in a function conditioned to stop only on
31 # the main thread, and then calling this function on a secondary thread, joining,
32 # and then calling again on the main thread. If the thread specific breakpoint works
33 # then it should not be hit on the secondary thread, only on the main thread.
35 main_source_spec = lldb.SBFileSpec ("main.cpp")
37 main_breakpoint = target.BreakpointCreateBySourceRegex("Set main breakpoint here", main_source_spec);
38 thread_breakpoint = target.BreakpointCreateBySourceRegex("Set thread-specific breakpoint here", main_source_spec)
40 self.assertTrue(main_breakpoint.IsValid(), "Failed to set main breakpoint.")
41 self.assertGreater(main_breakpoint.GetNumLocations(), 0, "main breakpoint has no locations associated with it.")
42 self.assertTrue(thread_breakpoint.IsValid(), "Failed to set thread breakpoint.")
43 self.assertGreater(thread_breakpoint.GetNumLocations(), 0, "thread breakpoint has no locations associated with it.")
45 process = target.LaunchSimple (None, None, self.get_process_working_directory())
47 self.assertTrue(process, PROCESS_IS_VALID)
49 stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(process, main_breakpoint)
50 self.assertEqual(len(stopped_threads), 1, "main breakpoint stopped at unexpected number of threads")
51 main_thread = stopped_threads[0]
52 main_thread_id = main_thread.GetThreadID()
54 # Set the thread-specific breakpoint to only stop on the main thread. The run the function
55 # on another thread and join on it. If the thread-specific breakpoint works, the next
56 # stop should be on the main thread.
57 thread_breakpoint.SetThreadID(main_thread_id)
60 next_stop_state = process.GetState()
61 self.assertEqual(next_stop_state, lldb.eStateStopped, "We should have stopped at the thread breakpoint.")
62 stopped_threads = lldbutil.get_threads_stopped_at_breakpoint(process, thread_breakpoint)
63 self.assertEqual(len(stopped_threads), 1, "thread breakpoint stopped at unexpected number of threads")
64 self.assertEqual(stopped_threads[0].GetThreadID(), main_thread_id, "thread breakpoint stopped at the wrong thread")