예제 #1
0
    def kvo_data_formatter_commands(self):
        """Test the behavior of formatters when KVO is in use."""
        self.runCmd("file " + self.getBuildArtifact("a.out"),
                    CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.m",
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        self.runCmd("run", RUN_SUCCEEDED)

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list",
                    STOPPED_DUE_TO_BREAKPOINT,
                    substrs=['stopped', 'stop reason = breakpoint'])

        # This is the function to remove the custom formats in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd('type format clear', check=False)
            self.runCmd('type summary clear', check=False)
            self.runCmd('type synth clear', check=False)

        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        # as long as KVO is implemented by subclassing, this test should succeed
        # we should be able to dynamically figure out that the KVO implementor class
        # is a subclass of Molecule, and use the appropriate summary for it
        self.runCmd("type summary add -s JustAMoleculeHere Molecule")
        self.expect('frame variable molecule', substrs=['JustAMoleculeHere'])
        self.runCmd("next")
        self.expect("thread list", substrs=['stopped', 'step over'])
        self.expect('frame variable molecule', substrs=['JustAMoleculeHere'])

        self.runCmd("next")
        # check that NSMutableDictionary's formatter is not confused when
        # dealing with a KVO'd dictionary
        self.expect('frame variable newMutableDictionary',
                    substrs=[
                        '(NSDictionary *) newMutableDictionary = ',
                        ' 21 key/value pairs'
                    ])

        lldbutil.run_break_set_by_regexp(self, 'setAtoms')

        self.runCmd("continue")
        self.expect("frame variable _cmd", substrs=['setAtoms:'])
예제 #2
0
    def kvo_data_formatter_commands(self):
        """Test the behavior of formatters when KVO is in use."""
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_file_and_line(
            self, "main.m", self.line, num_expected_locations=1, loc_exact=True)

        self.runCmd("run", RUN_SUCCEEDED)

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
                    substrs=['stopped',
                             'stop reason = breakpoint'])

        # This is the function to remove the custom formats in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd('type format clear', check=False)
            self.runCmd('type summary clear', check=False)
            self.runCmd('type synth clear', check=False)

        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        # as long as KVO is implemented by subclassing, this test should succeed
        # we should be able to dynamically figure out that the KVO implementor class
        # is a subclass of Molecule, and use the appropriate summary for it
        self.runCmd("type summary add -s JustAMoleculeHere Molecule")
        self.expect('frame variable molecule', substrs=['JustAMoleculeHere'])
        self.runCmd("next")
        self.expect("thread list",
                    substrs=['stopped',
                             'step over'])
        self.expect('frame variable molecule', substrs=['JustAMoleculeHere'])

        self.runCmd("next")
        # check that NSMutableDictionary's formatter is not confused when
        # dealing with a KVO'd dictionary
        self.expect(
            'frame variable newMutableDictionary',
            substrs=[
                '(NSDictionary *) newMutableDictionary = ',
                ' 21 key/value pairs'])

        lldbutil.run_break_set_by_regexp(self, 'setAtoms')

        self.runCmd("continue")
        self.expect("frame variable _cmd", substrs=['setAtoms:'])
예제 #3
0
    def test(self):
        """Test SBFrame.GetLanguageSpecificData() in async functions"""
        self.build()

        # This test uses "main" as a prefix for all functions, so that all will
        # be stopped at. Setting a breakpoint on "main" results in a breakpoint
        # at the start of each coroutine "funclet" function.
        target, process, thread, _ = lldbutil.run_to_name_breakpoint(
            self, "main")

        # Skip the real `main`. All other stops will be Swift async functions.
        self.assertEqual(thread.frames[0].name, "main")
        process.Continue()

        regex_bpno = lldbutil.run_break_set_by_regexp(self, "^main[[:digit:]]")

        while process.state == lldb.eStateStopped:
            thread = process.GetSelectedThread()
            frame = thread.frames[0]
            data = frame.GetLanguageSpecificData()
            is_async = data.GetValueForKey(
                "IsSwiftAsyncFunction").GetBooleanValue()
            self.assertTrue(is_async)

            process.Continue()

        bkpt = target.FindBreakpointByID(regex_bpno)
        self.assertEqual(bkpt.GetHitCount(), bkpt.num_locations)
        for location in bkpt.locations:
            self.assertEqual(location.GetHitCount(), 1)
