Skip to content

[lldb] Make private type reflection metadata available from the file … #10804

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

Open
wants to merge 1 commit into
base: stable/20240723
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,19 @@ LLDBMemoryReader::getFileAddressAndModuleForTaggedAddress(
return {{file_address, module}};
}

std::optional<swift::reflection::RemoteAddress>
LLDBMemoryReader::resolveRemoteAddress(
swift::reflection::RemoteAddress address) const {
std::optional<Address> lldb_address =
LLDBMemoryReader::resolveRemoteAddress(address.getAddressData());
if (!lldb_address)
return {};
lldb::addr_t addr = lldb_address->GetLoadAddress(&m_process.GetTarget());
if (addr != LLDB_INVALID_ADDRESS)
return swift::reflection::RemoteAddress(addr);
return {};
}

std::optional<Address>
LLDBMemoryReader::resolveRemoteAddress(uint64_t address) const {
Log *log(GetLog(LLDBLog::Types));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class LLDBMemoryReader : public swift::remote::MemoryReader {
resolvePointer(swift::remote::RemoteAddress address,
uint64_t readValue) override;

std::optional<swift::remote::RemoteAddress>
resolveRemoteAddress(swift::remote::RemoteAddress address) const override;

bool readBytes(swift::remote::RemoteAddress address, uint8_t *dest,
uint64_t size) override;

Expand Down
2 changes: 2 additions & 0 deletions lldb/test/API/lang/swift/observation/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SWIFT_SOURCES := main.swift
include Makefile.rules
21 changes: 21 additions & 0 deletions lldb/test/API/lang/swift/observation/TestSwiftObservation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil

class TestSwiftObservation(TestBase):
NO_DEBUG_INFO_TESTCASE = True
@swiftTest
def test(self):
"""Test that types with private discriminators read from the file cache work"""
self.build()
lldbutil.run_to_source_breakpoint(self, 'break here',
lldb.SBFileSpec('main.swift'))
# FIXME: Private discriminators are UUIDs in DWARF and pointers
# in Reflection metafdata, making tham not comparable.
# rdar://74374120
self.expect("settings set symbols.swift-validate-typesystem false")
self.expect("settings set target.experimental.swift-read-metadata-from-file-cache true")
r = self.frame().FindVariable("r")
extent = r.GetChildAtIndex(0)
self.assertEqual(extent.GetName(), "extent")
8 changes: 8 additions & 0 deletions lldb/test/API/lang/swift/observation/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Observation

func f() {
let r = ObservationRegistrar()
print("break here")
}

f()