1"""
2Test lldb-vscode variables/stackTrace request for optimized code
3"""
4
5from __future__ import print_function
6
7import unittest2
8import vscode
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12import lldbvscode_testcase
13
14
15class TestVSCode_optimized(lldbvscode_testcase.VSCodeTestCaseBase):
16
17    @skipIfWindows
18    @skipIfRemote
19    def test_stack_frame_name(self):
20        ''' Test optimized frame has special name suffix.
21        '''
22        program = self.getBuildArtifact("a.out")
23        self.build_and_launch(program)
24        source = 'main.cpp'
25        breakpoint_line = line_number(source, '// breakpoint 1')
26        lines = [breakpoint_line]
27        breakpoint_ids = self.set_source_breakpoints(source, lines)
28        self.assertEqual(len(breakpoint_ids), len(lines),
29                        "expect correct number of breakpoints")
30        self.continue_to_breakpoints(breakpoint_ids)
31        leaf_frame = self.vscode.get_stackFrame(frameIndex=0)
32        self.assertTrue(leaf_frame['name'].endswith(' [opt]'))
33        parent_frame = self.vscode.get_stackFrame(frameIndex=1)
34        self.assertTrue(parent_frame['name'].endswith(' [opt]'))
35
36    @skipIfWindows
37    @skipIfRemote
38    def test_optimized_variable(self):
39        ''' Test optimized variable value contains error.
40        '''
41        program = self.getBuildArtifact("a.out")
42        self.build_and_launch(program)
43        source = 'main.cpp'
44        breakpoint_line = line_number(source, '// breakpoint 2')
45        lines = [breakpoint_line]
46        # Set breakpoint in the thread function so we can step the threads
47        breakpoint_ids = self.set_source_breakpoints(source, lines)
48        self.assertEqual(len(breakpoint_ids), len(lines),
49                        "expect correct number of breakpoints")
50        self.continue_to_breakpoints(breakpoint_ids)
51        optimized_variable = self.vscode.get_local_variable('optimized')
52
53        self.assertTrue(optimized_variable['value'].startswith('<error:'))
54