예제 #4
0
    def test_kvo_with_run_command(self):
        """Test the behavior of formatters when KVO is in use."""
        self.build()
        self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
            self, '// Set break point at this line.',
            lldb.SBFileSpec('main.m', False))

        # The stop reason of the thread should be breakpoint.
        self.expect(
            "thread list",
            STOPPED_DUE_TO_BREAKPOINT,
            substrs=['stopped', 'stop reason = breakpoint'])

        # This is the function to remove the custom formats in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd('type format clear', check=False)
            self.runCmd('type summary clear', check=False)
            self.runCmd('type synth clear', check=False)

        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        # as long as KVO is implemented by subclassing, this test should succeed
        # we should be able to dynamically figure out that the KVO implementor class
        # is a subclass of Molecule, and use the appropriate summary for it
        self.runCmd("type summary add -s JustAMoleculeHere Molecule")
        self.expect('frame variable molecule', substrs=['JustAMoleculeHere'])
        self.runCmd("next")
        self.expect("thread list", substrs=['stopped', 'step over'])
        self.expect('frame variable molecule', substrs=['JustAMoleculeHere'])

        self.runCmd("next")
        # check that NSMutableDictionary's formatter is not confused when
        # dealing with a KVO'd dictionary
        self.expect(
            'frame variable newMutableDictionary',
            substrs=[
                '(NSDictionary *) newMutableDictionary = ',
                ' 21 key/value pairs'
            ])

        lldbutil.run_break_set_by_regexp(self, 'setAtoms')

        self.runCmd("continue")
        self.expect("frame variable _cmd", substrs=['setAtoms:'])
