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 12import os 13 14 15class TestVSCode_stackTrace(lldbvscode_testcase.VSCodeTestCaseBase): 16 17 mydir = TestBase.compute_mydir(__file__) 18 name_key_path = ['name'] 19 source_key_path = ['source', 'path'] 20 line_key_path = ['line'] 21 22 def verify_stackFrames(self, start_idx, stackFrames): 23 frame_idx = start_idx 24 for stackFrame in stackFrames: 25 # Don't care about frame above main 26 if frame_idx > 20: 27 return 28 self.verify_stackFrame(frame_idx, stackFrame) 29 frame_idx += 1 30 31 def verify_stackFrame(self, frame_idx, stackFrame): 32 frame_name = self.get_dict_value(stackFrame, self.name_key_path) 33 frame_source = self.get_dict_value(stackFrame, self.source_key_path) 34 frame_line = self.get_dict_value(stackFrame, self.line_key_path) 35 if frame_idx == 0: 36 expected_line = self.recurse_end 37 expected_name = 'recurse' 38 elif frame_idx < 20: 39 expected_line = self.recurse_call 40 expected_name = 'recurse' 41 else: 42 expected_line = self.recurse_invocation 43 expected_name = 'main' 44 self.assertEquals(frame_name, expected_name, 45 'frame #%i name "%s" == "%s"' % ( 46 frame_idx, frame_name, expected_name)) 47 self.assertEquals(frame_source, self.source_path, 48 'frame #%i source "%s" == "%s"' % ( 49 frame_idx, frame_source, self.source_path)) 50 self.assertEquals(frame_line, expected_line, 51 'frame #%i line %i == %i' % (frame_idx, frame_line, 52 expected_line)) 53 54 @skipIfWindows 55 @skipIfRemote 56 def test_stackTrace(self): 57 ''' 58 Tests the 'stackTrace' packet and all its variants. 59 ''' 60 program = self.getBuildArtifact("a.out") 61 self.build_and_launch(program) 62 source = 'main.c' 63 self.source_path = os.path.join(os.getcwd(), source) 64 self.recurse_end = line_number(source, 'recurse end') 65 self.recurse_call = line_number(source, 'recurse call') 66 self.recurse_invocation = line_number(source, 'recurse invocation') 67 68 lines = [self.recurse_end] 69 70 # Set breakpoint at a point of deepest recuusion 71 breakpoint_ids = self.set_source_breakpoints(source, lines) 72 self.assertEquals(len(breakpoint_ids), len(lines), 73 "expect correct number of breakpoints") 74 75 self.continue_to_breakpoints(breakpoint_ids) 76 startFrame = 0 77 # Verify we get all stack frames with no arguments 78 (stackFrames, totalFrames) = self.get_stackFrames_and_totalFramesCount() 79 frameCount = len(stackFrames) 80 self.assertTrue(frameCount >= 20, 81 'verify we get at least 20 frames for all frames') 82 self.assertEquals(totalFrames, frameCount, 83 'verify we get correct value for totalFrames count') 84 self.verify_stackFrames(startFrame, stackFrames) 85 86 # Verify all stack frames by specifying startFrame = 0 and levels not 87 # specified 88 stackFrames = self.get_stackFrames(startFrame=startFrame) 89 self.assertEquals(frameCount, len(stackFrames), 90 ('verify same number of frames with startFrame=%i') % ( 91 startFrame)) 92 self.verify_stackFrames(startFrame, stackFrames) 93 94 # Verify all stack frames by specifying startFrame = 0 and levels = 0 95 levels = 0 96 stackFrames = self.get_stackFrames(startFrame=startFrame, 97 levels=levels) 98 self.assertEquals(frameCount, len(stackFrames), 99 ('verify same number of frames with startFrame=%i and' 100 ' levels=%i') % (startFrame, levels)) 101 self.verify_stackFrames(startFrame, stackFrames) 102 103 # Get only the first stack frame by sepcifying startFrame = 0 and 104 # levels = 1 105 levels = 1 106 stackFrames = self.get_stackFrames(startFrame=startFrame, 107 levels=levels) 108 self.assertEquals(levels, len(stackFrames), 109 ('verify one frame with startFrame=%i and' 110 ' levels=%i') % (startFrame, levels)) 111 self.verify_stackFrames(startFrame, stackFrames) 112 113 # Get only the first 3 stack frames by sepcifying startFrame = 0 and 114 # levels = 3 115 levels = 3 116 stackFrames = self.get_stackFrames(startFrame=startFrame, 117 levels=levels) 118 self.assertEquals(levels, len(stackFrames), 119 ('verify %i frames with startFrame=%i and' 120 ' levels=%i') % (levels, startFrame, levels)) 121 self.verify_stackFrames(startFrame, stackFrames) 122 123 # Get only the first 15 stack frames by sepcifying startFrame = 5 and 124 # levels = 16 125 startFrame = 5 126 levels = 16 127 stackFrames = self.get_stackFrames(startFrame=startFrame, 128 levels=levels) 129 self.assertEquals(levels, len(stackFrames), 130 ('verify %i frames with startFrame=%i and' 131 ' levels=%i') % (levels, startFrame, levels)) 132 self.verify_stackFrames(startFrame, stackFrames) 133 134 # Verify we cap things correctly when we ask for too many frames 135 startFrame = 5 136 levels = 1000 137 (stackFrames, totalFrames) = self.get_stackFrames_and_totalFramesCount( 138 startFrame=startFrame, 139 levels=levels) 140 self.assertEquals(len(stackFrames), frameCount - startFrame, 141 ('verify less than 1000 frames with startFrame=%i and' 142 ' levels=%i') % (startFrame, levels)) 143 self.assertEquals(totalFrames, frameCount, 144 'verify we get correct value for totalFrames count ' 145 'when requested frames not from 0 index') 146 self.verify_stackFrames(startFrame, stackFrames) 147 148 # Verify level=0 works with non-zerp start frame 149 startFrame = 5 150 levels = 0 151 stackFrames = self.get_stackFrames(startFrame=startFrame, 152 levels=levels) 153 self.assertEquals(len(stackFrames), frameCount - startFrame, 154 ('verify less than 1000 frames with startFrame=%i and' 155 ' levels=%i') % (startFrame, levels)) 156 self.verify_stackFrames(startFrame, stackFrames) 157 158 # Verify we get not frames when startFrame is too high 159 startFrame = 1000 160 levels = 1 161 stackFrames = self.get_stackFrames(startFrame=startFrame, 162 levels=levels) 163 self.assertEquals(0, len(stackFrames), 164 'verify zero frames with startFrame out of bounds') 165