Skip to content

Commit 1bf1a11

Browse files
committed
Split out qMemoryRegion tests
1 parent 9a92684 commit 1bf1a11

File tree

2 files changed

+218
-203
lines changed

2 files changed

+218
-203
lines changed
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
import binascii
2+
import itertools
3+
import struct
4+
5+
import gdbremote_testcase
6+
import lldbgdbserverutils
7+
from lldbsuite.support import seven
8+
from lldbsuite.test.decorators import *
9+
from lldbsuite.test.lldbtest import *
10+
from lldbsuite.test.lldbdwarf import *
11+
from lldbsuite.test import lldbutil, lldbplatformutil
12+
13+
14+
class TestGdbRemote_qMemoryRegion(gdbremote_testcase.GdbRemoteTestCaseBase):
15+
16+
def test_qMemoryRegionInfo_is_supported(self):
17+
self.build()
18+
self.set_inferior_startup_launch()
19+
# Start up the inferior.
20+
procs = self.prep_debug_monitor_and_inferior()
21+
22+
# Ask if it supports $qMemoryRegionInfo.
23+
self.test_sequence.add_log_lines(
24+
["read packet: $qMemoryRegionInfo#00", "send packet: $OK#00"], True
25+
)
26+
self.expect_gdbremote_sequence()
27+
28+
@skipIfWindows # No pty support to test any inferior output
29+
def test_qMemoryRegionInfo_reports_code_address_as_executable(self):
30+
self.build()
31+
self.set_inferior_startup_launch()
32+
33+
# Start up the inferior.
34+
procs = self.prep_debug_monitor_and_inferior(
35+
inferior_args=["get-code-address-hex:hello", "sleep:5"]
36+
)
37+
38+
# Run the process
39+
self.test_sequence.add_log_lines(
40+
[
41+
# Start running after initial stop.
42+
"read packet: $c#63",
43+
# Match output line that prints the memory address of the message buffer within the inferior.
44+
# Note we require launch-only testing so we can get inferior otuput.
45+
{
46+
"type": "output_match",
47+
"regex": self.maybe_strict_output_regex(
48+
r"code address: 0x([0-9a-fA-F]+)\r\n"
49+
),
50+
"capture": {1: "code_address"},
51+
},
52+
# Now stop the inferior.
53+
"read packet: {}".format(chr(3)),
54+
# And wait for the stop notification.
55+
{
56+
"direction": "send",
57+
"regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);",
58+
"capture": {1: "stop_signo", 2: "stop_thread_id"},
59+
},
60+
],
61+
True,
62+
)
63+
64+
# Run the packet stream.
65+
context = self.expect_gdbremote_sequence()
66+
self.assertIsNotNone(context)
67+
68+
# Grab the code address.
69+
self.assertIsNotNone(context.get("code_address"))
70+
code_address = int(context.get("code_address"), 16)
71+
72+
# Grab memory region info from the inferior.
73+
self.reset_test_sequence()
74+
self.add_query_memory_region_packets(code_address)
75+
76+
# Run the packet stream.
77+
context = self.expect_gdbremote_sequence()
78+
self.assertIsNotNone(context)
79+
mem_region_dict = self.parse_memory_region_packet(context)
80+
81+
# Ensure there are no errors reported.
82+
self.assertNotIn("error", mem_region_dict)
83+
84+
# Ensure code address is readable and executable.
85+
self.assertIn("permissions", mem_region_dict)
86+
self.assertIn("r", mem_region_dict["permissions"])
87+
self.assertIn("x", mem_region_dict["permissions"])
88+
89+
# Ensure the start address and size encompass the address we queried.
90+
self.assert_address_within_memory_region(code_address, mem_region_dict)
91+
92+
@skipIfWindows # No pty support to test any inferior output
93+
def test_qMemoryRegionInfo_reports_stack_address_as_rw(self):
94+
self.build()
95+
self.set_inferior_startup_launch()
96+
97+
# Start up the inferior.
98+
procs = self.prep_debug_monitor_and_inferior(
99+
inferior_args=["get-stack-address-hex:", "sleep:5"]
100+
)
101+
102+
# Run the process
103+
self.test_sequence.add_log_lines(
104+
[
105+
# Start running after initial stop.
106+
"read packet: $c#63",
107+
# Match output line that prints the memory address of the message buffer within the inferior.
108+
# Note we require launch-only testing so we can get inferior otuput.
109+
{
110+
"type": "output_match",
111+
"regex": self.maybe_strict_output_regex(
112+
r"stack address: 0x([0-9a-fA-F]+)\r\n"
113+
),
114+
"capture": {1: "stack_address"},
115+
},
116+
# Now stop the inferior.
117+
"read packet: {}".format(chr(3)),
118+
# And wait for the stop notification.
119+
{
120+
"direction": "send",
121+
"regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);",
122+
"capture": {1: "stop_signo", 2: "stop_thread_id"},
123+
},
124+
],
125+
True,
126+
)
127+
128+
# Run the packet stream.
129+
context = self.expect_gdbremote_sequence()
130+
self.assertIsNotNone(context)
131+
132+
# Grab the address.
133+
self.assertIsNotNone(context.get("stack_address"))
134+
stack_address = int(context.get("stack_address"), 16)
135+
136+
# Grab memory region info from the inferior.
137+
self.reset_test_sequence()
138+
self.add_query_memory_region_packets(stack_address)
139+
140+
# Run the packet stream.
141+
context = self.expect_gdbremote_sequence()
142+
self.assertIsNotNone(context)
143+
mem_region_dict = self.parse_memory_region_packet(context)
144+
145+
# Ensure there are no errors reported.
146+
self.assertNotIn("error", mem_region_dict)
147+
148+
# Ensure address is readable and executable.
149+
self.assertIn("permissions", mem_region_dict)
150+
self.assertIn("r", mem_region_dict["permissions"])
151+
self.assertIn("w", mem_region_dict["permissions"])
152+
153+
# Ensure the start address and size encompass the address we queried.
154+
self.assert_address_within_memory_region(stack_address, mem_region_dict)
155+
156+
@skipIfWindows # No pty support to test any inferior output
157+
def test_qMemoryRegionInfo_reports_heap_address_as_rw(self):
158+
self.build()
159+
self.set_inferior_startup_launch()
160+
161+
# Start up the inferior.
162+
procs = self.prep_debug_monitor_and_inferior(
163+
inferior_args=["get-heap-address-hex:", "sleep:5"]
164+
)
165+
166+
# Run the process
167+
self.test_sequence.add_log_lines(
168+
[
169+
# Start running after initial stop.
170+
"read packet: $c#63",
171+
# Match output line that prints the memory address of the message buffer within the inferior.
172+
# Note we require launch-only testing so we can get inferior otuput.
173+
{
174+
"type": "output_match",
175+
"regex": self.maybe_strict_output_regex(
176+
r"heap address: 0x([0-9a-fA-F]+)\r\n"
177+
),
178+
"capture": {1: "heap_address"},
179+
},
180+
# Now stop the inferior.
181+
"read packet: {}".format(chr(3)),
182+
# And wait for the stop notification.
183+
{
184+
"direction": "send",
185+
"regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);",
186+
"capture": {1: "stop_signo", 2: "stop_thread_id"},
187+
},
188+
],
189+
True,
190+
)
191+
192+
# Run the packet stream.
193+
context = self.expect_gdbremote_sequence()
194+
self.assertIsNotNone(context)
195+
196+
# Grab the address.
197+
self.assertIsNotNone(context.get("heap_address"))
198+
heap_address = int(context.get("heap_address"), 16)
199+
200+
# Grab memory region info from the inferior.
201+
self.reset_test_sequence()
202+
self.add_query_memory_region_packets(heap_address)
203+
204+
# Run the packet stream.
205+
context = self.expect_gdbremote_sequence()
206+
self.assertIsNotNone(context)
207+
mem_region_dict = self.parse_memory_region_packet(context)
208+
209+
# Ensure there are no errors reported.
210+
self.assertNotIn("error", mem_region_dict)
211+
212+
# Ensure address is readable and executable.
213+
self.assertIn("permissions", mem_region_dict)
214+
self.assertIn("r", mem_region_dict["permissions"])
215+
self.assertIn("w", mem_region_dict["permissions"])
216+
217+
# Ensure the start address and size encompass the address we queried.
218+
self.assert_address_within_memory_region(heap_address, mem_region_dict)

0 commit comments

Comments
 (0)