• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Test the use of setjmp/longjmp for non-local goto operations in a single-threaded inferior.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class LongjmpTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    @skipIfDarwin  # llvm.org/pr16769: LLDB on Mac OS X dies in function ReadRegisterBytes in GDBRemoteRegisterContext.cpp
18    @expectedFailureAll(oslist=["freebsd", "linux"], bugnumber="llvm.org/pr20231")
19    @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778")
20    @expectedFlakeyNetBSD
21    def test_step_out(self):
22        """Test stepping when the inferior calls setjmp/longjmp, in particular, thread step-out."""
23        self.build()
24        self.step_out()
25
26    @skipIfDarwin  # llvm.org/pr16769: LLDB on Mac OS X dies in function ReadRegisterBytes in GDBRemoteRegisterContext.cpp
27    @expectedFailureAll(oslist=["freebsd", "linux"], bugnumber="llvm.org/pr20231")
28    @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778")
29    @skipIfNetBSD
30    def test_step_over(self):
31        """Test stepping when the inferior calls setjmp/longjmp, in particular, thread step-over a longjmp."""
32        self.build()
33        self.step_over()
34
35    @skipIfDarwin  # llvm.org/pr16769: LLDB on Mac OS X dies in function ReadRegisterBytes in GDBRemoteRegisterContext.cpp
36    @expectedFailureAll(oslist=["freebsd", "linux"], bugnumber="llvm.org/pr20231")
37    @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778")
38    @expectedFlakeyNetBSD
39    def test_step_back_out(self):
40        """Test stepping when the inferior calls setjmp/longjmp, in particular, thread step-out after thread step-in."""
41        self.build()
42        self.step_back_out()
43
44    def start_test(self, symbol):
45        exe = self.getBuildArtifact("a.out")
46
47        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
48
49        # Break in main().
50        lldbutil.run_break_set_by_symbol(
51            self, symbol, num_expected_locations=-1)
52
53        self.runCmd("run", RUN_SUCCEEDED)
54
55        # The stop reason of the thread should be breakpoint.
56        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
57                    substrs=['stopped', 'stop reason = breakpoint'])
58
59    def check_status(self):
60        # Note: Depending on the generated mapping of DWARF to assembly,
61        # the process may have stopped or exited.
62        self.expect("process status", PROCESS_STOPPED,
63                    patterns=['Process .* exited with status = 0'])
64
65    def step_out(self):
66        self.start_test("do_jump")
67        self.runCmd("thread step-out", RUN_SUCCEEDED)
68        self.check_status()
69
70    def step_over(self):
71        self.start_test("do_jump")
72        self.runCmd("thread step-over", RUN_SUCCEEDED)
73        self.runCmd("thread step-over", RUN_SUCCEEDED)
74        self.check_status()
75
76    def step_back_out(self):
77        self.start_test("main")
78
79        self.runCmd("thread step-over", RUN_SUCCEEDED)
80        self.runCmd("thread step-in", RUN_SUCCEEDED)
81        self.runCmd("thread step-out", RUN_SUCCEEDED)
82        self.check_status()
83