Skip to content

Make Objective-C interoperability configurable in the runtime #3789

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 1 commit into from
Jan 19, 2022
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
20 changes: 15 additions & 5 deletions lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,24 @@ void SwiftLanguageRuntimeImpl::SetupReflection() {

auto &target = m_process.GetTarget();
if (auto exe_module = target.GetExecutableModule()) {
bool objc_interop = (bool)findRuntime(m_process, RuntimeKind::ObjC);
const char *objc_interop_msg =
objc_interop ? "with Objective-C interopability" : "Swift only";

auto &triple = exe_module->GetArchitecture().GetTriple();
if (triple.isArch64Bit())
if (triple.isArch64Bit()) {
LLDB_LOGF(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
"Initializing a 64-bit reflection context (%s) for \"%s\"",
triple.str().c_str(), objc_interop_msg);
m_reflection_ctx = ReflectionContextInterface::CreateReflectionContext64(
this->GetMemoryReader());
else if (triple.isArch32Bit())
this->GetMemoryReader(), objc_interop);
} else if (triple.isArch32Bit()) {
LLDB_LOGF(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
"Initializing a 32-bit reflection context (%s) for \"%s\"",
triple.str().c_str(), objc_interop_msg);
m_reflection_ctx = ReflectionContextInterface::CreateReflectionContext32(
this->GetMemoryReader());
else {
this->GetMemoryReader(), objc_interop);
} else {
LLDB_LOGF(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
"Could not initialize reflection context for \"%s\"",
triple.str().c_str());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MemoryReader;
class RemoteAddress;
} // namespace remote

template <typename T> struct External;
template <typename Runtime> struct External;
template <unsigned PointerSize> struct RuntimeTarget;

namespace reflection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,10 @@ namespace {

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

public:
Expand Down Expand Up @@ -350,14 +348,30 @@ class TargetReflectionContext

std::unique_ptr<SwiftLanguageRuntimeImpl::ReflectionContextInterface>
SwiftLanguageRuntimeImpl::ReflectionContextInterface::CreateReflectionContext32(
std::shared_ptr<swift::remote::MemoryReader> reader) {
return std::make_unique<TargetReflectionContext<4>>(reader);
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop) {
using ReflectionContext32ObjCInterop =
TargetReflectionContext<swift::reflection::ReflectionContext<
swift::External<swift::WithObjCInterop<swift::RuntimeTarget<4>>>>>;
using ReflectionContext32NoObjCInterop =
TargetReflectionContext<swift::reflection::ReflectionContext<
swift::External<swift::NoObjCInterop<swift::RuntimeTarget<4>>>>>;
if (ObjCInterop)
return std::make_unique<ReflectionContext32ObjCInterop>(reader);
return std::make_unique<ReflectionContext32NoObjCInterop>(reader);
}

std::unique_ptr<SwiftLanguageRuntimeImpl::ReflectionContextInterface>
SwiftLanguageRuntimeImpl::ReflectionContextInterface::CreateReflectionContext64(
std::shared_ptr<swift::remote::MemoryReader> reader) {
return std::make_unique<TargetReflectionContext<8>>(reader);
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop) {
using ReflectionContext64ObjCInterop =
TargetReflectionContext<swift::reflection::ReflectionContext<
swift::External<swift::WithObjCInterop<swift::RuntimeTarget<8>>>>>;
using ReflectionContext64NoObjCInterop =
TargetReflectionContext<swift::reflection::ReflectionContext<
swift::External<swift::NoObjCInterop<swift::RuntimeTarget<8>>>>>;
if (ObjCInterop)
return std::make_unique<ReflectionContext64ObjCInterop>(reader);
return std::make_unique<ReflectionContext64NoObjCInterop>(reader);
}

SwiftLanguageRuntimeImpl::ReflectionContextInterface::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ class SwiftLanguageRuntimeImpl {
/// Return a 32-bit reflection context.
static std::unique_ptr<ReflectionContextInterface>
CreateReflectionContext32(
std::shared_ptr<swift::remote::MemoryReader> reader);
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop);

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

virtual ~ReflectionContextInterface();

Expand Down