]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/c/step-target/TestStepTarget.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / c / step-target / TestStepTarget.py
1 """Test the 'step target' feature."""
2
3 from __future__ import print_function
4
5 import os, time
6 import lldb
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9 from lldbsuite.test import lldbutil
10
11 class TestStepTarget(TestBase):
12
13     mydir = TestBase.compute_mydir(__file__)
14
15     def getCategories(self):
16         return ['basic_process']
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
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")
24
25     @add_test_categories(['pyapi'])
26
27     def get_to_start (self):
28         self.build()
29         exe = os.path.join(os.getcwd(), "a.out")
30
31         target = self.dbg.CreateTarget(exe)
32         self.assertTrue(target, VALID_TARGET)
33
34         self.main_source_spec = lldb.SBFileSpec (self.main_source)
35
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.")
39
40         # Now launch the process, and do not stop at entry point.
41         process = target.LaunchSimple (None, None, self.get_process_working_directory())
42
43         self.assertTrue(process, PROCESS_IS_VALID)
44
45         # The stop reason of the thread should be breakpoint.
46         threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_in_main)
47
48         if len(threads) != 1:
49             self.fail ("Failed to stop at first breakpoint in main.")
50
51         thread = threads[0]
52         return thread
53
54     def test_with_end_line(self):
55         """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
56
57         thread = self.get_to_start()
58
59         error = lldb.SBError()
60         thread.StepInto("lotsOfArgs", self.end_line, error)
61         frame = thread.frames[0]
62
63         self.assertTrue (frame.name == "lotsOfArgs", "Stepped to lotsOfArgs.")
64
65     def test_with_end_line_bad_name(self):
66         """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
67
68         thread = self.get_to_start()
69
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.")
74
75     def test_with_end_line_deeper(self):
76         """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
77
78         thread = self.get_to_start()
79
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.")
84
85     def test_with_command_and_block(self):
86         """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
87
88         thread = self.get_to_start()
89
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.")
93
94         frame = thread.frames[0]
95         self.assertTrue (frame.name == "lotsOfArgs", "Stepped to lotsOfArgs.")
96
97     def test_with_command_and_block_and_bad_name(self):
98         """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
99
100         thread = self.get_to_start()
101
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.")
105
106         frame = thread.frames[0]
107
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")
111
112
113