1""" 2Test that if we hit a breakpoint on a lambda capture 3on two threads at the same time we stop only for 4the correct one. 5""" 6 7import lldb 8import lldbsuite.test.lldbutil as lldbutil 9from lldbsuite.test.decorators import * 10from lldbsuite.test.lldbtest import * 11 12 13class TestBreakOnLambdaCapture(TestBase): 14 15 NO_DEBUG_INFO_TESTCASE = True 16 17 def test_break_on_lambda_capture(self): 18 self.build() 19 self.main_source_file = lldb.SBFileSpec("main.cpp") 20 21 (target, process, main_thread, _) = lldbutil.run_to_source_breakpoint(self, 22 "First break", self.main_source_file) 23 24 # FIXME: This is working around a separate bug. If you hit a breakpoint and 25 # run an expression and it is the first expression you've ever run, on 26 # Darwin that will involve running the ObjC runtime parsing code, and we'll 27 # be in the middle of that when we do PerformAction on the other thread, 28 # which will cause the condition expression to fail. Calling another 29 # expression first works around this. 30 val_obj = main_thread.frame[0].EvaluateExpression("true") 31 self.assertSuccess(val_obj.GetError(), "Ran our expression successfully") 32 self.assertEqual(val_obj.value, "true", "Value was true.") 33 34 bkpt = target.BreakpointCreateBySourceRegex("Break here in the helper", 35 self.main_source_file); 36 37 bkpt.SetCondition("enable && usec == 1") 38 process.Continue() 39 40 # This is hard to test definitively, becuase it requires hitting 41 # a breakpoint on multiple threads at the same time. On Darwin, this 42 # will happen pretty much ever time we continue. What we are really 43 # asserting is that we only ever stop on one thread, so we approximate that 44 # by continuing 20 times and assert we only ever hit the first thread. Either 45 # this is a platform that only reports one hit at a time, in which case all 46 # this code is unused, or we actually didn't hit the other thread. 47 48 for idx in range(0, 20): 49 process.Continue() 50 for thread in process.threads: 51 if thread.id == main_thread.id: 52 self.assertEqual(thread.stop_reason, lldb.eStopReasonBreakpoint) 53 else: 54 self.assertEqual(thread.stop_reason, lldb.eStopReasonNone) 55