• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    mydir = TestBase.compute_mydir(__file__)
18
19    def check_lldb_command(self, lldb_command, contains_string, assert_msg):
20        response = self.vscode.request_evaluate('`%s' % (lldb_command))
21        output = response['body']['result']
22        self.assertTrue(contains_string in output,
23                        ("""Verify %s by checking the command output:\n"""
24                         """'''\n%s'''\nfor the string: "%s" """ % (
25                         assert_msg, output, contains_string)))
26
27    @skipIfWindows
28    @skipIfRemote
29    def test_scopes_variables_setVariable_evaluate(self):
30        '''
31            Tests that the "scopes" request causes the currently selected
32            thread and frame to be updated. There are no DAP packets that tell
33            lldb-vscode which thread and frame are selected other than the
34            "scopes" request. lldb-vscode will now select the thread and frame
35            for the latest "scopes" request that it receives.
36
37            The LLDB command interpreter needs to have the right thread and
38            frame selected so that commands executed in the debug console act
39            on the right scope. This applies both to the expressions that are
40            evaluated and the lldb commands that start with the backtick
41            character.
42        '''
43        program = self.getBuildArtifact("a.out")
44        self.build_and_launch(program)
45        source = 'main.cpp'
46        breakpoint1_line = line_number(source, '// breakpoint 1')
47        lines = [breakpoint1_line]
48        # Set breakpoint in the thread function so we can step the threads
49        breakpoint_ids = self.set_source_breakpoints(source, lines)
50        self.assertTrue(len(breakpoint_ids) == len(lines),
51                        "expect correct number of breakpoints")
52        self.continue_to_breakpoints(breakpoint_ids)
53        # Cause a "scopes" to be sent for frame zero which should update the
54        # selected thread and frame to frame 0.
55        self.vscode.get_local_variables(frameIndex=0)
56        # Verify frame #0 is selected in the command interpreter by running
57        # the "frame select" command with no frame index which will print the
58        # currently selected frame.
59        self.check_lldb_command("frame select", "frame #0",
60                                "frame 0 is selected")
61
62        # Cause a "scopes" to be sent for frame one which should update the
63        # selected thread and frame to frame 1.
64        self.vscode.get_local_variables(frameIndex=1)
65        # Verify frame #1 is selected in the command interpreter by running
66        # the "frame select" command with no frame index which will print the
67        # currently selected frame.
68
69        self.check_lldb_command("frame select", "frame #1",
70                                "frame 1 is selected")
71