예제 #5
0
    def test_kvo_with_run_command(self):
        """Test the behavior of formatters when KVO is in use."""
        self.build()
        self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
            self, '// Set break point at this line.',
            lldb.SBFileSpec('main.m', False))

        # The stop reason of the thread should be breakpoint.
        self.expect(
            "thread list",
            STOPPED_DUE_TO_BREAKPOINT,
            substrs=['stopped', 'stop reason = breakpoint'])

        # This is the function to remove the custom formats in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd('type format clear', check=False)
            self.runCmd('type summary clear', check=False)
            self.runCmd('type synth clear', check=False)

        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        # as long as KVO is implemented by subclassing, this test should succeed
        # we should be able to dynamically figure out that the KVO implementor class
        # is a subclass of Molecule, and use the appropriate summary for it
        self.runCmd("type summary add -s JustAMoleculeHere Molecule")
        self.expect('frame variable molecule', substrs=['JustAMoleculeHere'])
        self.runCmd("next")
        self.expect("thread list", substrs=['stopped', 'step over'])
        self.expect('frame variable molecule', substrs=['JustAMoleculeHere'])

        self.runCmd("next")
        # check that NSMutableDictionary's formatter is not confused when
        # dealing with a KVO'd dictionary
        self.expect(
            'frame variable newMutableDictionary',
            substrs=[
                '(NSDictionary *) newMutableDictionary = ',
                ' 21 key/value pairs'
            ])

        lldbutil.run_break_set_by_regexp(self, 'setAtoms')

        self.runCmd("continue")
        self.expect("frame variable _cmd", substrs=['setAtoms:'])
    def breakpoint_command_sequence(self):
        """Test a sequence of breakpoint command add, list, and delete."""
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Add three breakpoints on the same line.  The first time we don't specify the file,
        # since the default file is the one containing main:
        lldbutil.run_break_set_by_file_and_line(
            self, None, self.line, num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
        # Breakpoint 4 - set at the same location as breakpoint 1 to test
        # setting breakpoint commands on two breakpoints at a time
        lldbutil.run_break_set_by_file_and_line(
            self, None, self.line, num_expected_locations=1, loc_exact=True)
        # Make sure relative path source breakpoints work as expected. We test
        # with partial paths with and without "./" prefixes.
        lldbutil.run_break_set_by_file_and_line(
            self, "./main.c", self.line,
            num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "breakpoint_command/main.c", self.line,
            num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "./breakpoint_command/main.c", self.line,
            num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "breakpoint/breakpoint_command/main.c", self.line,
            num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "./breakpoint/breakpoint_command/main.c", self.line,
            num_expected_locations=1, loc_exact=True)
        # Test relative breakpoints with incorrect paths and make sure we get
        # no breakpoint locations
        lldbutil.run_break_set_by_file_and_line(
            self, "invalid/main.c", self.line,
            num_expected_locations=0, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "./invalid/main.c", self.line,
            num_expected_locations=0, loc_exact=True)
        # Now add callbacks for the breakpoints just created.
        self.runCmd(
            "breakpoint command add -s command -o 'frame variable --show-types --scope' 1 4")
        self.runCmd(
            "breakpoint command add -s python -o 'import side_effect; side_effect.one_liner = \"one liner was here\"' 2")

        import side_effect
        self.runCmd("command script import --allow-reload ./bktptcmd.py")

        self.runCmd(
            "breakpoint command add --python-function bktptcmd.function 3")

        # Check that the breakpoint commands are correctly set.

        # The breakpoint list now only contains breakpoint 1.
        self.expect(
            "breakpoint list", "Breakpoints 1 & 2 created", substrs=[
                "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" %
                self.line], patterns=[
                "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" %
                self.line])

        self.expect(
            "breakpoint list -f",
            "Breakpoints 1 & 2 created",
            substrs=[
                "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" %
                self.line],
            patterns=[
                "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" %
                self.line,
                "1.1: .+at main.c:%d:?[0-9]*, .+unresolved, hit count = 0" %
                self.line,
                "2.1: .+at main.c:%d:?[0-9]*, .+unresolved, hit count = 0" %
                self.line])

        self.expect("breakpoint command list 1", "Breakpoint 1 command ok",
                    substrs=["Breakpoint commands:",
                             "frame variable --show-types --scope"])
        self.expect("breakpoint command list 2", "Breakpoint 2 command ok",
                    substrs=["Breakpoint commands (Python):",
                             "import side_effect",
                             "side_effect.one_liner"])
        self.expect("breakpoint command list 3", "Breakpoint 3 command ok",
                    substrs=["Breakpoint commands (Python):",
                             "bktptcmd.function(frame, bp_loc, internal_dict)"])

        self.expect("breakpoint command list 4", "Breakpoint 4 command ok",
                    substrs=["Breakpoint commands:",
                             "frame variable --show-types --scope"])

        self.runCmd("breakpoint delete 4")

        # Next lets try some other breakpoint kinds.  First break with a regular expression
        # and then specify only one file.  The first time we should get two locations,
        # the second time only one:

        lldbutil.run_break_set_by_regexp(
            self, r"._MyFunction", num_expected_locations=2)

        lldbutil.run_break_set_by_regexp(
            self,
            r"._MyFunction",
            extra_options="-f a.c",
            num_expected_locations=1)

        lldbutil.run_break_set_by_regexp(
            self,
            r"._MyFunction",
            extra_options="-f a.c -f b.c",
            num_expected_locations=2)

        # Now try a source regex breakpoint:
        lldbutil.run_break_set_by_source_regexp(
            self,
            r"is about to return [12]0",
            extra_options="-f a.c -f b.c",
            num_expected_locations=2)

        lldbutil.run_break_set_by_source_regexp(
            self,
            r"is about to return [12]0",
            extra_options="-f a.c",
            num_expected_locations=1)

        # Reset our canary variables and run the program.
        side_effect.one_liner = None
        side_effect.bktptcmd = None
        self.runCmd("run", RUN_SUCCEEDED)

        # Check the value of canary variables.
        self.assertEquals("one liner was here", side_effect.one_liner)
        self.assertEquals("function was here", side_effect.bktptcmd)

        # Finish the program.
        self.runCmd("process continue")

        # Remove the breakpoint command associated with breakpoint 1.
        self.runCmd("breakpoint command delete 1")

        # Remove breakpoint 2.
        self.runCmd("breakpoint delete 2")

        self.expect(
            "breakpoint command list 1",
            startstr="Breakpoint 1 does not have an associated command.")
        self.expect(
            "breakpoint command list 2",
            error=True,
            startstr="error: '2' is not a currently valid breakpoint ID.")

        # The breakpoint list now only contains breakpoint 1.
        self.expect(
            "breakpoint list -f",
            "Breakpoint 1 exists",
            patterns=[
                "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" %
                self.line,
                "hit count = 1"])

        # Not breakpoint 2.
        self.expect(
            "breakpoint list -f",
            "No more breakpoint 2",
            matching=False,
            substrs=[
                "2: file = 'main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" %
                self.line])

        # Run the program again, with breakpoint 1 remaining.
        self.runCmd("run", RUN_SUCCEEDED)

        # We should be stopped again due to breakpoint 1.

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
                    substrs=['stopped',
                             'stop reason = breakpoint'])

        # The breakpoint should have a hit count of 2.
        self.expect("breakpoint list -f", BREAKPOINT_HIT_TWICE,
                    substrs=['resolved, hit count = 2'])
    def breakpoint_command_sequence(self):
        """Test a sequence of breakpoint command add, list, and delete."""
        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Add three breakpoints on the same line.  The first time we don't specify the file,
        # since the default file is the one containing main:
        lldbutil.run_break_set_by_file_and_line(self,
                                                None,
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.c",
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(self,
                                                "main.c",
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)
        # Breakpoint 4 - set at the same location as breakpoint 1 to test
        # setting breakpoint commands on two breakpoints at a time
        lldbutil.run_break_set_by_file_and_line(self,
                                                None,
                                                self.line,
                                                num_expected_locations=1,
                                                loc_exact=True)

        # Now add callbacks for the breakpoints just created.
        self.runCmd(
            "breakpoint command add -s command -o 'frame variable --show-types --scope' 1 4"
        )
        self.runCmd(
            "breakpoint command add -s python -o 'here = open(\"output.txt\", \"w\"); here.write(\"lldb\\n\"); here.close()' 2"
        )
        self.runCmd(
            "breakpoint command add --python-function bktptcmd.function 3")

        # Check that the breakpoint commands are correctly set.

        # The breakpoint list now only contains breakpoint 1.
        self.expect(
            "breakpoint list",
            "Breakpoints 1 & 2 created",
            substrs=[
                "2: file = 'main.c', line = %d, exact_match = 0, locations = 1"
                % self.line
            ],
            patterns=[
                "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1"
                % self.line
            ])

        self.expect(
            "breakpoint list -f",
            "Breakpoints 1 & 2 created",
            substrs=[
                "2: file = 'main.c', line = %d, exact_match = 0, locations = 1"
                % self.line
            ],
            patterns=[
                "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1"
                % self.line,
                "1.1: .+at main.c:%d, .+unresolved, hit count = 0" % self.line,
                "2.1: .+at main.c:%d, .+unresolved, hit count = 0" % self.line
            ])

        self.expect("breakpoint command list 1",
                    "Breakpoint 1 command ok",
                    substrs=[
                        "Breakpoint commands:",
                        "frame variable --show-types --scope"
                    ])
        self.expect("breakpoint command list 2",
                    "Breakpoint 2 command ok",
                    substrs=[
                        "Breakpoint commands:", "here = open", "here.write",
                        "here.close()"
                    ])
        self.expect("breakpoint command list 3",
                    "Breakpoint 3 command ok",
                    substrs=[
                        "Breakpoint commands:",
                        "bktptcmd.function(frame, bp_loc, internal_dict)"
                    ])

        self.expect("breakpoint command list 4",
                    "Breakpoint 4 command ok",
                    substrs=[
                        "Breakpoint commands:",
                        "frame variable --show-types --scope"
                    ])

        self.runCmd("breakpoint delete 4")

        self.runCmd("command script import --allow-reload ./bktptcmd.py")

        # Next lets try some other breakpoint kinds.  First break with a regular expression
        # and then specify only one file.  The first time we should get two locations,
        # the second time only one:

        lldbutil.run_break_set_by_regexp(self,
                                         r"._MyFunction",
                                         num_expected_locations=2)

        lldbutil.run_break_set_by_regexp(self,
                                         r"._MyFunction",
                                         extra_options="-f a.c",
                                         num_expected_locations=1)

        lldbutil.run_break_set_by_regexp(self,
                                         r"._MyFunction",
                                         extra_options="-f a.c -f b.c",
                                         num_expected_locations=2)

        # Now try a source regex breakpoint:
        lldbutil.run_break_set_by_source_regexp(self,
                                                r"is about to return [12]0",
                                                extra_options="-f a.c -f b.c",
                                                num_expected_locations=2)

        lldbutil.run_break_set_by_source_regexp(self,
                                                r"is about to return [12]0",
                                                extra_options="-f a.c",
                                                num_expected_locations=1)

        # Run the program.  Remove 'output.txt' if it exists.
        self.RemoveTempFile("output.txt")
        self.RemoveTempFile("output2.txt")
        self.runCmd("run", RUN_SUCCEEDED)

        # Check that the file 'output.txt' exists and contains the string
        # "lldb".

        # The 'output.txt' file should now exist.
        self.assertTrue(
            os.path.isfile("output.txt"),
            "'output.txt' exists due to breakpoint command for breakpoint 2.")
        self.assertTrue(
            os.path.isfile("output2.txt"),
            "'output2.txt' exists due to breakpoint command for breakpoint 3.")

        # Read the output file produced by running the program.
        with open('output.txt', 'r') as f:
            output = f.read()

        self.expect(output,
                    "File 'output.txt' and the content matches",
                    exe=False,
                    startstr="lldb")

        with open('output2.txt', 'r') as f:
            output = f.read()

        self.expect(output,
                    "File 'output2.txt' and the content matches",
                    exe=False,
                    startstr="lldb")

        # Finish the program.
        self.runCmd("process continue")

        # Remove the breakpoint command associated with breakpoint 1.
        self.runCmd("breakpoint command delete 1")

        # Remove breakpoint 2.
        self.runCmd("breakpoint delete 2")

        self.expect(
            "breakpoint command list 1",
            startstr="Breakpoint 1 does not have an associated command.")
        self.expect(
            "breakpoint command list 2",
            error=True,
            startstr="error: '2' is not a currently valid breakpoint ID.")

        # The breakpoint list now only contains breakpoint 1.
        self.expect(
            "breakpoint list -f",
            "Breakpoint 1 exists",
            patterns=[
                "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1, resolved = 1"
                % self.line, "hit count = 1"
            ])

        # Not breakpoint 2.
        self.expect(
            "breakpoint list -f",
            "No more breakpoint 2",
            matching=False,
            substrs=[
                "2: file = 'main.c', line = %d, exact_match = 0, locations = 1, resolved = 1"
                % self.line
            ])

        # Run the program again, with breakpoint 1 remaining.
        self.runCmd("run", RUN_SUCCEEDED)

        # We should be stopped again due to breakpoint 1.

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list",
                    STOPPED_DUE_TO_BREAKPOINT,
                    substrs=['stopped', 'stop reason = breakpoint'])

        # The breakpoint should have a hit count of 2.
        self.expect("breakpoint list -f",
                    BREAKPOINT_HIT_TWICE,
                    substrs=['resolved, hit count = 2'])
