brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.7 KiB · beab4d6 Raw
105 lines · python
1"""2Test lldb-dap setBreakpoints request3"""4 5from dap_server import Source6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8from lldbsuite.test import lldbutil9import lldbdap_testcase10import os11 12 13class TestDAP_breakpointEvents(lldbdap_testcase.DAPTestCaseBase):14    @skipUnlessDarwin15    def test_breakpoint_events(self):16        """17        This test sets a breakpoint in a shared library and runs and stops18        at the entry point of a program. When we stop at the entry point,19        the shared library won't be loaded yet. At this point the20        breakpoint should set itself, but not be verified because no21        locations are resolved. We will then continue and expect to get a22        breakpoint event that informs us that the breakpoint in the shared23        library is "changed" and the correct line number should be24        supplied. We also set a breakpoint using a LLDB command using the25        "preRunCommands" when launching our program. Any breakpoints set via26        the command interpreter should not be have breakpoint events sent27        back to VS Code as the UI isn't able to add new breakpoints to28        their UI. Code has been added that tags breakpoints set from VS Code29        DAP packets so we know the IDE knows about them. If VS Code is ever30        able to register breakpoints that aren't initially set in the GUI,31        then we will need to revise this.32        """33        main_source_basename = "main.cpp"34        main_source_path = os.path.join(os.getcwd(), main_source_basename)35        foo_source_basename = "foo.cpp"36        foo_source_path = os.path.join(os.getcwd(), foo_source_basename)37        main_bp_line = line_number("main.cpp", "main breakpoint 1")38        foo_bp1_line = line_number("foo.cpp", "foo breakpoint 1")39        foo_bp2_line = line_number("foo.cpp", "foo breakpoint 2")40 41        # Visual Studio Code Debug Adapters have no way to specify the file42        # without launching or attaching to a process, so we must start a43        # process in order to be able to set breakpoints.44        program = self.getBuildArtifact("a.out")45 46        # Set a breakpoint after creating the target by running a command line47        # command. It will eventually resolve and cause a breakpoint changed48        # event to be sent to lldb-dap. We want to make sure we don't send a49        # breakpoint any breakpoints that were set from the command line.50        # Breakpoints that are set via the VS code DAP packets will be51        # registered and marked with a special keyword to ensure we deliver52        # breakpoint events for these breakpoints but not for ones that are not53        # set via the command interpreter.54        bp_command = "breakpoint set --file foo.cpp --line %u" % (foo_bp2_line)55        self.build_and_launch(program, preRunCommands=[bp_command])56        main_bp_id = 057        foo_bp_id = 058        # Set breakpoints and verify that they got set correctly59        dap_breakpoint_ids = []60        response = self.dap_server.request_setBreakpoints(61            Source.build(path=main_source_path), [main_bp_line]62        )63        self.assertTrue(response["success"])64        breakpoints = response["body"]["breakpoints"]65        for breakpoint in breakpoints:66            main_bp_id = breakpoint["id"]67            dap_breakpoint_ids.append("%i" % (main_bp_id))68            self.assertTrue(69                breakpoint["verified"], "expect main breakpoint to be verified"70            )71 72        response = self.dap_server.request_setBreakpoints(73            Source.build(path=foo_source_path), [foo_bp1_line]74        )75        self.assertTrue(response["success"])76        breakpoints = response["body"]["breakpoints"]77        for breakpoint in breakpoints:78            foo_bp_id = breakpoint["id"]79            dap_breakpoint_ids.append("%i" % (foo_bp_id))80            self.assertFalse(81                breakpoint["verified"], "expect foo breakpoint to not be verified"82            )83 84        # Flush the breakpoint events.85        self.dap_server.wait_for_breakpoint_events()86 87        # Continue to the breakpoint88        self.continue_to_breakpoints(dap_breakpoint_ids)89 90        verified_breakpoint_ids = []91        unverified_breakpoint_ids = []92        for breakpoint_event in self.dap_server.wait_for_breakpoint_events():93            breakpoint = breakpoint_event["body"]["breakpoint"]94            id = breakpoint["id"]95            if breakpoint["verified"]:96                verified_breakpoint_ids.append(id)97            else:98                unverified_breakpoint_ids.append(id)99 100        self.assertIn(main_bp_id, unverified_breakpoint_ids)101        self.assertIn(foo_bp_id, unverified_breakpoint_ids)102 103        self.assertIn(main_bp_id, verified_breakpoint_ids)104        self.assertIn(foo_bp_id, verified_breakpoint_ids)105