1""" 2Test lldb-dap setBreakpoints request 3""" 4 5from lldbsuite.test.decorators import * 6from lldbsuite.test.lldbtest import * 7from lldbsuite.test import lldbutil 8import lldbdap_testcase 9 10 11class TestDAP_threads(lldbdap_testcase.DAPTestCaseBase): 12 @skipIfWindows 13 def test_correct_thread(self): 14 """ 15 Tests that the correct thread is selected if we continue from 16 a thread that goes away and hit a breakpoint in another thread. 17 In this case, the selected thread should be the thread that 18 just hit the breakpoint, and not the first thread in the list. 19 """ 20 program = self.getBuildArtifact("a.out") 21 self.build_and_launch(program) 22 source = "main.c" 23 breakpoint_line = line_number(source, "// break here") 24 lines = [breakpoint_line] 25 # Set breakpoint in the thread function 26 breakpoint_ids = self.set_source_breakpoints(source, lines) 27 self.assertEqual( 28 len(breakpoint_ids), len(lines), "expect correct number of breakpoints" 29 ) 30 self.continue_to_breakpoints(breakpoint_ids) 31 # We're now stopped at the breakpoint in the first thread, thread #2. 32 # Continue to join the first thread and hit the breakpoint in the 33 # second thread, thread #3. 34 self.dap_server.request_continue() 35 stopped_event = self.dap_server.wait_for_stopped() 36 # Verify that the description is the relevant breakpoint, 37 # preserveFocusHint is False and threadCausedFocus is True 38 self.assertTrue( 39 stopped_event[0]["body"]["description"].startswith( 40 "breakpoint %s." % breakpoint_ids[0] 41 ) 42 ) 43 self.assertFalse(stopped_event[0]["body"]["preserveFocusHint"]) 44 self.assertTrue(stopped_event[0]["body"]["threadCausedFocus"]) 45 46 @skipIfWindows 47 def test_thread_format(self): 48 """ 49 Tests the support for custom thread formats. 50 """ 51 program = self.getBuildArtifact("a.out") 52 self.build_and_launch( 53 program, customThreadFormat="This is thread index #${thread.index}" 54 ) 55 source = "main.c" 56 breakpoint_line = line_number(source, "// break here") 57 lines = [breakpoint_line] 58 # Set breakpoint in the thread function 59 breakpoint_ids = self.set_source_breakpoints(source, lines) 60 self.assertEqual( 61 len(breakpoint_ids), len(lines), "expect correct number of breakpoints" 62 ) 63 self.continue_to_breakpoints(breakpoint_ids) 64 # We are stopped at the second thread 65 threads = self.dap_server.get_threads() 66 self.assertEqual(threads[0]["name"], "This is thread index #1") 67 self.assertEqual(threads[1]["name"], "This is thread index #2") 68