Skip to content

Commit acfbd1b

Browse files
Merge pull request #3823 from adrian-prantl/87179578-main
Reland swiftlang/swift#40843
2 parents d43a6ae + bd02a7f commit acfbd1b

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,24 @@ void SwiftLanguageRuntimeImpl::SetupReflection() {
461461

462462
auto &target = m_process.GetTarget();
463463
if (auto exe_module = target.GetExecutableModule()) {
464+
bool objc_interop = (bool)findRuntime(m_process, RuntimeKind::ObjC);
465+
const char *objc_interop_msg =
466+
objc_interop ? "with Objective-C interopability" : "Swift only";
467+
464468
auto &triple = exe_module->GetArchitecture().GetTriple();
465-
if (triple.isArch64Bit())
469+
if (triple.isArch64Bit()) {
470+
LLDB_LOGF(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
471+
"Initializing a 64-bit reflection context (%s) for \"%s\"",
472+
triple.str().c_str(), objc_interop_msg);
466473
m_reflection_ctx = ReflectionContextInterface::CreateReflectionContext64(
467-
this->GetMemoryReader());
468-
else if (triple.isArch32Bit())
474+
this->GetMemoryReader(), objc_interop);
475+
} else if (triple.isArch32Bit()) {
476+
LLDB_LOGF(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
477+
"Initializing a 32-bit reflection context (%s) for \"%s\"",
478+
triple.str().c_str(), objc_interop_msg);
469479
m_reflection_ctx = ReflectionContextInterface::CreateReflectionContext32(
470-
this->GetMemoryReader());
471-
else {
480+
this->GetMemoryReader(), objc_interop);
481+
} else {
472482
LLDB_LOGF(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
473483
"Could not initialize reflection context for \"%s\"",
474484
triple.str().c_str());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class MemoryReader;
3434
class RemoteAddress;
3535
} // namespace remote
3636

37-
template <typename T> struct External;
37+
template <typename Runtime> struct External;
3838
template <unsigned PointerSize> struct RuntimeTarget;
3939

4040
namespace reflection {

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,10 @@ namespace {
231231

232232
/// An implementation of the generic ReflectionContextInterface that
233233
/// is templatized on target pointer width and specialized to either
234-
/// 32-bit or 64-bit pointers.
235-
template <unsigned PointerSize>
234+
/// 32-bit or 64-bit pointers, with and without ObjC interoperability.
235+
template <typename ReflectionContext>
236236
class TargetReflectionContext
237237
: public SwiftLanguageRuntimeImpl::ReflectionContextInterface {
238-
using ReflectionContext = swift::reflection::ReflectionContext<
239-
swift::External<swift::RuntimeTarget<PointerSize>>>;
240238
ReflectionContext m_reflection_ctx;
241239

242240
public:
@@ -348,14 +346,30 @@ class TargetReflectionContext
348346

349347
std::unique_ptr<SwiftLanguageRuntimeImpl::ReflectionContextInterface>
350348
SwiftLanguageRuntimeImpl::ReflectionContextInterface::CreateReflectionContext32(
351-
std::shared_ptr<swift::remote::MemoryReader> reader) {
352-
return std::make_unique<TargetReflectionContext<4>>(reader);
349+
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop) {
350+
using ReflectionContext32ObjCInterop =
351+
TargetReflectionContext<swift::reflection::ReflectionContext<
352+
swift::External<swift::WithObjCInterop<swift::RuntimeTarget<4>>>>>;
353+
using ReflectionContext32NoObjCInterop =
354+
TargetReflectionContext<swift::reflection::ReflectionContext<
355+
swift::External<swift::NoObjCInterop<swift::RuntimeTarget<4>>>>>;
356+
if (ObjCInterop)
357+
return std::make_unique<ReflectionContext32ObjCInterop>(reader);
358+
return std::make_unique<ReflectionContext32NoObjCInterop>(reader);
353359
}
354360

355361
std::unique_ptr<SwiftLanguageRuntimeImpl::ReflectionContextInterface>
356362
SwiftLanguageRuntimeImpl::ReflectionContextInterface::CreateReflectionContext64(
357-
std::shared_ptr<swift::remote::MemoryReader> reader) {
358-
return std::make_unique<TargetReflectionContext<8>>(reader);
363+
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop) {
364+
using ReflectionContext64ObjCInterop =
365+
TargetReflectionContext<swift::reflection::ReflectionContext<
366+
swift::External<swift::WithObjCInterop<swift::RuntimeTarget<8>>>>>;
367+
using ReflectionContext64NoObjCInterop =
368+
TargetReflectionContext<swift::reflection::ReflectionContext<
369+
swift::External<swift::NoObjCInterop<swift::RuntimeTarget<8>>>>>;
370+
if (ObjCInterop)
371+
return std::make_unique<ReflectionContext64ObjCInterop>(reader);
372+
return std::make_unique<ReflectionContext64NoObjCInterop>(reader);
359373
}
360374

361375
SwiftLanguageRuntimeImpl::ReflectionContextInterface::

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ class SwiftLanguageRuntimeImpl {
200200
/// Return a 32-bit reflection context.
201201
static std::unique_ptr<ReflectionContextInterface>
202202
CreateReflectionContext32(
203-
std::shared_ptr<swift::remote::MemoryReader> reader);
203+
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop);
204204

205205
/// Return a 64-bit reflection context.
206206
static std::unique_ptr<ReflectionContextInterface>
207207
CreateReflectionContext64(
208-
std::shared_ptr<swift::remote::MemoryReader> reader);
208+
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop);
209209

210210
virtual ~ReflectionContextInterface();
211211

0 commit comments

Comments
 (0)