brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · a5c0abd Raw
58 lines · python
1"""Test that lldb on Darwin ignores metadata in the top byte of addresses, both corefile and live."""2 3import lldb4from lldbsuite.test.decorators import *5from lldbsuite.test.lldbtest import *6from lldbsuite.test import lldbutil7 8 9class TestTBIHonored(TestBase):10    NO_DEBUG_INFO_TESTCASE = True11 12    def do_variable_access_tests(self, frame):13        self.assertEqual(14            frame.variables["pb"][0]15            .GetChildMemberWithName("p")16            .Dereference()17            .GetValueAsUnsigned(),18            15,19        )20        addr = frame.variables["pb"][0].GetChildMemberWithName("p").GetValueAsUnsigned()21        # Confirm that there is metadata in the top byte of our pointer22        self.assertEqual((addr >> 56) & 0xFF, 0xFE)23        self.expect("expr -- *pb.p", substrs=["15"])24        self.expect("frame variable *pb.p", substrs=["15"])25        self.expect("expr -- *(int*)0x%x" % addr, substrs=["15"])26 27    # This test is valid on AArch64 systems with TBI mode enabled,28    # and an address mask that clears the top byte before reading29    # from memory.30    @skipUnlessDarwin31    @skipIf(archs=no_match(["arm64", "arm64e"]))32    @skipIfRemote33    def test(self):34        corefile = self.getBuildArtifact("process.core")35        self.build()36        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(37            self, "// break here", lldb.SBFileSpec("main.c")38        )39 40        # Test that we can dereference a pointer with TBI data41        # in a live process.42        self.do_variable_access_tests(thread.GetFrameAtIndex(0))43 44        # Create a corefile, delete this process45        self.runCmd("process save-core -s stack " + corefile)46        process.Destroy()47        self.dbg.DeleteTarget(target)48 49        # Now load the corefile50        target = self.dbg.CreateTarget("")51        process = target.LoadCore(corefile)52        thread = process.GetSelectedThread()53        self.assertTrue(process.GetSelectedThread().IsValid())54 55        # Test that we can dereference a pointer with TBI data56        # in a corefile process.57        self.do_variable_access_tests(thread.GetFrameAtIndex(0))58