1 import gdbremote_testcase
3 from lldbsuite
.test
.decorators
import *
4 from lldbsuite
.test
.lldbtest
import *
5 from lldbsuite
.test
import lldbutil
8 def _extract_register_value(reg_info
, reg_bank
, byte_order
, bytes_per_entry
=8):
9 reg_offset
= int(reg_info
["offset"]) * 2
10 reg_byte_size
= int(2 * int(reg_info
["bitsize"]) / 8)
11 # Create slice with the contents of the register.
12 reg_slice
= reg_bank
[reg_offset
: reg_offset
+ reg_byte_size
]
15 # Wrap slice according to bytes_per_entry.
16 for entry
in textwrap
.wrap(reg_slice
, 2 * bytes_per_entry
):
17 # Invert the bytes order if target uses little-endian.
18 if byte_order
== lldb
.eByteOrderLittle
:
20 reversed([entry
[i
: i
+ 2] for i
in range(0, len(entry
), 2)])
22 reg_value
.append("0x" + entry
)
27 class TestGdbRemoteGPacket(gdbremote_testcase
.GdbRemoteTestCaseBase
):
28 @skipIfOutOfTreeDebugserver
29 @skipUnlessDarwin # G packet not supported
30 def test_g_packet(self
):
32 self
.prep_debug_monitor_and_inferior()
33 self
.test_sequence
.add_log_lines(
38 "regex": r
"^\$(.+)#[0-9a-fA-F]{2}$",
39 "capture": {1: "register_bank"},
44 context
= self
.expect_gdbremote_sequence()
45 register_bank
= context
.get("register_bank")
46 self
.assertNotEqual(register_bank
[0], "E")
48 self
.test_sequence
.add_log_lines(
50 "read packet: $G" + register_bank
+ "#00",
53 "regex": r
"^\$(.+)#[0-9a-fA-F]{2}$",
54 "capture": {1: "G_reply"},
59 context
= self
.expect_gdbremote_sequence()
60 self
.assertNotEqual(context
.get("G_reply")[0], "E")
62 @skipIf(archs
=no_match(["x86_64"]))
63 def g_returns_correct_data(self
, with_suffix
):
64 procs
= self
.prep_debug_monitor_and_inferior()
66 self
.add_register_info_collection_packets()
68 self
.add_thread_suffix_request_packets()
69 self
.add_threadinfo_collection_packets()
70 context
= self
.expect_gdbremote_sequence()
71 self
.assertIsNotNone(context
)
73 # Gather register info.
74 reg_infos
= self
.parse_register_info_packets(context
)
75 self
.assertIsNotNone(reg_infos
)
76 self
.add_lldb_register_index(reg_infos
)
77 # Index register info entries by name.
78 reg_infos
= {info
["name"]: info
for info
in reg_infos
}
82 threads
= self
.parse_threadinfo_packets(context
)
83 self
.assertIsNotNone(threads
)
84 thread_id
= threads
[0]
85 self
.assertIsNotNone(thread_id
)
89 # Send vCont packet to resume the inferior.
90 self
.test_sequence
.add_log_lines(
92 "read packet: $vCont;c#a8",
95 "regex": r
"^\$T([0-9a-fA-F]{2}).*#[0-9a-fA-F]{2}$",
96 "capture": {1: "hex_exit_code"},
102 # Send g packet to retrieve the register bank
104 g_request
= "read packet: $g;thread:{:x}#00".format(thread_id
)
106 g_request
= "read packet: $g#00"
107 self
.test_sequence
.add_log_lines(
112 "regex": r
"^\$(.+)#[0-9a-fA-F]{2}$",
113 "capture": {1: "register_bank"},
118 context
= self
.expect_gdbremote_sequence()
119 self
.assertIsNotNone(context
)
120 reg_bank
= context
.get("register_bank")
121 self
.assertNotEqual(reg_bank
[0], "E")
123 byte_order
= self
.get_target_byte_order()
124 get_reg_value
= lambda reg_name
: _extract_register_value(
125 reg_infos
[reg_name
], reg_bank
, byte_order
128 self
.assertEqual(["0x0102030405060708"], get_reg_value("r8"))
129 self
.assertEqual(["0x1112131415161718"], get_reg_value("r9"))
130 self
.assertEqual(["0x2122232425262728"], get_reg_value("r10"))
131 self
.assertEqual(["0x3132333435363738"], get_reg_value("r11"))
132 self
.assertEqual(["0x4142434445464748"], get_reg_value("r12"))
133 self
.assertEqual(["0x5152535455565758"], get_reg_value("r13"))
134 self
.assertEqual(["0x6162636465666768"], get_reg_value("r14"))
135 self
.assertEqual(["0x7172737475767778"], get_reg_value("r15"))
138 ["0x020406080a0c0e01", "0x030507090b0d0f00"], get_reg_value("xmm8")
141 ["0x121416181a1c1e11", "0x131517191b1d1f10"], get_reg_value("xmm9")
144 ["0x222426282a2c2e21", "0x232527292b2d2f20"], get_reg_value("xmm10")
147 ["0x323436383a3c3e31", "0x333537393b3d3f30"], get_reg_value("xmm11")
150 ["0x424446484a4c4e41", "0x434547494b4d4f40"], get_reg_value("xmm12")
153 ["0x525456585a5c5e51", "0x535557595b5d5f50"], get_reg_value("xmm13")
156 ["0x626466686a6c6e61", "0x636567696b6d6f60"], get_reg_value("xmm14")
159 ["0x727476787a7c7e71", "0x737577797b7d7f70"], get_reg_value("xmm15")
162 @expectedFailureAll(oslist
=["freebsd"], bugnumber
="llvm.org/pr48420")
163 @expectedFailureNetBSD
164 @skipIfDarwin # g packet not supported
165 def test_g_returns_correct_data_with_suffix(self
):
167 self
.set_inferior_startup_launch()
168 self
.g_returns_correct_data(True)
170 @expectedFailureAll(oslist
=["freebsd"], bugnumber
="llvm.org/pr48420")
171 @expectedFailureNetBSD
172 @skipIfDarwin # g packet not supported
173 def test_g_returns_correct_data_no_suffix(self
):
175 self
.set_inferior_startup_launch()
176 self
.g_returns_correct_data(False)