1from __future__ import print_function 2 3 4import gdbremote_testcase 5from lldbsuite.test.decorators import * 6from lldbsuite.test.lldbtest import * 7from lldbsuite.test import lldbutil 8 9 10class TestGdbRemoteExpeditedRegisters( 11 gdbremote_testcase.GdbRemoteTestCaseBase): 12 13 mydir = TestBase.compute_mydir(__file__) 14 @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet 15 16 def gather_expedited_registers(self): 17 # Setup the stub and set the gdb remote command stream. 18 procs = self.prep_debug_monitor_and_inferior(inferior_args=["sleep:2"]) 19 self.test_sequence.add_log_lines([ 20 # Start up the inferior. 21 "read packet: $c#63", 22 # Immediately tell it to stop. We want to see what it reports. 23 "read packet: {}".format(chr(3)), 24 {"direction": "send", 25 "regex": r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", 26 "capture": {1: "stop_result", 27 2: "key_vals_text"}}, 28 ], True) 29 30 # Run the gdb remote command stream. 31 context = self.expect_gdbremote_sequence() 32 self.assertIsNotNone(context) 33 34 # Pull out expedited registers. 35 key_vals_text = context.get("key_vals_text") 36 self.assertIsNotNone(key_vals_text) 37 38 expedited_registers = self.extract_registers_from_stop_notification( 39 key_vals_text) 40 self.assertIsNotNone(expedited_registers) 41 42 return expedited_registers 43 44 def stop_notification_contains_generic_register( 45 self, generic_register_name): 46 # Generate a stop reply, parse out expedited registers from stop 47 # notification. 48 expedited_registers = self.gather_expedited_registers() 49 self.assertIsNotNone(expedited_registers) 50 self.assertTrue(len(expedited_registers) > 0) 51 52 # Gather target register infos. 53 reg_infos = self.gather_register_infos() 54 55 # Find the generic register. 56 reg_info = self.find_generic_register_with_name( 57 reg_infos, generic_register_name) 58 self.assertIsNotNone(reg_info) 59 60 # Ensure the expedited registers contained it. 61 self.assertTrue(reg_info["lldb_register_index"] in expedited_registers) 62 # print("{} reg_info:{}".format(generic_register_name, reg_info)) 63 64 def stop_notification_contains_any_registers(self): 65 # Generate a stop reply, parse out expedited registers from stop 66 # notification. 67 expedited_registers = self.gather_expedited_registers() 68 # Verify we have at least one expedited register. 69 self.assertTrue(len(expedited_registers) > 0) 70 71 @debugserver_test 72 def test_stop_notification_contains_any_registers_debugserver(self): 73 self.init_debugserver_test() 74 self.build() 75 self.set_inferior_startup_launch() 76 self.stop_notification_contains_any_registers() 77 78 @llgs_test 79 def test_stop_notification_contains_any_registers_llgs(self): 80 self.init_llgs_test() 81 self.build() 82 self.set_inferior_startup_launch() 83 self.stop_notification_contains_any_registers() 84 85 def stop_notification_contains_no_duplicate_registers(self): 86 # Generate a stop reply, parse out expedited registers from stop 87 # notification. 88 expedited_registers = self.gather_expedited_registers() 89 # Verify no expedited register was specified multiple times. 90 for (reg_num, value) in list(expedited_registers.items()): 91 if (isinstance(value, list)) and (len(value) > 0): 92 self.fail( 93 "expedited register number {} specified more than once ({} times)".format( 94 reg_num, len(value))) 95 96 @debugserver_test 97 def test_stop_notification_contains_no_duplicate_registers_debugserver( 98 self): 99 self.init_debugserver_test() 100 self.build() 101 self.set_inferior_startup_launch() 102 self.stop_notification_contains_no_duplicate_registers() 103 104 @llgs_test 105 def test_stop_notification_contains_no_duplicate_registers_llgs(self): 106 self.init_llgs_test() 107 self.build() 108 self.set_inferior_startup_launch() 109 self.stop_notification_contains_no_duplicate_registers() 110 111 def stop_notification_contains_pc_register(self): 112 self.stop_notification_contains_generic_register("pc") 113 114 @debugserver_test 115 def test_stop_notification_contains_pc_register_debugserver(self): 116 self.init_debugserver_test() 117 self.build() 118 self.set_inferior_startup_launch() 119 self.stop_notification_contains_pc_register() 120 121 @llgs_test 122 def test_stop_notification_contains_pc_register_llgs(self): 123 self.init_llgs_test() 124 self.build() 125 self.set_inferior_startup_launch() 126 self.stop_notification_contains_pc_register() 127 128 # powerpc64 has no FP register 129 @skipIf(triple='^powerpc64') 130 def stop_notification_contains_fp_register(self): 131 self.stop_notification_contains_generic_register("fp") 132 133 @debugserver_test 134 def test_stop_notification_contains_fp_register_debugserver(self): 135 self.init_debugserver_test() 136 self.build() 137 self.set_inferior_startup_launch() 138 self.stop_notification_contains_fp_register() 139 140 @llgs_test 141 def test_stop_notification_contains_fp_register_llgs(self): 142 self.init_llgs_test() 143 self.build() 144 self.set_inferior_startup_launch() 145 self.stop_notification_contains_fp_register() 146 147 def stop_notification_contains_sp_register(self): 148 self.stop_notification_contains_generic_register("sp") 149 150 @debugserver_test 151 def test_stop_notification_contains_sp_register_debugserver(self): 152 self.init_debugserver_test() 153 self.build() 154 self.set_inferior_startup_launch() 155 self.stop_notification_contains_sp_register() 156 157 @llgs_test 158 def test_stop_notification_contains_sp_register_llgs(self): 159 self.init_llgs_test() 160 self.build() 161 self.set_inferior_startup_launch() 162 self.stop_notification_contains_sp_register() 163