1 """Test the 'step target' feature."""
3 from __future__ import print_function
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9 from lldbsuite.test import lldbutil
11 class TestStepTarget(TestBase):
13 mydir = TestBase.compute_mydir(__file__)
15 def getCategories(self):
16 return ['basic_process']
19 # Call super's setUp().
21 # Find the line numbers that we will step to in main:
22 self.main_source = "main.c"
23 self.end_line = line_number(self.main_source, "All done")
25 @add_test_categories(['pyapi'])
27 def get_to_start (self):
29 exe = os.path.join(os.getcwd(), "a.out")
31 target = self.dbg.CreateTarget(exe)
32 self.assertTrue(target, VALID_TARGET)
34 self.main_source_spec = lldb.SBFileSpec (self.main_source)
36 break_in_main = target.BreakpointCreateBySourceRegex ('Break here to try targetted stepping', self.main_source_spec)
37 self.assertTrue(break_in_main, VALID_BREAKPOINT)
38 self.assertTrue(break_in_main.GetNumLocations() > 0,"Has locations.")
40 # Now launch the process, and do not stop at entry point.
41 process = target.LaunchSimple (None, None, self.get_process_working_directory())
43 self.assertTrue(process, PROCESS_IS_VALID)
45 # The stop reason of the thread should be breakpoint.
46 threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_in_main)
49 self.fail ("Failed to stop at first breakpoint in main.")
54 def test_with_end_line(self):
55 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
57 thread = self.get_to_start()
59 error = lldb.SBError()
60 thread.StepInto("lotsOfArgs", self.end_line, error)
61 frame = thread.frames[0]
63 self.assertTrue (frame.name == "lotsOfArgs", "Stepped to lotsOfArgs.")
65 def test_with_end_line_bad_name(self):
66 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
68 thread = self.get_to_start()
70 error = lldb.SBError()
71 thread.StepInto("lotsOfArgssss", self.end_line, error)
72 frame = thread.frames[0]
73 self.assertTrue (frame.line_entry.line == self.end_line, "Stepped to the block end.")
75 def test_with_end_line_deeper(self):
76 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
78 thread = self.get_to_start()
80 error = lldb.SBError()
81 thread.StepInto("modifyInt", self.end_line, error)
82 frame = thread.frames[0]
83 self.assertTrue (frame.name == "modifyInt", "Stepped to modifyInt.")
85 def test_with_command_and_block(self):
86 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
88 thread = self.get_to_start()
90 result = lldb.SBCommandReturnObject()
91 self.dbg.GetCommandInterpreter().HandleCommand('thread step-in -t "lotsOfArgs" -e block', result)
92 self.assertTrue(result.Succeeded(), "thread step-in command succeeded.")
94 frame = thread.frames[0]
95 self.assertTrue (frame.name == "lotsOfArgs", "Stepped to lotsOfArgs.")
97 def test_with_command_and_block_and_bad_name(self):
98 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
100 thread = self.get_to_start()
102 result = lldb.SBCommandReturnObject()
103 self.dbg.GetCommandInterpreter().HandleCommand('thread step-in -t "lotsOfArgsssss" -e block', result)
104 self.assertTrue(result.Succeeded(), "thread step-in command succeeded.")
106 frame = thread.frames[0]
108 self.assertTrue (frame.name == "main", "Stepped back out to main.")
109 # end_line is set to the line after the containing block. Check that we got there:
110 self.assertTrue(frame.line_entry.line == self.end_line, "Got out of the block")