xref: /llvm-project/lldb/test/API/functionalities/thread/jump/TestThreadJump.py (revision 4cc8f2a017c76af25234afc7c380550e9c93135c)
1"""
2Test jumping to different places.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class ThreadJumpTestCase(TestBase):
14
15    def test(self):
16        """Test thread jump handling."""
17        self.build()
18        exe = self.getBuildArtifact("a.out")
19        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
20
21        # Find the line numbers for our breakpoints.
22        self.mark1 = line_number('main.cpp', '// 1st marker')
23        self.mark2 = line_number('main.cpp', '// 2nd marker')
24        self.mark3 = line_number('main.cpp', '// 3rd marker')
25        self.mark4 = line_number('main.cpp', '// 4th marker')
26        self.mark5 = line_number('other.cpp', '// other marker')
27
28        lldbutil.run_break_set_by_file_and_line(
29            self, "main.cpp", self.mark3, num_expected_locations=1)
30        self.runCmd("run", RUN_SUCCEEDED)
31
32        # The stop reason of the thread should be breakpoint 1.
33        self.expect(
34            "thread list",
35            STOPPED_DUE_TO_BREAKPOINT + " 1",
36            substrs=[
37                'stopped',
38                'main.cpp:{}'.format(
39                    self.mark3),
40                'stop reason = breakpoint 1'])
41
42        # Try the int path, force it to return 'a'
43        self.do_min_test(self.mark3, self.mark1, "i", "4")
44        # Try the int path, force it to return 'b'
45        self.do_min_test(self.mark3, self.mark2, "i", "5")
46        # Try the double path, force it to return 'a'
47        self.do_min_test(self.mark4, self.mark1, "j", "7")
48        # Expected to fail on powerpc64le architecture
49        if not self.isPPC64le():
50            # Try the double path, force it to return 'b'
51            self.do_min_test(self.mark4, self.mark2, "j", "8")
52
53        # Try jumping to another function in a different file.
54        self.runCmd(
55            "thread jump --file other.cpp --line %i --force" %
56            self.mark5)
57        self.expect("process status",
58                    substrs=["at other.cpp:%i" % self.mark5])
59
60        # Try jumping to another function (without forcing)
61        self.expect(
62            "j main.cpp:%i" %
63            self.mark1,
64            COMMAND_FAILED_AS_EXPECTED,
65            error=True,
66            substrs=["error"])
67
68    def do_min_test(self, start, jump, var, value):
69        # jump to the start marker
70        self.runCmd("j %i" % start)
71        self.runCmd("thread step-in")                   # step into the min fn
72        # jump to the branch we're interested in
73        self.runCmd("j %i" % jump)
74        self.runCmd("thread step-out")                  # return out
75        self.runCmd("thread step-over")                 # assign to the global
76        self.expect("expr %s" % var, substrs=[value])  # check it
77