|
| 1 | +"""Test that lldb on Darwin ignores metadata in the top byte of addresses, both corefile and live.""" |
| 2 | + |
| 3 | +import lldb |
| 4 | +from lldbsuite.test.decorators import * |
| 5 | +from lldbsuite.test.lldbtest import * |
| 6 | +from lldbsuite.test import lldbutil |
| 7 | + |
| 8 | + |
| 9 | +class TestTBIHonored(TestBase): |
| 10 | + NO_DEBUG_INFO_TESTCASE = True |
| 11 | + |
| 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 pointer |
| 22 | + 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 reading |
| 29 | + # from memory. |
| 30 | + @skipUnlessDarwin |
| 31 | + @skipIf(archs=no_match(["arm64", "arm64e"])) |
| 32 | + @skipIfRemote |
| 33 | + 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 data |
| 41 | + # in a live process. |
| 42 | + self.do_variable_access_tests(thread.GetFrameAtIndex(0)) |
| 43 | + |
| 44 | + # Create a corefile, delete this process |
| 45 | + self.runCmd("process save-core -s stack " + corefile) |
| 46 | + process.Destroy() |
| 47 | + self.dbg.DeleteTarget(target) |
| 48 | + |
| 49 | + # Now load the corefile |
| 50 | + 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 data |
| 56 | + # in a corefile process. |
| 57 | + self.do_variable_access_tests(thread.GetFrameAtIndex(0)) |
0 commit comments