File: TestBreakpointAutoContinue.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (107 lines) | stat: -rw-r--r-- 3,670 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
Test that the breakpoint auto-continue flag works correctly.
"""


import lldb
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *


class BreakpointAutoContinue(TestBase):
    NO_DEBUG_INFO_TESTCASE = True

    def test_breakpoint_auto_continue(self):
        """Make sure the auto continue continues with no other complications"""
        self.build()
        self.simple_auto_continue()

    def test_auto_continue_with_command(self):
        """Add a command, make sure the command gets run"""
        self.build()
        self.auto_continue_with_command()

    def test_auto_continue_on_location(self):
        """Set auto-continue on a location and make sure only that location continues"""
        self.build()
        self.auto_continue_location()

    def make_target_and_bkpt(
        self,
        additional_options=None,
        num_expected_loc=1,
        pattern="Set a breakpoint here",
    ):
        self.target = self.createTestTarget()

        extra_options_txt = "--auto-continue 1 "
        if additional_options:
            extra_options_txt += additional_options
        bpno = lldbutil.run_break_set_by_source_regexp(
            self,
            pattern,
            extra_options=extra_options_txt,
            num_expected_locations=num_expected_loc,
        )
        return bpno

    def launch_it(self, expected_state):
        error = lldb.SBError()
        launch_info = self.target.GetLaunchInfo()
        launch_info.SetWorkingDirectory(self.get_process_working_directory())

        process = self.target.Launch(launch_info, error)
        self.assertSuccess(error, "Launch failed.")

        state = process.GetState()
        self.assertEqual(state, expected_state, "Didn't get expected state")

        return process

    def simple_auto_continue(self):
        bpno = self.make_target_and_bkpt()
        process = self.launch_it(lldb.eStateExited)

        bkpt = self.target.FindBreakpointByID(bpno)
        self.assertEqual(
            bkpt.GetHitCount(), 2, "Should have run through the breakpoint twice"
        )

    def auto_continue_with_command(self):
        bpno = self.make_target_and_bkpt(
            "-N BKPT -C 'break modify --auto-continue 0 BKPT'"
        )
        process = self.launch_it(lldb.eStateStopped)
        state = process.GetState()
        self.assertState(state, lldb.eStateStopped, "Process should be stopped")
        bkpt = self.target.FindBreakpointByID(bpno)
        threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
        self.assertEqual(
            len(threads), 1, "There was a thread stopped at our breakpoint"
        )
        self.assertEqual(bkpt.GetHitCount(), 2, "Should have hit the breakpoint twice")

    def auto_continue_location(self):
        bpno = self.make_target_and_bkpt(
            pattern="Set a[^ ]* breakpoint here", num_expected_loc=2
        )
        bkpt = self.target.FindBreakpointByID(bpno)
        bkpt.SetAutoContinue(False)

        loc = lldb.SBBreakpointLocation()
        for i in range(0, 2):
            func_name = bkpt.location[i].GetAddress().function.name
            if func_name == "main":
                loc = bkpt.location[i]

        self.assertTrue(loc.IsValid(), "Didn't find a location in main")
        loc.SetAutoContinue(True)

        process = self.launch_it(lldb.eStateStopped)

        threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
        self.assertEqual(
            len(threads), 1, "Didn't get one thread stopped at our breakpoint"
        )
        func_name = threads[0].frame[0].function.name
        self.assertEqual(func_name, "call_me")