2 Check that lldb falls back to default register layouts when the remote provides
3 no target XML or does not include registers in the target XML.
5 GPRS are passed to the responder to create register data to send back to lldb.
6 Registers in SUPPL are virtual registers based on those general ones. The tests
7 pass __file__ to FileCheck so any prefixes in this Python file will be checked.
11 from lldbsuite
.test
.lldbtest
import *
12 from lldbsuite
.test
.decorators
import *
13 from lldbsuite
.test
.gdbclientutils
import *
14 from lldbsuite
.test
.lldbgdbclient
import GDBRemoteTestBase
17 from textwrap
import dedent
20 class MyResponder(MockGDBServerResponder
):
22 def filecheck_to_blob(fc
):
23 for l
in fc
.strip().splitlines():
24 val
= l
.split("0x")[1]
25 yield binascii
.b2a_hex(bytes(reversed(binascii
.a2b_hex(val
)))).decode()
27 def __init__(self
, architecture
, has_target_xml
, reg_data
, halt_reason
):
29 self
.architecture
= architecture
30 self
.has_target_xml
= has_target_xml
31 self
.reg_data
= "".join(self
.filecheck_to_blob(reg_data
))
32 self
.halt_reason
= halt_reason
34 def readRegister(self
, regnum
):
37 def readRegisters(self
):
41 return self
.halt_reason
43 def qXferRead(self
, obj
, annex
, offset
, length
):
44 if self
.has_target_xml
and annex
== "target.xml":
49 <target version="1.0">
50 <architecture>{self.architecture}</architecture>
59 class TestGDBServerTargetXML(GDBRemoteTestBase
):
60 def check_x86_64_regs(self
, has_target_xml
):
62 CHECK-AMD64-DAG: rax = 0x0807060504030201
63 CHECK-AMD64-DAG: rbx = 0x1817161514131211
64 CHECK-AMD64-DAG: rcx = 0x2827262524232221
65 CHECK-AMD64-DAG: rdx = 0x3837363534333231
66 CHECK-AMD64-DAG: rsi = 0x4847464544434241
67 CHECK-AMD64-DAG: rdi = 0x5857565554535251
68 CHECK-AMD64-DAG: rbp = 0x6867666564636261
69 CHECK-AMD64-DAG: rsp = 0x7877767574737271
70 CHECK-AMD64-DAG: r8 = 0x8887868584838281
71 CHECK-AMD64-DAG: r9 = 0x9897969594939291
72 CHECK-AMD64-DAG: r10 = 0xa8a7a6a5a4a3a2a1
73 CHECK-AMD64-DAG: r11 = 0xb8b7b6b5b4b3b2b1
74 CHECK-AMD64-DAG: r12 = 0xc8c7c6c5c4c3c2c1
75 CHECK-AMD64-DAG: r13 = 0xd8d7d6d5d4d3d2d1
76 CHECK-AMD64-DAG: r14 = 0xe8e7e6e5e4e3e2e1
77 CHECK-AMD64-DAG: r15 = 0xf8f7f6f5f4f3f2f1
78 CHECK-AMD64-DAG: rip = 0x100f0e0d0c0b0a09
79 CHECK-AMD64-DAG: eflags = 0x1c1b1a19
80 CHECK-AMD64-DAG: cs = 0x2c2b2a29
81 CHECK-AMD64-DAG: ss = 0x3c3b3a39
85 CHECK-AMD64-DAG: eax = 0x04030201
86 CHECK-AMD64-DAG: ebx = 0x14131211
87 CHECK-AMD64-DAG: ecx = 0x24232221
88 CHECK-AMD64-DAG: edx = 0x34333231
89 CHECK-AMD64-DAG: esi = 0x44434241
90 CHECK-AMD64-DAG: edi = 0x54535251
91 CHECK-AMD64-DAG: ebp = 0x64636261
92 CHECK-AMD64-DAG: esp = 0x74737271
93 CHECK-AMD64-DAG: r8d = 0x84838281
94 CHECK-AMD64-DAG: r9d = 0x94939291
95 CHECK-AMD64-DAG: r10d = 0xa4a3a2a1
96 CHECK-AMD64-DAG: r11d = 0xb4b3b2b1
97 CHECK-AMD64-DAG: r12d = 0xc4c3c2c1
98 CHECK-AMD64-DAG: r13d = 0xd4d3d2d1
99 CHECK-AMD64-DAG: r14d = 0xe4e3e2e1
100 CHECK-AMD64-DAG: r15d = 0xf4f3f2f1
102 CHECK-AMD64-DAG: ax = 0x0201
103 CHECK-AMD64-DAG: bx = 0x1211
104 CHECK-AMD64-DAG: cx = 0x2221
105 CHECK-AMD64-DAG: dx = 0x3231
106 CHECK-AMD64-DAG: si = 0x4241
107 CHECK-AMD64-DAG: di = 0x5251
108 CHECK-AMD64-DAG: bp = 0x6261
109 CHECK-AMD64-DAG: sp = 0x7271
110 CHECK-AMD64-DAG: r8w = 0x8281
111 CHECK-AMD64-DAG: r9w = 0x9291
112 CHECK-AMD64-DAG: r10w = 0xa2a1
113 CHECK-AMD64-DAG: r11w = 0xb2b1
114 CHECK-AMD64-DAG: r12w = 0xc2c1
115 CHECK-AMD64-DAG: r13w = 0xd2d1
116 CHECK-AMD64-DAG: r14w = 0xe2e1
117 CHECK-AMD64-DAG: r15w = 0xf2f1
119 CHECK-AMD64-DAG: ah = 0x02
120 CHECK-AMD64-DAG: bh = 0x12
121 CHECK-AMD64-DAG: ch = 0x22
122 CHECK-AMD64-DAG: dh = 0x32
124 CHECK-AMD64-DAG: al = 0x01
125 CHECK-AMD64-DAG: bl = 0x11
126 CHECK-AMD64-DAG: cl = 0x21
127 CHECK-AMD64-DAG: dl = 0x31
128 CHECK-AMD64-DAG: sil = 0x41
129 CHECK-AMD64-DAG: dil = 0x51
130 CHECK-AMD64-DAG: bpl = 0x61
131 CHECK-AMD64-DAG: spl = 0x71
132 CHECK-AMD64-DAG: r8l = 0x81
133 CHECK-AMD64-DAG: r9l = 0x91
134 CHECK-AMD64-DAG: r10l = 0xa1
135 CHECK-AMD64-DAG: r11l = 0xb1
136 CHECK-AMD64-DAG: r12l = 0xc1
137 CHECK-AMD64-DAG: r13l = 0xd1
138 CHECK-AMD64-DAG: r14l = 0xe1
139 CHECK-AMD64-DAG: r15l = 0xf1
142 self
.server
.responder
= MyResponder(
146 "T02thread:1ff0d;threads:1ff0d;thread-pcs:000000010001bc00;07:0102030405060708;10:1112131415161718;",
149 target
= self
.createTarget("basic_eh_frame.yaml")
150 process
= self
.connect(target
)
151 lldbutil
.expect_state_changes(
152 self
, self
.dbg
.GetListener(), process
, [lldb
.eStateStopped
]
157 "register read --all",
159 filecheck_options
="--check-prefix=CHECK-AMD64",
162 # test generic aliases
163 self
.match("register read arg4", ["rcx = 0x2827262524232221"])
164 self
.match("register read arg3", ["rdx = 0x3837363534333231"])
165 self
.match("register read arg2", ["rsi = 0x4847464544434241"])
166 self
.match("register read arg1", ["rdi = 0x5857565554535251"])
167 self
.match("register read fp", ["rbp = 0x6867666564636261"])
168 self
.match("register read sp", ["rsp = 0x7877767574737271"])
169 self
.match("register read arg5", ["r8 = 0x8887868584838281"])
170 self
.match("register read arg6", ["r9 = 0x9897969594939291"])
171 self
.match("register read pc", ["rip = 0x100f0e0d0c0b0a09"])
172 self
.match("register read flags", ["eflags = 0x1c1b1a19"])
175 @skipIfLLVMTargetMissing("X86")
176 def test_x86_64_regs_no_target_xml(self
):
177 """Test grabbing various x86_64 registers from gdbserver when there
179 self
.check_x86_64_regs(False)
181 @skipIfXmlSupportMissing
183 @skipIfLLVMTargetMissing("X86")
184 def test_x86_64_regs_no_register_info(self
):
185 """Test grabbing various x86_64 registers from gdbserver when there
186 is target XML but it does not include register info."""
187 self
.check_x86_64_regs(True)
189 def check_aarch64_regs(self
, has_target_xml
):
191 CHECK-AARCH64-DAG: x0 = 0x0001020304050607
192 CHECK-AARCH64-DAG: x1 = 0x0102030405060708
193 CHECK-AARCH64-DAG: x2 = 0x0203040506070809
194 CHECK-AARCH64-DAG: x3 = 0x030405060708090a
195 CHECK-AARCH64-DAG: x4 = 0x0405060708090a0b
196 CHECK-AARCH64-DAG: x5 = 0x05060708090a0b0c
197 CHECK-AARCH64-DAG: x6 = 0x060708090a0b0c0d
198 CHECK-AARCH64-DAG: x7 = 0x0708090a0b0c0d0e
199 CHECK-AARCH64-DAG: x8 = 0x08090a0b0c0d0e0f
200 CHECK-AARCH64-DAG: x9 = 0x090a0b0c0d0e0f10
201 CHECK-AARCH64-DAG: x10 = 0x0a0b0c0d0e0f1011
202 CHECK-AARCH64-DAG: x11 = 0x0b0c0d0e0f101112
203 CHECK-AARCH64-DAG: x12 = 0x0c0d0e0f10111213
204 CHECK-AARCH64-DAG: x13 = 0x0d0e0f1011121314
205 CHECK-AARCH64-DAG: x14 = 0x0e0f101112131415
206 CHECK-AARCH64-DAG: x15 = 0x0f10111213141516
207 CHECK-AARCH64-DAG: x16 = 0x1011121314151617
208 CHECK-AARCH64-DAG: x17 = 0x1112131415161718
209 CHECK-AARCH64-DAG: x18 = 0x1213141516171819
210 CHECK-AARCH64-DAG: x19 = 0x131415161718191a
211 CHECK-AARCH64-DAG: x20 = 0x1415161718191a1b
212 CHECK-AARCH64-DAG: x21 = 0x15161718191a1b1c
213 CHECK-AARCH64-DAG: x22 = 0x161718191a1b1c1d
214 CHECK-AARCH64-DAG: x23 = 0x1718191a1b1c1d1e
215 CHECK-AARCH64-DAG: x24 = 0x18191a1b1c1d1e1f
216 CHECK-AARCH64-DAG: x25 = 0x191a1b1c1d1e1f20
217 CHECK-AARCH64-DAG: x26 = 0x1a1b1c1d1e1f2021
218 CHECK-AARCH64-DAG: x27 = 0x1b1c1d1e1f202122
219 CHECK-AARCH64-DAG: x28 = 0x1c1d1e1f20212223
220 CHECK-AARCH64-DAG: x29 = 0x1d1e1f2021222324
221 CHECK-AARCH64-DAG: x30 = 0x1e1f202122232425
222 CHECK-AARCH64-DAG: sp = 0x1f20212223242526
223 CHECK-AARCH64-DAG: pc = 0x2021222324252627
224 CHECK-AARCH64-DAG: cpsr = 0x21222324
228 CHECK-AARCH64-DAG: w0 = 0x04050607
229 CHECK-AARCH64-DAG: w1 = 0x05060708
230 CHECK-AARCH64-DAG: w2 = 0x06070809
231 CHECK-AARCH64-DAG: w3 = 0x0708090a
232 CHECK-AARCH64-DAG: w4 = 0x08090a0b
233 CHECK-AARCH64-DAG: w5 = 0x090a0b0c
234 CHECK-AARCH64-DAG: w6 = 0x0a0b0c0d
235 CHECK-AARCH64-DAG: w7 = 0x0b0c0d0e
236 CHECK-AARCH64-DAG: w8 = 0x0c0d0e0f
237 CHECK-AARCH64-DAG: w9 = 0x0d0e0f10
238 CHECK-AARCH64-DAG: w10 = 0x0e0f1011
239 CHECK-AARCH64-DAG: w11 = 0x0f101112
240 CHECK-AARCH64-DAG: w12 = 0x10111213
241 CHECK-AARCH64-DAG: w13 = 0x11121314
242 CHECK-AARCH64-DAG: w14 = 0x12131415
243 CHECK-AARCH64-DAG: w15 = 0x13141516
244 CHECK-AARCH64-DAG: w16 = 0x14151617
245 CHECK-AARCH64-DAG: w17 = 0x15161718
246 CHECK-AARCH64-DAG: w18 = 0x16171819
247 CHECK-AARCH64-DAG: w19 = 0x1718191a
248 CHECK-AARCH64-DAG: w20 = 0x18191a1b
249 CHECK-AARCH64-DAG: w21 = 0x191a1b1c
250 CHECK-AARCH64-DAG: w22 = 0x1a1b1c1d
251 CHECK-AARCH64-DAG: w23 = 0x1b1c1d1e
252 CHECK-AARCH64-DAG: w24 = 0x1c1d1e1f
253 CHECK-AARCH64-DAG: w25 = 0x1d1e1f20
254 CHECK-AARCH64-DAG: w26 = 0x1e1f2021
255 CHECK-AARCH64-DAG: w27 = 0x1f202122
256 CHECK-AARCH64-DAG: w28 = 0x20212223
257 CHECK-AARCH64-DAG: w29 = 0x21222324
258 CHECK-AARCH64-DAG: w30 = 0x22232425
259 CHECK-AARCH64-DAG: w31 = 0x23242526
262 self
.server
.responder
= MyResponder(
266 "T02thread:1ff0d;threads:1ff0d;thread-pcs:000000010001bc00;07:0102030405060708;10:1112131415161718;",
269 target
= self
.createTarget("basic_eh_frame-aarch64.yaml")
270 process
= self
.connect(target
)
271 lldbutil
.expect_state_changes(
272 self
, self
.dbg
.GetListener(), process
, [lldb
.eStateStopped
]
277 "register read --all",
279 filecheck_options
="--check-prefix=CHECK-AARCH64",
282 # test generic aliases
283 self
.match("register read arg1", ["x0 = 0x0001020304050607"])
284 self
.match("register read arg2", ["x1 = 0x0102030405060708"])
285 self
.match("register read fp", ["x29 = 0x1d1e1f2021222324"])
286 self
.match("register read lr", ["x30 = 0x1e1f202122232425"])
287 self
.match("register read ra", ["x30 = 0x1e1f202122232425"])
288 self
.match("register read flags", ["cpsr = 0x21222324"])
291 @skipIfLLVMTargetMissing("AArch64")
292 def test_aarch64_regs_no_target_xml(self
):
293 """Test grabbing various aarch64 registers from gdbserver when there
295 self
.check_aarch64_regs(False)
297 @skipIfXmlSupportMissing
299 @skipIfLLVMTargetMissing("AArch64")
300 def test_aarch64_regs_no_register_info(self
):
301 """Test grabbing various aarch64 registers from gdbserver when there
302 is target XML but it does not include register info."""
303 self
.check_aarch64_regs(True)
305 def check_i386_regs(self
, has_target_xml
):
307 CHECK-I386-DAG: eax = 0x04030201
308 CHECK-I386-DAG: ecx = 0x14131211
309 CHECK-I386-DAG: edx = 0x24232221
310 CHECK-I386-DAG: ebx = 0x34333231
311 CHECK-I386-DAG: esp = 0x44434241
312 CHECK-I386-DAG: ebp = 0x54535251
313 CHECK-I386-DAG: esi = 0x64636261
314 CHECK-I386-DAG: edi = 0x74737271
315 CHECK-I386-DAG: eip = 0x84838281
316 CHECK-I386-DAG: eflags = 0x94939291
317 CHECK-I386-DAG: cs = 0xa4a3a2a1
318 CHECK-I386-DAG: ss = 0xb4b3b2b1
319 CHECK-I386-DAG: ds = 0xc4c3c2c1
320 CHECK-I386-DAG: es = 0xd4d3d2d1
321 CHECK-I386-DAG: fs = 0xe4e3e2e1
322 CHECK-I386-DAG: gs = 0xf4f3f2f1
326 CHECK-I386-DAG: ax = 0x0201
327 CHECK-I386-DAG: cx = 0x1211
328 CHECK-I386-DAG: dx = 0x2221
329 CHECK-I386-DAG: bx = 0x3231
330 CHECK-I386-DAG: sp = 0x4241
331 CHECK-I386-DAG: bp = 0x5251
332 CHECK-I386-DAG: si = 0x6261
333 CHECK-I386-DAG: di = 0x7271
335 CHECK-I386-DAG: ah = 0x02
336 CHECK-I386-DAG: ch = 0x12
337 CHECK-I386-DAG: dh = 0x22
338 CHECK-I386-DAG: bh = 0x32
340 CHECK-I386-DAG: al = 0x01
341 CHECK-I386-DAG: cl = 0x11
342 CHECK-I386-DAG: dl = 0x21
343 CHECK-I386-DAG: bl = 0x31
344 CHECK-I386-DAG: spl = 0x41
345 CHECK-I386-DAG: bpl = 0x51
346 CHECK-I386-DAG: sil = 0x61
347 CHECK-I386-DAG: dil = 0x71
350 self
.server
.responder
= MyResponder(
354 "T02thread:1ff0d;threads:1ff0d;thread-pcs:000000010001bc00;07:0102030405060708;10:1112131415161718;",
357 target
= self
.createTarget("basic_eh_frame-i386.yaml")
358 process
= self
.connect(target
)
359 lldbutil
.expect_state_changes(
360 self
, self
.dbg
.GetListener(), process
, [lldb
.eStateStopped
]
365 "register read --all",
367 filecheck_options
="--check-prefix=CHECK-I386",
370 # test generic aliases
371 self
.match("register read fp", ["ebp = 0x54535251"])
372 self
.match("register read sp", ["esp = 0x44434241"])
373 self
.match("register read pc", ["eip = 0x84838281"])
374 self
.match("register read flags", ["eflags = 0x94939291"])
377 @skipIfLLVMTargetMissing("X86")
378 def test_i386_regs_no_target_xml(self
):
379 """Test grabbing various i386 registers from gdbserver when there is
381 self
.check_i386_regs(False)
383 @skipIfXmlSupportMissing
385 @skipIfLLVMTargetMissing("X86")
386 def test_i386_regs_no_register_info(self
):
387 """Test grabbing various i386 registers from gdbserver when there is
388 target XML but it does not include register info."""
389 self
.check_i386_regs(True)