1 from __future__ import print_function
4 import gdbremote_testcase
5 from lldbsuite.test.decorators import *
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test import lldbutil
10 class TestGdbRemoteExpeditedRegisters(
11 gdbremote_testcase.GdbRemoteTestCaseBase):
13 mydir = TestBase.compute_mydir(__file__)
15 def gather_expedited_registers(self):
16 # Setup the stub and set the gdb remote command stream.
17 procs = self.prep_debug_monitor_and_inferior(inferior_args=["sleep:2"])
18 self.test_sequence.add_log_lines([
19 # Start up the inferior.
21 # Immediately tell it to stop. We want to see what it reports.
22 "read packet: {}".format(chr(3)),
24 "regex": r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$",
25 "capture": {1: "stop_result",
29 # Run the gdb remote command stream.
30 context = self.expect_gdbremote_sequence()
31 self.assertIsNotNone(context)
33 # Pull out expedited registers.
34 key_vals_text = context.get("key_vals_text")
35 self.assertIsNotNone(key_vals_text)
37 expedited_registers = self.extract_registers_from_stop_notification(
39 self.assertIsNotNone(expedited_registers)
41 return expedited_registers
43 def stop_notification_contains_generic_register(
44 self, generic_register_name):
45 # Generate a stop reply, parse out expedited registers from stop
47 expedited_registers = self.gather_expedited_registers()
48 self.assertIsNotNone(expedited_registers)
49 self.assertTrue(len(expedited_registers) > 0)
51 # Gather target register infos.
52 reg_infos = self.gather_register_infos()
54 # Find the generic register.
55 reg_info = self.find_generic_register_with_name(
56 reg_infos, generic_register_name)
57 self.assertIsNotNone(reg_info)
59 # Ensure the expedited registers contained it.
60 self.assertTrue(reg_info["lldb_register_index"] in expedited_registers)
61 # print("{} reg_info:{}".format(generic_register_name, reg_info))
63 def stop_notification_contains_any_registers(self):
64 # Generate a stop reply, parse out expedited registers from stop
66 expedited_registers = self.gather_expedited_registers()
67 # Verify we have at least one expedited register.
68 self.assertTrue(len(expedited_registers) > 0)
71 def test_stop_notification_contains_any_registers_debugserver(self):
72 self.init_debugserver_test()
74 self.set_inferior_startup_launch()
75 self.stop_notification_contains_any_registers()
78 def test_stop_notification_contains_any_registers_llgs(self):
81 self.set_inferior_startup_launch()
82 self.stop_notification_contains_any_registers()
84 def stop_notification_contains_no_duplicate_registers(self):
85 # Generate a stop reply, parse out expedited registers from stop
87 expedited_registers = self.gather_expedited_registers()
88 # Verify no expedited register was specified multiple times.
89 for (reg_num, value) in list(expedited_registers.items()):
90 if (isinstance(value, list)) and (len(value) > 0):
92 "expedited register number {} specified more than once ({} times)".format(
96 def test_stop_notification_contains_no_duplicate_registers_debugserver(
98 self.init_debugserver_test()
100 self.set_inferior_startup_launch()
101 self.stop_notification_contains_no_duplicate_registers()
104 def test_stop_notification_contains_no_duplicate_registers_llgs(self):
105 self.init_llgs_test()
107 self.set_inferior_startup_launch()
108 self.stop_notification_contains_no_duplicate_registers()
110 def stop_notification_contains_pc_register(self):
111 self.stop_notification_contains_generic_register("pc")
114 def test_stop_notification_contains_pc_register_debugserver(self):
115 self.init_debugserver_test()
117 self.set_inferior_startup_launch()
118 self.stop_notification_contains_pc_register()
121 def test_stop_notification_contains_pc_register_llgs(self):
122 self.init_llgs_test()
124 self.set_inferior_startup_launch()
125 self.stop_notification_contains_pc_register()
127 def stop_notification_contains_fp_register(self):
128 self.stop_notification_contains_generic_register("fp")
131 def test_stop_notification_contains_fp_register_debugserver(self):
132 self.init_debugserver_test()
134 self.set_inferior_startup_launch()
135 self.stop_notification_contains_fp_register()
138 def test_stop_notification_contains_fp_register_llgs(self):
139 self.init_llgs_test()
141 self.set_inferior_startup_launch()
142 self.stop_notification_contains_fp_register()
144 def stop_notification_contains_sp_register(self):
145 self.stop_notification_contains_generic_register("sp")
148 def test_stop_notification_contains_sp_register_debugserver(self):
149 self.init_debugserver_test()
151 self.set_inferior_startup_launch()
152 self.stop_notification_contains_sp_register()
155 def test_stop_notification_contains_sp_register_llgs(self):
156 self.init_llgs_test()
158 self.set_inferior_startup_launch()
159 self.stop_notification_contains_sp_register()