1"""
2Test lldb-vscode setBreakpoints request
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_console(lldbvscode_testcase.VSCodeTestCaseBase):
16
17    def check_lldb_command(self, lldb_command, contains_string, assert_msg):
18        response = self.vscode.request_evaluate('`%s' % (lldb_command))
19        output = response['body']['result']
20        self.assertIn(contains_string, output,
21                      ("""Verify %s by checking the command output:\n"""
22                       """'''\n%s'''\nfor the string: "%s" """ % (
23                       assert_msg, output, contains_string)))
24
25    @skipIfWindows
26    @skipIfRemote
27    def test_scopes_variables_setVariable_evaluate(self):
28        '''
29            Tests that the "scopes" request causes the currently selected
30            thread and frame to be updated. There are no DAP packets that tell
31            lldb-vscode which thread and frame are selected other than the
32            "scopes" request. lldb-vscode will now select the thread and frame
33            for the latest "scopes" request that it receives.
34
35            The LLDB command interpreter needs to have the right thread and
36            frame selected so that commands executed in the debug console act
37            on the right scope. This applies both to the expressions that are
38            evaluated and the lldb commands that start with the backtick
39            character.
40        '''
41        program = self.getBuildArtifact("a.out")
42        self.build_and_launch(program)
43        source = 'main.cpp'
44        breakpoint1_line = line_number(source, '// breakpoint 1')
45        lines = [breakpoint1_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        # Cause a "scopes" to be sent for frame zero which should update the
52        # selected thread and frame to frame 0.
53        self.vscode.get_local_variables(frameIndex=0)
54        # Verify frame #0 is selected in the command interpreter by running
55        # the "frame select" command with no frame index which will print the
56        # currently selected frame.
57        self.check_lldb_command("frame select", "frame #0",
58                                "frame 0 is selected")
59
60        # Cause a "scopes" to be sent for frame one which should update the
61        # selected thread and frame to frame 1.
62        self.vscode.get_local_variables(frameIndex=1)
63        # Verify frame #1 is selected in the command interpreter by running
64        # the "frame select" command with no frame index which will print the
65        # currently selected frame.
66
67        self.check_lldb_command("frame select", "frame #1",
68                                "frame 1 is selected")
69