Skip to content

[lldb] [Mach-O] ProcessMachCore needs to strip TBI data from addrs #84998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ size_t ProcessMachCore::ReadMemory(addr_t addr, void *buf, size_t size,
Status &error) {
// Don't allow the caching that lldb_private::Process::ReadMemory does since
// in core files we have it all cached our our core file anyway.
return DoReadMemory(addr, buf, size, error);
return DoReadMemory(FixAnyAddress(addr), buf, size, error);
}

size_t ProcessMachCore::DoReadMemory(addr_t addr, void *buf, size_t size,
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/macosx/tbi-honored/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
C_SOURCES := main.c

include Makefile.rules
57 changes: 57 additions & 0 deletions lldb/test/API/macosx/tbi-honored/TestTBIHonored.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Test that lldb on Darwin ignores metadata in the top byte of addresses, both corefile and live."""

import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TestTBIHonored(TestBase):
NO_DEBUG_INFO_TESTCASE = True

def do_variable_access_tests(self, frame):
self.assertEqual(
frame.variables["pb"][0]
.GetChildMemberWithName("p")
.Dereference()
.GetValueAsUnsigned(),
15,
)
addr = frame.variables["pb"][0].GetChildMemberWithName("p").GetValueAsUnsigned()
# Confirm that there is metadata in the top byte of our pointer
self.assertEqual((addr >> 56) & 0xFF, 0xFE)
self.expect("expr -- *pb.p", substrs=["15"])
self.expect("frame variable *pb.p", substrs=["15"])
self.expect("expr -- *(int*)0x%x" % addr, substrs=["15"])

# This test is valid on AArch64 systems with TBI mode enabled,
# and an address mask that clears the top byte before reading
# from memory.
@skipUnlessDarwin
@skipIf(archs=no_match(["arm64", "arm64e"]))
@skipIfRemote
def test(self):
corefile = self.getBuildArtifact("process.core")
self.build()
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "// break here", lldb.SBFileSpec("main.c")
)

# Test that we can dereference a pointer with TBI data
# in a live process.
self.do_variable_access_tests(thread.GetFrameAtIndex(0))

# Create a corefile, delete this process
self.runCmd("process save-core -s stack " + corefile)
process.Destroy()
self.dbg.DeleteTarget(target)

# Now load the corefile
target = self.dbg.CreateTarget("")
process = target.LoadCore(corefile)
thread = process.GetSelectedThread()
self.assertTrue(process.GetSelectedThread().IsValid())

# Test that we can dereference a pointer with TBI data
# in a corefile process.
self.do_variable_access_tests(thread.GetFrameAtIndex(0))
13 changes: 13 additions & 0 deletions lldb/test/API/macosx/tbi-honored/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdint.h>
#include <stdio.h>
union ptrbytes {
int *p;
uint8_t bytes[8];
};
int main() {
int c = 15;
union ptrbytes pb;
pb.p = &c;
pb.bytes[7] = 0xfe;
printf("%d\n", *pb.p); // break here
}