a27cb01e938585dfbdb4aeef490a5043e903bd58
[openbsd] /
1
2
3 import gdbremote_testcase
4 import textwrap
5 from lldbsuite.test.decorators import *
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test import lldbutil
8
9
10 def _extract_register_value(reg_info, reg_bank, byte_order, bytes_per_entry=8):
11     reg_offset = int(reg_info["offset"])*2
12     reg_byte_size = int(2 * int(reg_info["bitsize"]) / 8)
13     # Create slice with the contents of the register.
14     reg_slice = reg_bank[reg_offset:reg_offset+reg_byte_size]
15
16     reg_value = []
17     # Wrap slice according to bytes_per_entry.
18     for entry in textwrap.wrap(reg_slice, 2 * bytes_per_entry):
19         # Invert the bytes order if target uses little-endian.
20         if byte_order == lldb.eByteOrderLittle:
21             entry = "".join(reversed([entry[i:i+2] for i in range(0,
22                                           len(entry),2)]))
23         reg_value.append("0x" + entry)
24
25     return reg_value
26
27
28 class TestGdbRemoteGPacket(gdbremote_testcase.GdbRemoteTestCaseBase):
29
30     mydir = TestBase.compute_mydir(__file__)
31
32     def run_test_g_packet(self):
33         self.build()
34         self.prep_debug_monitor_and_inferior()
35         self.test_sequence.add_log_lines(
36             ["read packet: $g#67",
37              {"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$",
38               "capture": {1: "register_bank"}}],
39             True)
40         self.connect_to_debug_monitor()
41         context = self.expect_gdbremote_sequence()
42         register_bank = context.get("register_bank")
43         self.assertTrue(register_bank[0] != 'E')
44
45         self.test_sequence.add_log_lines(
46             ["read packet: $G" + register_bank + "#00",
47              {"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$",
48               "capture": {1: "G_reply"}}],
49             True)
50         context = self.expect_gdbremote_sequence()
51         self.assertTrue(context.get("G_reply")[0] != 'E')
52
53     @skipIfOutOfTreeDebugserver
54     @debugserver_test
55     @skipIfDarwinEmbedded
56     def test_g_packet_debugserver(self):
57         self.init_debugserver_test()
58         self.run_test_g_packet()
59
60     @skipIf(archs=no_match(["x86_64"]))
61     def g_returns_correct_data(self, with_suffix):
62         procs = self.prep_debug_monitor_and_inferior()
63
64         self.add_register_info_collection_packets()
65         if with_suffix:
66             self.add_thread_suffix_request_packets()
67         self.add_threadinfo_collection_packets()
68         context = self.expect_gdbremote_sequence()
69         self.assertIsNotNone(context)
70
71         # Gather register info.
72         reg_infos = self.parse_register_info_packets(context)
73         self.assertIsNotNone(reg_infos)
74         self.add_lldb_register_index(reg_infos)
75         # Index register info entries by name.
76         reg_infos = {info['name']: info for info in reg_infos}
77
78         # Gather thread info.
79         if with_suffix:
80             threads = self.parse_threadinfo_packets(context)
81             self.assertIsNotNone(threads)
82             thread_id = threads[0]
83             self.assertIsNotNone(thread_id)
84         else:
85             thread_id = None
86
87         # Send vCont packet to resume the inferior.
88         self.test_sequence.add_log_lines(["read packet: $vCont;c#a8",
89                                           {"direction": "send",
90                                            "regex": r"^\$T([0-9a-fA-F]{2}).*#[0-9a-fA-F]{2}$",
91                                            "capture": {1: "hex_exit_code"}},
92                                           ],
93                                          True)
94
95         # Send g packet to retrieve the register bank
96         if thread_id:
97             g_request = "read packet: $g;thread:{:x}#00".format(thread_id)
98         else:
99             g_request = "read packet: $g#00"
100         self.test_sequence.add_log_lines(
101             [g_request,
102              {"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$",
103               "capture": {1: "register_bank"}}],
104             True)
105         context = self.expect_gdbremote_sequence()
106         self.assertIsNotNone(context)
107         reg_bank = context.get("register_bank")
108         self.assertTrue(reg_bank[0] != 'E')
109
110         byte_order = self.get_target_byte_order()
111         get_reg_value = lambda reg_name : _extract_register_value(
112             reg_infos[reg_name], reg_bank, byte_order)
113
114         self.assertEqual(['0x0102030405060708'], get_reg_value('r8'))
115         self.assertEqual(['0x1112131415161718'], get_reg_value('r9'))
116         self.assertEqual(['0x2122232425262728'], get_reg_value('r10'))
117         self.assertEqual(['0x3132333435363738'], get_reg_value('r11'))
118         self.assertEqual(['0x4142434445464748'], get_reg_value('r12'))
119         self.assertEqual(['0x5152535455565758'], get_reg_value('r13'))
120         self.assertEqual(['0x6162636465666768'], get_reg_value('r14'))
121         self.assertEqual(['0x7172737475767778'], get_reg_value('r15'))
122
123         self.assertEqual(
124             ['0x020406080a0c0e01', '0x030507090b0d0f00'], get_reg_value('xmm8'))
125         self.assertEqual(
126             ['0x121416181a1c1e11', '0x131517191b1d1f10'], get_reg_value('xmm9'))
127         self.assertEqual(
128             ['0x222426282a2c2e21', '0x232527292b2d2f20'], get_reg_value('xmm10'))
129         self.assertEqual(
130             ['0x323436383a3c3e31', '0x333537393b3d3f30'], get_reg_value('xmm11'))
131         self.assertEqual(
132             ['0x424446484a4c4e41', '0x434547494b4d4f40'], get_reg_value('xmm12'))
133         self.assertEqual(
134             ['0x525456585a5c5e51', '0x535557595b5d5f50'], get_reg_value('xmm13'))
135         self.assertEqual(
136             ['0x626466686a6c6e61', '0x636567696b6d6f60'], get_reg_value('xmm14'))
137         self.assertEqual(
138             ['0x727476787a7c7e71', '0x737577797b7d7f70'], get_reg_value('xmm15'))
139
140     @expectedFailureNetBSD
141     @llgs_test
142     def test_g_returns_correct_data_with_suffix_llgs(self):
143         self.init_llgs_test()
144         self.build()
145         self.set_inferior_startup_launch()
146         self.g_returns_correct_data(True)
147
148     @expectedFailureNetBSD
149     @llgs_test
150     def test_g_returns_correct_data_no_suffix_llgs(self):
151         self.init_llgs_test()
152         self.build()
153         self.set_inferior_startup_launch()
154         self.g_returns_correct_data(False)