File: TestGdbRemoteExpeditedRegisters.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (127 lines) | stat: -rw-r--r-- 5,072 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import gdbremote_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TestGdbRemoteExpeditedRegisters(gdbremote_testcase.GdbRemoteTestCaseBase):
    # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
    def gather_expedited_registers(self):
        # Setup the stub and set the gdb remote command stream.
        procs = self.prep_debug_monitor_and_inferior(inferior_args=["sleep:2"])
        self.test_sequence.add_log_lines(
            [
                # Start up the inferior.
                "read packet: $c#63",
                # Immediately tell it to stop.  We want to see what it reports.
                "read packet: {}".format(chr(3)),
                {
                    "direction": "send",
                    "regex": r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$",
                    "capture": {1: "stop_result", 2: "key_vals_text"},
                },
            ],
            True,
        )

        # Run the gdb remote command stream.
        context = self.expect_gdbremote_sequence()
        self.assertIsNotNone(context)

        # Pull out expedited registers.
        key_vals_text = context.get("key_vals_text")
        self.assertIsNotNone(key_vals_text)

        expedited_registers = self.extract_registers_from_stop_notification(
            key_vals_text
        )
        self.assertIsNotNone(expedited_registers)

        return expedited_registers

    def stop_notification_contains_generic_register(self, generic_register_name):
        # Generate a stop reply, parse out expedited registers from stop
        # notification.
        expedited_registers = self.gather_expedited_registers()
        self.assertIsNotNone(expedited_registers)
        self.assertTrue(len(expedited_registers) > 0)

        # Gather target register infos.
        reg_infos = self.gather_register_infos()

        # Find the generic register.
        reg_info = self.find_generic_register_with_name(
            reg_infos, generic_register_name
        )
        self.assertIsNotNone(reg_info)

        # Ensure the expedited registers contained it.
        self.assertIn(reg_info["lldb_register_index"], expedited_registers)
        self.trace("{} reg_info:{}".format(generic_register_name, reg_info))

    def test_stop_notification_contains_any_registers(self):
        self.build()
        self.set_inferior_startup_launch()

        # Generate a stop reply, parse out expedited registers from stop
        # notification.
        expedited_registers = self.gather_expedited_registers()
        # Verify we have at least one expedited register.
        self.assertTrue(len(expedited_registers) > 0)

    def test_stop_notification_contains_no_duplicate_registers(self):
        self.build()
        self.set_inferior_startup_launch()

        # Generate a stop reply, parse out expedited registers from stop
        # notification.
        expedited_registers = self.gather_expedited_registers()
        # Verify no expedited register was specified multiple times.
        for reg_num, value in list(expedited_registers.items()):
            if (isinstance(value, list)) and (len(value) > 0):
                self.fail(
                    "expedited register number {} specified more than once ({} times)".format(
                        reg_num, len(value)
                    )
                )

    def test_stop_notification_contains_pc_register(self):
        self.build()
        self.set_inferior_startup_launch()
        self.stop_notification_contains_generic_register("pc")

    @skipIf(triple="^powerpc64")  # powerpc64 has no FP register
    def test_stop_notification_contains_fp_register(self):
        self.build()
        self.set_inferior_startup_launch()
        self.stop_notification_contains_generic_register("fp")

    def test_stop_notification_contains_sp_register(self):
        self.build()
        self.set_inferior_startup_launch()
        self.stop_notification_contains_generic_register("sp")

    @skipIf(archs=no_match(["aarch64"]))
    @skipIf(oslist=no_match(["linux"]))
    def test_stop_notification_contains_vg_register(self):
        if not self.isAArch64SVE():
            self.skipTest("SVE registers must be supported.")
        self.build()
        self.set_inferior_startup_launch()

        # Generate a stop reply, parse out expedited registers from stop
        # notification.
        expedited_registers = self.gather_expedited_registers()
        self.assertIsNotNone(expedited_registers)
        self.assertTrue(len(expedited_registers) > 0)

        # Gather target register infos.
        reg_infos = self.gather_register_infos()

        # Find the vg register.
        reg_info = self.find_register_with_name_and_dwarf_regnum(reg_infos, "vg", "46")
        self.assertIsNotNone(reg_info)

        # Ensure the expedited registers contained it.
        self.assertIn(reg_info["lldb_register_index"], expedited_registers)
        self.trace("{} reg_info:{}".format("vg", reg_info))