1""" 2Test thread stepping features in combination with frame select. 3""" 4 5 6 7import lldb 8from lldbsuite.test.lldbtest import * 9import lldbsuite.test.lldbutil as lldbutil 10 11 12class ThreadSteppingTestCase(TestBase): 13 14 mydir = TestBase.compute_mydir(__file__) 15 16 def setUp(self): 17 # Call super's setUp(). 18 TestBase.setUp(self) 19 # Find the line number to of function 'c'. 20 self.line1 = line_number( 21 'main.c', '// Find the line number of function "c" here.') 22 self.line2 = line_number( 23 'main.c', '// frame select 2, thread step-out while stopped at "c(1)"') 24 self.line3 = line_number( 25 'main.c', '// thread step-out while stopped at "c(2)"') 26 self.line4 = line_number( 27 'main.c', '// frame select 1, thread step-out while stopped at "c(3)"') 28 29 def test_step_out_with_run_command(self): 30 """Exercise thread step-out and frame select followed by thread step-out.""" 31 self.build() 32 exe = self.getBuildArtifact("a.out") 33 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 34 35 # Create a breakpoint inside function 'c'. 36 lldbutil.run_break_set_by_file_and_line( 37 self, "main.c", self.line1, num_expected_locations=1, loc_exact=True) 38 39 # Now run the program. 40 self.runCmd("run", RUN_SUCCEEDED) 41 42 # The process should be stopped at this point. 43 self.expect("process status", PROCESS_STOPPED, 44 patterns=['Process .* stopped']) 45 46 # The frame #0 should correspond to main.c:32, the executable statement 47 # in function name 'c'. And frame #3 should point to main.c:37. 48 self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, 49 substrs=["stop reason = breakpoint"], 50 patterns=["frame #0.*main.c:%d" % self.line1, 51 "frame #3.*main.c:%d" % self.line2]) 52 53 # We want to move the pc to frame #3. This can be accomplished by 54 # 'frame select 2', followed by 'thread step-out'. 55 self.runCmd("frame select 2") 56 self.runCmd("thread step-out") 57 self.expect("thread backtrace", STEP_OUT_SUCCEEDED, 58 substrs=["stop reason = step out"], 59 patterns=["frame #0.*main.c:%d" % self.line2]) 60 61 # Let's move on to a single step-out case. 62 self.runCmd("process continue") 63 64 # The process should be stopped at this point. 65 self.expect("process status", PROCESS_STOPPED, 66 patterns=['Process .* stopped']) 67 self.runCmd("thread step-out") 68 self.expect("thread backtrace", STEP_OUT_SUCCEEDED, 69 substrs=["stop reason = step out"], 70 patterns=["frame #0.*main.c:%d" % self.line3]) 71 72 # Do another frame selct, followed by thread step-out. 73 self.runCmd("process continue") 74 75 # The process should be stopped at this point. 76 self.expect("process status", PROCESS_STOPPED, 77 patterns=['Process .* stopped']) 78 self.runCmd("frame select 1") 79 self.runCmd("thread step-out") 80 self.expect("thread backtrace", STEP_OUT_SUCCEEDED, 81 substrs=["stop reason = step out"], 82 patterns=["frame #0.*main.c:%d" % self.line4]) 83