예제 #8
0
    def breakpoint_command_sequence(self):
        """Test a sequence of breakpoint command add, list, and delete."""
        exe = self.getBuildArtifact("a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Add three breakpoints on the same line.  The first time we don't specify the file,
        # since the default file is the one containing main:
        lldbutil.run_break_set_by_file_and_line(
            self, None, self.line, num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
        # Breakpoint 4 - set at the same location as breakpoint 1 to test
        # setting breakpoint commands on two breakpoints at a time
        lldbutil.run_break_set_by_file_and_line(
            self, None, self.line, num_expected_locations=1, loc_exact=True)
        # Make sure relative path source breakpoints work as expected. We test
        # with partial paths with and without "./" prefixes.
        lldbutil.run_break_set_by_file_and_line(
            self, "./main.c", self.line,
            num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "breakpoint_command/main.c", self.line,
            num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "./breakpoint_command/main.c", self.line,
            num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "breakpoint/breakpoint_command/main.c", self.line,
            num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "./breakpoint/breakpoint_command/main.c", self.line,
            num_expected_locations=1, loc_exact=True)
        # Test relative breakpoints with incorrect paths and make sure we get
        # no breakpoint locations
        lldbutil.run_break_set_by_file_and_line(
            self, "invalid/main.c", self.line,
            num_expected_locations=0, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(
            self, "./invalid/main.c", self.line,
            num_expected_locations=0, loc_exact=True)
        # Now add callbacks for the breakpoints just created.
        self.runCmd(
            "breakpoint command add -s command -o 'frame variable --show-types --scope' 1 4")
        self.runCmd(
            "breakpoint command add -s python -o 'import side_effect; side_effect.one_liner = \"one liner was here\"' 2")
        self.runCmd(
            "breakpoint command add --python-function bktptcmd.function 3")

        # Check that the breakpoint commands are correctly set.

        # The breakpoint list now only contains breakpoint 1.
        self.expect(
            "breakpoint list", "Breakpoints 1 & 2 created", substrs=[
                "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" %
                self.line], patterns=[
                "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" %
                self.line])

        self.expect(
            "breakpoint list -f",
            "Breakpoints 1 & 2 created",
            substrs=[
                "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" %
                self.line],
            patterns=[
                "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" %
                self.line,
                "1.1: .+at main.c:%d:?[0-9]*, .+unresolved, hit count = 0" %
                self.line,
                "2.1: .+at main.c:%d:?[0-9]*, .+unresolved, hit count = 0" %
                self.line])

        self.expect("breakpoint command list 1", "Breakpoint 1 command ok",
                    substrs=["Breakpoint commands:",
                             "frame variable --show-types --scope"])
        self.expect("breakpoint command list 2", "Breakpoint 2 command ok",
                    substrs=["Breakpoint commands (Python):",
                             "import side_effect",
                             "side_effect.one_liner"])
        self.expect("breakpoint command list 3", "Breakpoint 3 command ok",
                    substrs=["Breakpoint commands (Python):",
                             "bktptcmd.function(frame, bp_loc, internal_dict)"])

        self.expect("breakpoint command list 4", "Breakpoint 4 command ok",
                    substrs=["Breakpoint commands:",
                             "frame variable --show-types --scope"])

        self.runCmd("breakpoint delete 4")

        self.runCmd("command script import --allow-reload ./bktptcmd.py")

        # Next lets try some other breakpoint kinds.  First break with a regular expression
        # and then specify only one file.  The first time we should get two locations,
        # the second time only one:

        lldbutil.run_break_set_by_regexp(
            self, r"._MyFunction", num_expected_locations=2)

        lldbutil.run_break_set_by_regexp(
            self,
            r"._MyFunction",
            extra_options="-f a.c",
            num_expected_locations=1)

        lldbutil.run_break_set_by_regexp(
            self,
            r"._MyFunction",
            extra_options="-f a.c -f b.c",
            num_expected_locations=2)

        # Now try a source regex breakpoint:
        lldbutil.run_break_set_by_source_regexp(
            self,
            r"is about to return [12]0",
            extra_options="-f a.c -f b.c",
            num_expected_locations=2)

        lldbutil.run_break_set_by_source_regexp(
            self,
            r"is about to return [12]0",
            extra_options="-f a.c",
            num_expected_locations=1)

        # Reset our canary variables and run the program.
        side_effect.one_liner = None
        side_effect.bktptcmd = None
        self.runCmd("run", RUN_SUCCEEDED)

        # Check the value of canary variables.
        self.assertEquals("one liner was here", side_effect.one_liner)
        self.assertEquals("function was here", side_effect.bktptcmd)

        # Finish the program.
        self.runCmd("process continue")

        # Remove the breakpoint command associated with breakpoint 1.
        self.runCmd("breakpoint command delete 1")

        # Remove breakpoint 2.
        self.runCmd("breakpoint delete 2")

        self.expect(
            "breakpoint command list 1",
            startstr="Breakpoint 1 does not have an associated command.")
        self.expect(
            "breakpoint command list 2",
            error=True,
            startstr="error: '2' is not a currently valid breakpoint ID.")

        # The breakpoint list now only contains breakpoint 1.
        self.expect(
            "breakpoint list -f",
            "Breakpoint 1 exists",
            patterns=[
                "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" %
                self.line,
                "hit count = 1"])

        # Not breakpoint 2.
        self.expect(
            "breakpoint list -f",
            "No more breakpoint 2",
            matching=False,
            substrs=[
                "2: file = 'main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" %
                self.line])

        # Run the program again, with breakpoint 1 remaining.
        self.runCmd("run", RUN_SUCCEEDED)

        # We should be stopped again due to breakpoint 1.

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
                    substrs=['stopped',
                             'stop reason = breakpoint'])

        # The breakpoint should have a hit count of 2.
        self.expect("breakpoint list -f", BREAKPOINT_HIT_TWICE,
                    substrs=['resolved, hit count = 2'])
예제 #9
0
    def breakpoint_command_sequence(self):
        """Test a sequence of breakpoint command add, list, and delete."""
        exe = os.path.join(os.getcwd(), "a.out")
        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

        # Add three breakpoints on the same line.  The first time we don't specify the file,
        # since the default file is the one containing main:
        lldbutil.run_break_set_by_file_and_line(self, None, self.line, num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
        lldbutil.run_break_set_by_file_and_line(self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
        # Breakpoint 4 - set at the same location as breakpoint 1 to test
        # setting breakpoint commands on two breakpoints at a time
        lldbutil.run_break_set_by_file_and_line(self, None, self.line, num_expected_locations=1, loc_exact=True)

        # Now add callbacks for the breakpoints just created.
        self.runCmd("breakpoint command add -s command -o 'frame variable --show-types --scope' 1 4")
        self.runCmd(
            'breakpoint command add -s python -o \'here = open("output.txt", "w"); here.write("lldb\\n"); here.close()\' 2'
        )
        self.runCmd("breakpoint command add --python-function bktptcmd.function 3")

        # Check that the breakpoint commands are correctly set.

        # The breakpoint list now only contains breakpoint 1.
        self.expect(
            "breakpoint list",
            "Breakpoints 1 & 2 created",
            substrs=["2: file = 'main.c', line = %d, exact_match = 0, locations = 1" % self.line],
            patterns=["1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" % self.line],
        )

        self.expect(
            "breakpoint list -f",
            "Breakpoints 1 & 2 created",
            substrs=["2: file = 'main.c', line = %d, exact_match = 0, locations = 1" % self.line],
            patterns=[
                "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" % self.line,
                "1.1: .+at main.c:%d, .+unresolved, hit count = 0" % self.line,
                "2.1: .+at main.c:%d, .+unresolved, hit count = 0" % self.line,
            ],
        )

        self.expect(
            "breakpoint command list 1",
            "Breakpoint 1 command ok",
            substrs=["Breakpoint commands:", "frame variable --show-types --scope"],
        )
        self.expect(
            "breakpoint command list 2",
            "Breakpoint 2 command ok",
            substrs=["Breakpoint commands (Python):", "here = open", "here.write", "here.close()"],
        )
        self.expect(
            "breakpoint command list 3",
            "Breakpoint 3 command ok",
            substrs=["Breakpoint commands (Python):", "bktptcmd.function(frame, bp_loc, internal_dict)"],
        )

        self.expect(
            "breakpoint command list 4",
            "Breakpoint 4 command ok",
            substrs=["Breakpoint commands:", "frame variable --show-types --scope"],
        )

        self.runCmd("breakpoint delete 4")

        self.runCmd("command script import --allow-reload ./bktptcmd.py")

        # Next lets try some other breakpoint kinds.  First break with a regular expression
        # and then specify only one file.  The first time we should get two locations,
        # the second time only one:

        lldbutil.run_break_set_by_regexp(self, r"._MyFunction", num_expected_locations=2)

        lldbutil.run_break_set_by_regexp(self, r"._MyFunction", extra_options="-f a.c", num_expected_locations=1)

        lldbutil.run_break_set_by_regexp(self, r"._MyFunction", extra_options="-f a.c -f b.c", num_expected_locations=2)

        # Now try a source regex breakpoint:
        lldbutil.run_break_set_by_source_regexp(
            self, r"is about to return [12]0", extra_options="-f a.c -f b.c", num_expected_locations=2
        )

        lldbutil.run_break_set_by_source_regexp(
            self, r"is about to return [12]0", extra_options="-f a.c", num_expected_locations=1
        )

        # Run the program.  Remove 'output.txt' if it exists.
        self.RemoveTempFile("output.txt")
        self.RemoveTempFile("output2.txt")
        self.runCmd("run", RUN_SUCCEEDED)

        # Check that the file 'output.txt' exists and contains the string
        # "lldb".

        # The 'output.txt' file should now exist.
        self.assertTrue(os.path.isfile("output.txt"), "'output.txt' exists due to breakpoint command for breakpoint 2.")
        self.assertTrue(
            os.path.isfile("output2.txt"), "'output2.txt' exists due to breakpoint command for breakpoint 3."
        )

        # Read the output file produced by running the program.
        with open("output.txt", "r") as f:
            output = f.read()

        self.expect(output, "File 'output.txt' and the content matches", exe=False, startstr="lldb")

        with open("output2.txt", "r") as f:
            output = f.read()

        self.expect(output, "File 'output2.txt' and the content matches", exe=False, startstr="lldb")

        # Finish the program.
        self.runCmd("process continue")

        # Remove the breakpoint command associated with breakpoint 1.
        self.runCmd("breakpoint command delete 1")

        # Remove breakpoint 2.
        self.runCmd("breakpoint delete 2")

        self.expect("breakpoint command list 1", startstr="Breakpoint 1 does not have an associated command.")
        self.expect(
            "breakpoint command list 2", error=True, startstr="error: '2' is not a currently valid breakpoint ID."
        )

        # The breakpoint list now only contains breakpoint 1.
        self.expect(
            "breakpoint list -f",
            "Breakpoint 1 exists",
            patterns=[
                "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" % self.line,
                "hit count = 1",
            ],
        )

        # Not breakpoint 2.
        self.expect(
            "breakpoint list -f",
            "No more breakpoint 2",
            matching=False,
            substrs=["2: file = 'main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" % self.line],
        )

        # Run the program again, with breakpoint 1 remaining.
        self.runCmd("run", RUN_SUCCEEDED)

        # We should be stopped again due to breakpoint 1.

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=["stopped", "stop reason = breakpoint"])

        # The breakpoint should have a hit count of 2.
        self.expect("breakpoint list -f", BREAKPOINT_HIT_TWICE, substrs=["resolved, hit count = 2"])