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
|
"""
Watch contiguous memory regions with separate watchpoints, check that lldb
correctly detect which watchpoint was hit for each one.
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class ConsecutiveWatchpointsTestCase(TestBase):
NO_DEBUG_INFO_TESTCASE = True
def continue_and_report_stop_reason(self, process, iter_str):
process.Continue()
self.assertIn(
process.GetState(), [lldb.eStateStopped, lldb.eStateExited], iter_str
)
thread = process.GetSelectedThread()
return thread.GetStopReason()
# debugserver only gained the ability to watch larger regions
# with this patch.
@skipIfOutOfTreeDebugserver
def test_consecutive_watchpoints(self):
"""Test watchpoint that covers a large region of memory."""
self.build()
self.main_source_file = lldb.SBFileSpec("main.c")
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "break here", self.main_source_file
)
frame = thread.GetFrameAtIndex(0)
field2_wp = (
frame.locals["var"][0]
.GetChildMemberWithName("field2")
.Watch(True, False, True)
)
field3_wp = (
frame.locals["var"][0]
.GetChildMemberWithName("field3")
.Watch(True, False, True)
)
field4_wp = (
frame.locals["var"][0]
.GetChildMemberWithName("field4")
.Watch(True, False, True)
)
field5_wp = (
frame.locals["var"][0]
.GetChildMemberWithName("field5")
.Watch(True, False, True)
)
# Require that the first two watchpoints
# are set -- hopefully every machine running
# the testsuite can support two watchpoints.
self.assertTrue(field2_wp.IsValid())
self.assertTrue(field3_wp.IsValid())
reason = self.continue_and_report_stop_reason(process, "continue to field2 wp")
self.assertEqual(reason, lldb.eStopReasonWatchpoint)
stop_reason_watchpoint_id = (
process.GetSelectedThread().GetStopReasonDataAtIndex(0)
)
self.assertEqual(stop_reason_watchpoint_id, field2_wp.GetID())
reason = self.continue_and_report_stop_reason(process, "continue to field3 wp")
self.assertEqual(reason, lldb.eStopReasonWatchpoint)
stop_reason_watchpoint_id = (
process.GetSelectedThread().GetStopReasonDataAtIndex(0)
)
self.assertEqual(stop_reason_watchpoint_id, field3_wp.GetID())
# If we were able to set the second two watchpoints,
# check that they are hit. Some CI bots can only
# create two watchpoints.
if field4_wp.IsValid() and field5_wp.IsValid():
reason = self.continue_and_report_stop_reason(
process, "continue to field4 wp"
)
self.assertEqual(reason, lldb.eStopReasonWatchpoint)
stop_reason_watchpoint_id = (
process.GetSelectedThread().GetStopReasonDataAtIndex(0)
)
self.assertEqual(stop_reason_watchpoint_id, field4_wp.GetID())
reason = self.continue_and_report_stop_reason(
process, "continue to field5 wp"
)
self.assertEqual(reason, lldb.eStopReasonWatchpoint)
stop_reason_watchpoint_id = (
process.GetSelectedThread().GetStopReasonDataAtIndex(0)
)
self.assertEqual(stop_reason_watchpoint_id, field5_wp.GetID())
|