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