Skip to content

Commit dbacde9

Browse files
adrian-prantlaugusto2112
authored andcommitted
[lldb] Make private type reflection metadata available from the file cache
This fixes a bug in LLDB's file cache. Private types have anonymous context descriptors, which are just a string that is the metadata pointer in hex. This is a problem when the meatdata was read from a file because then the address isn't comparable against the same type constructed from in-process memory. This patch fixes this by implementing a new hook to canonicalize file addresses to in-process addresses in MemoryReader. rdar://151330005 (cherry picked from commit d86ea4e)
1 parent cd13a9b commit dbacde9

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/LLDBMemoryReader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class LLDBMemoryReader : public swift::remote::MemoryReader {
7676
resolvePointer(swift::remote::RemoteAddress address,
7777
uint64_t readValue) override;
7878

79+
std::optional<swift::remote::RemoteAddress>
80+
resolveRemoteAddress(swift::remote::RemoteAddress address) const override;
81+
7982
bool readBytes(swift::remote::RemoteAddress address, uint8_t *dest,
8083
uint64_t size) override;
8184

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SWIFT_SOURCES := main.swift
2+
include Makefile.rules
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
class TestSwiftObservation(TestBase):
7+
NO_DEBUG_INFO_TESTCASE = True
8+
@swiftTest
9+
def test(self):
10+
"""Test that types with private discriminators read from the file cache work"""
11+
self.build()
12+
lldbutil.run_to_source_breakpoint(self, 'break here',
13+
lldb.SBFileSpec('main.swift'))
14+
# FIXME: Private discriminators are UUIDs in DWARF and pointers
15+
# in Reflection metafdata, making tham not comparable.
16+
# rdar://74374120
17+
self.expect("settings set symbols.swift-validate-typesystem false")
18+
self.expect("settings set target.experimental.swift-read-metadata-from-file-cache true")
19+
r = self.frame().FindVariable("r")
20+
extent = r.GetChildAtIndex(0)
21+
self.assertEqual(extent.GetName(), "extent")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Observation
2+
3+
func f() {
4+
let r = ObservationRegistrar()
5+
print("break here")
6+
}
7+
8+
f()

0 commit comments

Comments
 (0)