Skip to content

Commit c790e7a

Browse files
committed
WIP: Make Objective-C interoperability configurable in the runtime
1 parent cce8265 commit c790e7a

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:
@@ -350,14 +348,30 @@ class TargetReflectionContext
350348

351349
std::unique_ptr<SwiftLanguageRuntimeImpl::ReflectionContextInterface>
352350
SwiftLanguageRuntimeImpl::ReflectionContextInterface::CreateReflectionContext32(
353-
std::shared_ptr<swift::remote::MemoryReader> reader) {
354-
return std::make_unique<TargetReflectionContext<4>>(reader);
351+
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop) {
352+
using ReflectionContext32ObjCInterop =
353+
TargetReflectionContext<swift::reflection::ReflectionContext<
354+
swift::External<swift::WithObjCInterop<swift::RuntimeTarget<4>>>>>;
355+
using ReflectionContext32NoObjCInterop =
356+
TargetReflectionContext<swift::reflection::ReflectionContext<
357+
swift::External<swift::NoObjCInterop<swift::RuntimeTarget<4>>>>>;
358+
if (ObjCInterop)
359+
return std::make_unique<ReflectionContext32ObjCInterop>(reader);
360+
return std::make_unique<ReflectionContext32NoObjCInterop>(reader);
355361
}
356362

357363
std::unique_ptr<SwiftLanguageRuntimeImpl::ReflectionContextInterface>
358364
SwiftLanguageRuntimeImpl::ReflectionContextInterface::CreateReflectionContext64(
359-
std::shared_ptr<swift::remote::MemoryReader> reader) {
360-
return std::make_unique<TargetReflectionContext<8>>(reader);
365+
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop) {
366+
using ReflectionContext64ObjCInterop =
367+
TargetReflectionContext<swift::reflection::ReflectionContext<
368+
swift::External<swift::WithObjCInterop<swift::RuntimeTarget<8>>>>>;
369+
using ReflectionContext64NoObjCInterop =
370+
TargetReflectionContext<swift::reflection::ReflectionContext<
371+
swift::External<swift::NoObjCInterop<swift::RuntimeTarget<8>>>>>;
372+
if (ObjCInterop)
373+
return std::make_unique<ReflectionContext64ObjCInterop>(reader);
374+
return std::make_unique<ReflectionContext64NoObjCInterop>(reader);
361375
}
362376

363377
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)