xref: /llvm-project/lldb/test/API/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py (revision 9c2468821ec51defd09c246fea4a47886fff8c01)
199451b44SJordan Rupprechtimport gdbremote_testcase
299451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
399451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
499451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
599451b44SJordan Rupprecht
699451b44SJordan Rupprecht
72238dcc3SJonas Devlieghereclass TestGdbRemoteExpeditedRegisters(gdbremote_testcase.GdbRemoteTestCaseBase):
84e8aeb97SMuhammad Omair Javaid    # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
999451b44SJordan Rupprecht    def gather_expedited_registers(self):
1099451b44SJordan Rupprecht        # Setup the stub and set the gdb remote command stream.
1199451b44SJordan Rupprecht        procs = self.prep_debug_monitor_and_inferior(inferior_args=["sleep:2"])
122238dcc3SJonas Devlieghere        self.test_sequence.add_log_lines(
132238dcc3SJonas Devlieghere            [
1499451b44SJordan Rupprecht                # Start up the inferior.
1599451b44SJordan Rupprecht                "read packet: $c#63",
1699451b44SJordan Rupprecht                # Immediately tell it to stop.  We want to see what it reports.
1799451b44SJordan Rupprecht                "read packet: {}".format(chr(3)),
182238dcc3SJonas Devlieghere                {
192238dcc3SJonas Devlieghere                    "direction": "send",
2099451b44SJordan Rupprecht                    "regex": r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$",
212238dcc3SJonas Devlieghere                    "capture": {1: "stop_result", 2: "key_vals_text"},
222238dcc3SJonas Devlieghere                },
232238dcc3SJonas Devlieghere            ],
242238dcc3SJonas Devlieghere            True,
252238dcc3SJonas Devlieghere        )
2699451b44SJordan Rupprecht
2799451b44SJordan Rupprecht        # Run the gdb remote command stream.
2899451b44SJordan Rupprecht        context = self.expect_gdbremote_sequence()
2999451b44SJordan Rupprecht        self.assertIsNotNone(context)
3099451b44SJordan Rupprecht
3199451b44SJordan Rupprecht        # Pull out expedited registers.
3299451b44SJordan Rupprecht        key_vals_text = context.get("key_vals_text")
3399451b44SJordan Rupprecht        self.assertIsNotNone(key_vals_text)
3499451b44SJordan Rupprecht
3599451b44SJordan Rupprecht        expedited_registers = self.extract_registers_from_stop_notification(
362238dcc3SJonas Devlieghere            key_vals_text
372238dcc3SJonas Devlieghere        )
3899451b44SJordan Rupprecht        self.assertIsNotNone(expedited_registers)
3999451b44SJordan Rupprecht
4099451b44SJordan Rupprecht        return expedited_registers
4199451b44SJordan Rupprecht
422238dcc3SJonas Devlieghere    def stop_notification_contains_generic_register(self, generic_register_name):
4399451b44SJordan Rupprecht        # Generate a stop reply, parse out expedited registers from stop
4499451b44SJordan Rupprecht        # notification.
4599451b44SJordan Rupprecht        expedited_registers = self.gather_expedited_registers()
4699451b44SJordan Rupprecht        self.assertIsNotNone(expedited_registers)
47*9c246882SJordan Rupprecht        self.assertGreater(len(expedited_registers), 0)
4899451b44SJordan Rupprecht
4999451b44SJordan Rupprecht        # Gather target register infos.
5099451b44SJordan Rupprecht        reg_infos = self.gather_register_infos()
5199451b44SJordan Rupprecht
5299451b44SJordan Rupprecht        # Find the generic register.
5399451b44SJordan Rupprecht        reg_info = self.find_generic_register_with_name(
542238dcc3SJonas Devlieghere            reg_infos, generic_register_name
552238dcc3SJonas Devlieghere        )
5699451b44SJordan Rupprecht        self.assertIsNotNone(reg_info)
5799451b44SJordan Rupprecht
5899451b44SJordan Rupprecht        # Ensure the expedited registers contained it.
593cc37622SDave Lee        self.assertIn(reg_info["lldb_register_index"], expedited_registers)
60b321b429SJonas Devlieghere        self.trace("{} reg_info:{}".format(generic_register_name, reg_info))
6199451b44SJordan Rupprecht
6276a718eeSPavel Labath    def test_stop_notification_contains_any_registers(self):
6376a718eeSPavel Labath        self.build()
6476a718eeSPavel Labath        self.set_inferior_startup_launch()
6576a718eeSPavel Labath
6676a718eeSPavel Labath        # Generate a stop reply, parse out expedited registers from stop
6776a718eeSPavel Labath        # notification.
6876a718eeSPavel Labath        expedited_registers = self.gather_expedited_registers()
6976a718eeSPavel Labath        # Verify we have at least one expedited register.
70*9c246882SJordan Rupprecht        self.assertGreater(len(expedited_registers), 0)
7176a718eeSPavel Labath
7276a718eeSPavel Labath    def test_stop_notification_contains_no_duplicate_registers(self):
7376a718eeSPavel Labath        self.build()
7476a718eeSPavel Labath        self.set_inferior_startup_launch()
7576a718eeSPavel Labath
7676a718eeSPavel Labath        # Generate a stop reply, parse out expedited registers from stop
7776a718eeSPavel Labath        # notification.
7876a718eeSPavel Labath        expedited_registers = self.gather_expedited_registers()
7976a718eeSPavel Labath        # Verify no expedited register was specified multiple times.
802238dcc3SJonas Devlieghere        for reg_num, value in list(expedited_registers.items()):
8176a718eeSPavel Labath            if (isinstance(value, list)) and (len(value) > 0):
8276a718eeSPavel Labath                self.fail(
8376a718eeSPavel Labath                    "expedited register number {} specified more than once ({} times)".format(
842238dcc3SJonas Devlieghere                        reg_num, len(value)
852238dcc3SJonas Devlieghere                    )
862238dcc3SJonas Devlieghere                )
8776a718eeSPavel Labath
8876a718eeSPavel Labath    def test_stop_notification_contains_pc_register(self):
8976a718eeSPavel Labath        self.build()
9076a718eeSPavel Labath        self.set_inferior_startup_launch()
9176a718eeSPavel Labath        self.stop_notification_contains_generic_register("pc")
9276a718eeSPavel Labath
932238dcc3SJonas Devlieghere    @skipIf(triple="^powerpc64")  # powerpc64 has no FP register
9476a718eeSPavel Labath    def test_stop_notification_contains_fp_register(self):
9576a718eeSPavel Labath        self.build()
9676a718eeSPavel Labath        self.set_inferior_startup_launch()
9776a718eeSPavel Labath        self.stop_notification_contains_generic_register("fp")
9876a718eeSPavel Labath
9976a718eeSPavel Labath    def test_stop_notification_contains_sp_register(self):
10076a718eeSPavel Labath        self.build()
10176a718eeSPavel Labath        self.set_inferior_startup_launch()
10276a718eeSPavel Labath        self.stop_notification_contains_generic_register("sp")
10376a718eeSPavel Labath
10476a718eeSPavel Labath    @skipIf(archs=no_match(["aarch64"]))
1052238dcc3SJonas Devlieghere    @skipIf(oslist=no_match(["linux"]))
10676a718eeSPavel Labath    def test_stop_notification_contains_vg_register(self):
10776a718eeSPavel Labath        if not self.isAArch64SVE():
1082238dcc3SJonas Devlieghere            self.skipTest("SVE registers must be supported.")
10976a718eeSPavel Labath        self.build()
11076a718eeSPavel Labath        self.set_inferior_startup_launch()
11176a718eeSPavel Labath
1124e8aeb97SMuhammad Omair Javaid        # Generate a stop reply, parse out expedited registers from stop
1134e8aeb97SMuhammad Omair Javaid        # notification.
1144e8aeb97SMuhammad Omair Javaid        expedited_registers = self.gather_expedited_registers()
1154e8aeb97SMuhammad Omair Javaid        self.assertIsNotNone(expedited_registers)
116*9c246882SJordan Rupprecht        self.assertGreater(len(expedited_registers), 0)
1174e8aeb97SMuhammad Omair Javaid
1184e8aeb97SMuhammad Omair Javaid        # Gather target register infos.
1194e8aeb97SMuhammad Omair Javaid        reg_infos = self.gather_register_infos()
1204e8aeb97SMuhammad Omair Javaid
1214e8aeb97SMuhammad Omair Javaid        # Find the vg register.
1222238dcc3SJonas Devlieghere        reg_info = self.find_register_with_name_and_dwarf_regnum(reg_infos, "vg", "46")
1234e8aeb97SMuhammad Omair Javaid        self.assertIsNotNone(reg_info)
1244e8aeb97SMuhammad Omair Javaid
1254e8aeb97SMuhammad Omair Javaid        # Ensure the expedited registers contained it.
1263cc37622SDave Lee        self.assertIn(reg_info["lldb_register_index"], expedited_registers)
1272238dcc3SJonas Devlieghere        self.trace("{} reg_info:{}".format("vg", reg_info))
128