• 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
5import os
6import unittest2
7import lldb
8import lldbutil
9from lldbtest import *
10
11class LongjmpTestCase(TestBase):
12
13    mydir = os.path.join("functionalities", "longjmp")
14
15    def setUp(self):
16        TestBase.setUp(self)
17
18    @skipIfDarwin # llvm.org/pr16769: LLDB on Mac OS X dies in function ReadRegisterBytes in GDBRemoteRegisterContext.cpp
19    def test_step_out(self):
20        """Test stepping when the inferior calls setjmp/longjmp, in particular, thread step-out."""
21        self.buildDefault()
22        self.step_out()
23
24    @skipIfDarwin # llvm.org/pr16769: LLDB on Mac OS X dies in function ReadRegisterBytes in GDBRemoteRegisterContext.cpp
25    def test_step_over(self):
26        """Test stepping when the inferior calls setjmp/longjmp, in particular, thread step-over a longjmp."""
27        self.buildDefault()
28        self.step_over()
29
30    @skipIfDarwin # llvm.org/pr16769: LLDB on Mac OS X dies in function ReadRegisterBytes in GDBRemoteRegisterContext.cpp
31    def test_step_back_out(self):
32        """Test stepping when the inferior calls setjmp/longjmp, in particular, thread step-out after thread step-in."""
33        self.buildDefault()
34        self.step_back_out()
35
36    def start_test(self, symbol):
37        exe = os.path.join(os.getcwd(), "a.out")
38
39        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
40
41        # Break in main().
42        lldbutil.run_break_set_by_symbol (self, symbol, num_expected_locations=-1)
43
44        self.runCmd("run", RUN_SUCCEEDED)
45
46        # The stop reason of the thread should be breakpoint.
47        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
48            substrs = ['stopped', 'stop reason = breakpoint'])
49
50    def check_status(self):
51        # Note: Depending on the generated mapping of DWARF to assembly,
52        # the process may have stopped or exited.
53        self.expect("process status", PROCESS_STOPPED,
54            patterns = ['Process .* exited with status = 0'])
55
56    def step_out(self):
57        self.start_test("do_jump")
58        self.runCmd("thread step-out", RUN_SUCCEEDED)
59        self.check_status()
60
61    def step_over(self):
62        self.start_test("do_jump")
63        self.runCmd("thread step-over", RUN_SUCCEEDED)
64        self.runCmd("thread step-over", RUN_SUCCEEDED)
65        self.check_status()
66
67    def step_back_out(self):
68        self.start_test("main")
69
70        self.runCmd("thread step-over", RUN_SUCCEEDED)
71        self.runCmd("thread step-in", RUN_SUCCEEDED)
72        self.runCmd("thread step-out", RUN_SUCCEEDED)
73        self.check_status()
74
75if __name__ == '__main__':
76    import atexit
77    lldb.SBDebugger.Initialize()
78    atexit.register(lambda: lldb.SBDebugger.Terminate())
79    unittest2.main()
80