199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest that we obey thread conditioned breakpoints. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprecht 699451b44SJordan Rupprecht 799451b44SJordan Rupprechtimport lldb 899451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 999451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 1099451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1199451b44SJordan Rupprecht 12*f362b05dSJim Inghamdef using_current(test, thread, breakpoint): 13*f362b05dSJim Ingham bp_id = breakpoint.GetID() 14*f362b05dSJim Ingham test.runCmd("break modify -t current {0}".format(bp_id)) 15*f362b05dSJim Ingham 16*f362b05dSJim Inghamdef set_thread_id(test, thread, breakpoint): 1799451b44SJordan Rupprecht id = thread.id 1899451b44SJordan Rupprecht breakpoint.SetThreadID(id) 1999451b44SJordan Rupprecht 20*f362b05dSJim Inghamdef set_thread_name(test, thread, breakpoint): 2199451b44SJordan Rupprecht breakpoint.SetThreadName("main-thread") 2299451b44SJordan Rupprecht 2399451b44SJordan Rupprechtclass ThreadSpecificBreakTestCase(TestBase): 2499451b44SJordan Rupprecht NO_DEBUG_INFO_TESTCASE = True 2599451b44SJordan Rupprecht 2699451b44SJordan Rupprecht @add_test_categories(['pyapi']) 2799451b44SJordan Rupprecht 2899451b44SJordan Rupprecht @expectedFailureAll(oslist=['ios', 'watchos', 'tvos', 'bridgeos'], archs=['armv7', 'armv7k'], bugnumber='rdar://problem/34563920') # armv7 ios problem - breakpoint with tid qualifier isn't working 2999451b44SJordan Rupprecht def test_thread_id(self): 3099451b44SJordan Rupprecht self.do_test(set_thread_id) 3199451b44SJordan Rupprecht 3299451b44SJordan Rupprecht @skipUnlessDarwin 3399451b44SJordan Rupprecht @expectedFailureAll(oslist=['ios', 'watchos', 'tvos', 'bridgeos'], archs=['armv7', 'armv7k'], bugnumber='rdar://problem/34563920') # armv7 ios problem - breakpoint with tid qualifier isn't working 3499451b44SJordan Rupprecht def test_thread_name(self): 3599451b44SJordan Rupprecht self.do_test(set_thread_name) 3699451b44SJordan Rupprecht 37*f362b05dSJim Ingham @expectedFailureAll(oslist=['ios', 'watchos', 'tvos', 'bridgeos'], archs=['armv7', 'armv7k'], bugnumber='rdar://problem/34563920') # armv7 ios problem - breakpoint with tid qualifier isn't working 38*f362b05dSJim Ingham def test_current_token(self): 39*f362b05dSJim Ingham self.do_test(using_current) 40*f362b05dSJim Ingham 4199451b44SJordan Rupprecht def do_test(self, setter_method): 4299451b44SJordan Rupprecht """Test that we obey thread conditioned breakpoints.""" 4399451b44SJordan Rupprecht self.build() 4499451b44SJordan Rupprecht main_source_spec = lldb.SBFileSpec("main.cpp") 4599451b44SJordan Rupprecht (target, process, main_thread, main_breakpoint) = lldbutil.run_to_source_breakpoint(self, 4699451b44SJordan Rupprecht "Set main breakpoint here", main_source_spec) 4799451b44SJordan Rupprecht 4899451b44SJordan Rupprecht thread_breakpoint = target.BreakpointCreateBySourceRegex( 4999451b44SJordan Rupprecht "Set thread-specific breakpoint here", main_source_spec) 5099451b44SJordan Rupprecht self.assertGreater( 5199451b44SJordan Rupprecht thread_breakpoint.GetNumLocations(), 5299451b44SJordan Rupprecht 0, 5399451b44SJordan Rupprecht "thread breakpoint has no locations associated with it.") 5499451b44SJordan Rupprecht 5599451b44SJordan Rupprecht # Set the thread-specific breakpoint to stop only on the main thread 5699451b44SJordan Rupprecht # before the secondary thread has a chance to execute it. The main 5799451b44SJordan Rupprecht # thread joins the secondary thread, and then the main thread will 5899451b44SJordan Rupprecht # execute the code at the breakpoint. If the thread-specific 5999451b44SJordan Rupprecht # breakpoint works, the next stop will be on the main thread. 60*f362b05dSJim Ingham setter_method(self, main_thread, thread_breakpoint) 6199451b44SJordan Rupprecht 6299451b44SJordan Rupprecht process.Continue() 6399451b44SJordan Rupprecht next_stop_state = process.GetState() 6499451b44SJordan Rupprecht self.assertEqual( 6599451b44SJordan Rupprecht next_stop_state, 6699451b44SJordan Rupprecht lldb.eStateStopped, 6799451b44SJordan Rupprecht "We should have stopped at the thread breakpoint.") 6899451b44SJordan Rupprecht stopped_threads = lldbutil.get_threads_stopped_at_breakpoint( 6999451b44SJordan Rupprecht process, thread_breakpoint) 7099451b44SJordan Rupprecht self.assertEqual( 7199451b44SJordan Rupprecht len(stopped_threads), 7299451b44SJordan Rupprecht 1, 7399451b44SJordan Rupprecht "thread breakpoint stopped at unexpected number of threads") 7499451b44SJordan Rupprecht self.assertEqual( 7599451b44SJordan Rupprecht stopped_threads[0].GetThreadID(), 7699451b44SJordan Rupprecht main_thread.GetThreadID(), 7799451b44SJordan Rupprecht "thread breakpoint stopped at the wrong thread") 78