]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/thread/step_out/TestThreadStepOut.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / thread / step_out / TestThreadStepOut.py
1 """
2 Test stepping out from a function in a multi-threaded program.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import lldb
11 from lldbsuite.test.lldbtest import *
12 import lldbsuite.test.lldbutil as lldbutil
13
14 class ThreadStepOutTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     @skipIfLinux                              # Test occasionally times out on the Linux build bot
19     @expectedFailureLinux("llvm.org/pr23477") # Test occasionally times out on the Linux build bot
20     @expectedFailureFreeBSD("llvm.org/pr18066") # inferior does not exit
21     @expectedFailureWindows # Test crashes
22     def test_step_single_thread(self):
23         """Test thread step out on one thread via command interpreter. """
24         self.build(dictionary=self.getBuildFlags())
25         self.step_out_test(self.step_out_single_thread_with_cmd)
26
27     @skipIfLinux                              # Test occasionally times out on the Linux build bot
28     @expectedFailureLinux("llvm.org/pr23477") # Test occasionally times out on the Linux build bot
29     @expectedFailureFreeBSD("llvm.org/pr19347") # 2nd thread stops at breakpoint
30     @expectedFailureWindows # Test crashes
31     def test_step_all_threads(self):
32         """Test thread step out on all threads via command interpreter. """
33         self.build(dictionary=self.getBuildFlags())
34         self.step_out_test(self.step_out_all_threads_with_cmd)
35
36     @skipIfLinux                              # Test occasionally times out on the Linux build bot
37     @expectedFailureLinux("llvm.org/pr23477") # Test occasionally times out on the Linux build bot
38     @expectedFailureFreeBSD("llvm.org/pr19347")
39     @expectedFailureWindows("llvm.org/pr24681")
40     def test_python(self):
41         """Test thread step out on one thread via Python API (dwarf)."""
42         self.build(dictionary=self.getBuildFlags())
43         self.step_out_test(self.step_out_with_python)
44
45     def setUp(self):
46         # Call super's setUp().
47         TestBase.setUp(self)
48         # Find the line number for our breakpoint.
49         self.breakpoint = line_number('main.cpp', '// Set breakpoint here')
50         if "gcc" in self.getCompiler() or self.isIntelCompiler(): 
51             self.step_out_destination = line_number('main.cpp', '// Expect to stop here after step-out (icc and gcc)')
52         else:
53             self.step_out_destination = line_number('main.cpp', '// Expect to stop here after step-out (clang)')
54
55     def step_out_single_thread_with_cmd(self):
56         self.step_out_with_cmd("this-thread")
57         self.expect("thread backtrace all", "Thread location after step out is correct",
58             substrs = ["main.cpp:%d" % self.step_out_destination,
59                        "main.cpp:%d" % self.breakpoint])
60
61     def step_out_all_threads_with_cmd(self):
62         self.step_out_with_cmd("all-threads")
63         self.expect("thread backtrace all", "Thread location after step out is correct",
64             substrs = ["main.cpp:%d" % self.step_out_destination])
65
66     def step_out_with_cmd(self, run_mode):
67         self.runCmd("thread select %d" % self.step_out_thread.GetIndexID())
68         self.runCmd("thread step-out -m %s" % run_mode)
69         self.expect("process status", "Expected stop reason to be step-out",
70             substrs = ["stop reason = step out"])
71
72         self.expect("thread list", "Selected thread did not change during step-out",
73             substrs = ["* thread #%d" % self.step_out_thread.GetIndexID()])
74
75     def step_out_with_python(self):
76         self.step_out_thread.StepOut()
77
78         reason = self.step_out_thread.GetStopReason()
79         self.assertEqual(lldb.eStopReasonPlanComplete, reason,
80             "Expected thread stop reason 'plancomplete', but got '%s'" % lldbutil.stop_reason_to_str(reason))
81
82         # Verify location after stepping out
83         frame = self.step_out_thread.GetFrameAtIndex(0)
84         desc = lldbutil.get_description(frame.GetLineEntry())
85         expect = "main.cpp:%d" % self.step_out_destination
86         self.assertTrue(expect in desc, "Expected %s but thread stopped at %s" % (expect, desc))
87
88     def step_out_test(self, step_out_func):
89         """Test single thread step out of a function."""
90         exe = os.path.join(os.getcwd(), "a.out")
91         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
92
93         # This should create a breakpoint in the main thread.
94         lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.breakpoint, num_expected_locations=1)
95
96         # The breakpoint list should show 1 location.
97         self.expect("breakpoint list -f", "Breakpoint location shown correctly",
98             substrs = ["1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" % self.breakpoint])
99
100         # Run the program.
101         self.runCmd("run", RUN_SUCCEEDED)
102
103         # Get the target process
104         self.inferior_target = self.dbg.GetSelectedTarget()
105         self.inferior_process = self.inferior_target.GetProcess()
106
107         # Get the number of threads, ensure we see all three.
108         num_threads = self.inferior_process.GetNumThreads()
109         self.assertEqual(num_threads, 3, 'Number of expected threads and actual threads do not match.')
110
111         (breakpoint_threads, other_threads) = ([], [])
112         lldbutil.sort_stopped_threads(self.inferior_process,
113                                       breakpoint_threads=breakpoint_threads,
114                                       other_threads=other_threads)
115
116         while len(breakpoint_threads) < 2:
117             self.runCmd("thread continue %s" % " ".join([str(x.GetIndexID()) for x in other_threads]))
118             lldbutil.sort_stopped_threads(self.inferior_process,
119                                           breakpoint_threads=breakpoint_threads,
120                                           other_threads=other_threads)
121
122         self.step_out_thread = breakpoint_threads[0]
123
124         # Step out of thread stopped at breakpoint
125         step_out_func()
126
127         # Run to completion
128         self.runCmd("continue")
129
130         # At this point, the inferior process should have exited.
131         self.assertTrue(self.inferior_process.GetState() == lldb.eStateExited, PROCESS_EXITED)