1""" 2Test lldb-vscode setBreakpoints request 3""" 4 5 6import unittest2 7import vscode 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11import lldbvscode_testcase 12 13 14class TestVSCode_step(lldbvscode_testcase.VSCodeTestCaseBase): 15 16 mydir = TestBase.compute_mydir(__file__) 17 18 @skipIfWindows 19 @skipIfRemote 20 def test_step(self): 21 ''' 22 Tests the stepping in/out/over in threads. 23 ''' 24 program = self.getBuildArtifact("a.out") 25 self.build_and_launch(program) 26 source = 'main.cpp' 27 # source_path = os.path.join(os.getcwd(), source) 28 breakpoint1_line = line_number(source, '// breakpoint 1') 29 lines = [breakpoint1_line] 30 # Set breakpoint in the thread function so we can step the threads 31 breakpoint_ids = self.set_source_breakpoints(source, lines) 32 self.assertEqual(len(breakpoint_ids), len(lines), 33 "expect correct number of breakpoints") 34 self.continue_to_breakpoints(breakpoint_ids) 35 threads = self.vscode.get_threads() 36 for thread in threads: 37 if 'reason' in thread: 38 reason = thread['reason'] 39 if reason == 'breakpoint': 40 # We have a thread that is stopped at our breakpoint. 41 # Get the value of "x" and get the source file and line. 42 # These will help us determine if we are stepping 43 # correctly. If we step a thread correctly we will verify 44 # the correct falue for x as it progresses through the 45 # program. 46 tid = thread['id'] 47 x1 = self.get_local_as_int('x', threadId=tid) 48 (src1, line1) = self.get_source_and_line(threadId=tid) 49 50 # Now step into the "recurse()" function call again and 51 # verify, using the new value of "x" and the source file 52 # and line if we stepped correctly 53 self.stepIn(threadId=tid, waitForStop=True) 54 x2 = self.get_local_as_int('x', threadId=tid) 55 (src2, line2) = self.get_source_and_line(threadId=tid) 56 self.assertEqual(x1, x2 + 1, 'verify step in variable') 57 self.assertLess(line2, line1, 'verify step in line') 58 self.assertEqual(src1, src2, 'verify step in source') 59 60 # Now step out and verify 61 self.stepOut(threadId=tid, waitForStop=True) 62 x3 = self.get_local_as_int('x', threadId=tid) 63 (src3, line3) = self.get_source_and_line(threadId=tid) 64 self.assertEqual(x1, x3, 'verify step out variable') 65 self.assertGreaterEqual(line3, line1, 'verify step out line') 66 self.assertEqual(src1, src3, 'verify step in source') 67 68 # Step over and verify 69 self.stepOver(threadId=tid, waitForStop=True) 70 x4 = self.get_local_as_int('x', threadId=tid) 71 (src4, line4) = self.get_source_and_line(threadId=tid) 72 self.assertEqual(x4, x3, 'verify step over variable') 73 self.assertGreater(line4, line3, 'verify step over line') 74 self.assertEqual(src1, src4, 'verify step over source') 75 # only step one thread that is at the breakpoint and stop 76 break 77