forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestStepUntilAPI.py
133 lines (114 loc) · 4.79 KB
/
TestStepUntilAPI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class TestStepUntilAPI(TestBase):
NO_DEBUG_INFO_TESTCASE = True
def setUp(self):
super().setUp()
self.main_source = "main.c"
self.main_spec = lldb.SBFileSpec(self.main_source)
self.less_than_two = line_number("main.c", "Less than 2")
self.greater_than_two = line_number("main.c", "Greater than or equal to 2.")
self.back_out_in_main = line_number("main.c", "Back out in main")
self.in_foo = line_number("main.c", "In foo")
def _build_dict_for_discontinuity(self):
return dict(
CFLAGS_EXTRAS="-funique-basic-block-section-names "
+ "-ffunction-sections -fbasic-block-sections=list="
+ self.getSourcePath("function.list"),
LD_EXTRAS="-Wl,--script=" + self.getSourcePath("symbol.order"),
)
def _do_until(self, build_dict, args, until_line, expected_line):
self.build(dictionary=build_dict)
launch_info = lldb.SBLaunchInfo(args)
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
self, "At the start", self.main_spec, launch_info
)
self.assertSuccess(
thread.StepOverUntil(self.frame(), self.main_spec, until_line)
)
self.runCmd("process status")
line = self.frame().GetLineEntry().GetLine()
self.assertEqual(
line, expected_line, "Did not get the expected stop line number"
)
def _assertDiscontinuity(self):
target = self.target()
foo = target.FindFunctions("foo")
self.assertEqual(len(foo), 1)
foo = foo[0]
call_me = self.target().FindFunctions("call_me")
self.assertEqual(len(call_me), 1)
call_me = call_me[0]
foo_addr = foo.function.GetStartAddress().GetLoadAddress(target)
found_before = False
found_after = False
for range in call_me.function.GetRanges():
addr = range.GetBaseAddress().GetLoadAddress(target)
if addr < foo_addr:
found_before = True
if addr > foo_addr:
found_after = True
self.assertTrue(
found_before and found_after,
"'foo' is not between 'call_me'" + str(foo) + str(call_me),
)
def test_hitting(self):
"""Test SBThread.StepOverUntil - targeting a line and hitting it."""
self._do_until(None, None, self.less_than_two, self.less_than_two)
@skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"])
def test_hitting_discontinuous(self):
"""Test SBThread.StepOverUntil - targeting a line and hitting it -- with
discontinuous functions"""
self._do_until(
self._build_dict_for_discontinuity(),
None,
self.less_than_two,
self.less_than_two,
)
self._assertDiscontinuity()
def test_missing(self):
"""Test SBThread.StepOverUntil - targeting a line and missing it by stepping out to call site"""
self._do_until(
None, ["foo", "bar", "baz"], self.less_than_two, self.back_out_in_main
)
@skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"])
def test_missing_discontinuous(self):
"""Test SBThread.StepOverUntil - targeting a line and missing it by
stepping out to call site -- with discontinuous functions"""
self._do_until(
self._build_dict_for_discontinuity(),
["foo", "bar", "baz"],
self.less_than_two,
self.back_out_in_main,
)
self._assertDiscontinuity()
def test_bad_line(self):
"""Test that we get an error if attempting to step outside the current
function"""
self.build()
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
self, "At the start", self.main_spec
)
self.assertIn(
"step until target not in current function",
thread.StepOverUntil(
self.frame(), self.main_spec, self.in_foo
).GetCString(),
)
@skipIf(oslist=lldbplatformutil.getDarwinOSTriples() + ["windows"])
def test_bad_line_discontinuous(self):
"""Test that we get an error if attempting to step outside the current
function -- and the function is discontinuous"""
self.build(dictionary=self._build_dict_for_discontinuity())
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
self, "At the start", self.main_spec
)
self.assertIn(
"step until target not in current function",
thread.StepOverUntil(
self.frame(), self.main_spec, self.in_foo
).GetCString(),
)
self._assertDiscontinuity()