Skip to content

Commit b28a169

Browse files
committed
Parameterize CreateReflectionContext (NFC)
1 parent 6af13aa commit b28a169

File tree

3 files changed

+30
-44
lines changed

3 files changed

+30
-44
lines changed

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -517,23 +517,16 @@ void SwiftLanguageRuntimeImpl::SetupReflection() {
517517
objc_interop ? "with Objective-C interopability" : "Swift only";
518518

519519
auto &triple = exe_module->GetArchitecture().GetTriple();
520-
auto byte_size = m_process.GetAddressByteSize();
521-
if (byte_size == 8) {
522-
LLDB_LOGF(log, "Initializing a 64-bit reflection context (%s) for \"%s\"",
523-
triple.str().c_str(), objc_interop_msg);
524-
m_reflection_ctx = ReflectionContextInterface::CreateReflectionContext64(
525-
this->GetMemoryReader(), objc_interop, GetSwiftMetadataCache());
526-
} else if (byte_size == 4) {
527-
LLDB_LOGF(log,
528-
"Initializing a 32-bit reflection context (%s) for \"%s\"",
529-
triple.str().c_str(), objc_interop_msg);
530-
m_reflection_ctx = ReflectionContextInterface::CreateReflectionContext32(
531-
this->GetMemoryReader(), objc_interop, GetSwiftMetadataCache());
532-
} else {
533-
LLDB_LOGF(log,
534-
"Could not initialize reflection context for \"%s\"",
535-
triple.str().c_str());
536-
}
520+
uint32_t ptr_size = m_process.GetAddressByteSize();
521+
LLDB_LOG(log, "Initializing a {0}-bit reflection context ({1}) for \"{2}\"",
522+
ptr_size * 8, triple.str(), objc_interop_msg);
523+
if (ptr_size == 4 || ptr_size == 8)
524+
m_reflection_ctx = ReflectionContextInterface::CreateReflectionContext(
525+
ptr_size, this->GetMemoryReader(), objc_interop,
526+
GetSwiftMetadataCache());
527+
if (!m_reflection_ctx)
528+
LLDB_LOG(log, "Could not initialize reflection context for \"{0}\"",
529+
triple.str());
537530
// We set m_initialized_reflection_ctx to true here because
538531
// AddModuleToReflectionContext can potentially call into SetupReflection
539532
// again (which will early exit). This is safe to do since every other thread

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -387,37 +387,36 @@ class TargetReflectionContext
387387
} // namespace
388388

389389
std::unique_ptr<SwiftLanguageRuntimeImpl::ReflectionContextInterface>
390-
SwiftLanguageRuntimeImpl::ReflectionContextInterface::CreateReflectionContext32(
391-
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop,
392-
SwiftMetadataCache *swift_metadata_cache) {
390+
SwiftLanguageRuntimeImpl::ReflectionContextInterface::CreateReflectionContext(
391+
uint8_t ptr_size, std::shared_ptr<swift::remote::MemoryReader> reader,
392+
bool ObjCInterop, SwiftMetadataCache *swift_metadata_cache) {
393393
using ReflectionContext32ObjCInterop =
394394
TargetReflectionContext<swift::reflection::ReflectionContext<
395395
swift::External<swift::WithObjCInterop<swift::RuntimeTarget<4>>>>>;
396396
using ReflectionContext32NoObjCInterop =
397397
TargetReflectionContext<swift::reflection::ReflectionContext<
398398
swift::External<swift::NoObjCInterop<swift::RuntimeTarget<4>>>>>;
399-
if (ObjCInterop)
400-
return std::make_unique<ReflectionContext32ObjCInterop>(
401-
reader, swift_metadata_cache);
402-
return std::make_unique<ReflectionContext32NoObjCInterop>(
403-
reader, swift_metadata_cache);
404-
}
405-
406-
std::unique_ptr<SwiftLanguageRuntimeImpl::ReflectionContextInterface>
407-
SwiftLanguageRuntimeImpl::ReflectionContextInterface::CreateReflectionContext64(
408-
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop,
409-
SwiftMetadataCache *swift_metadata_cache) {
410399
using ReflectionContext64ObjCInterop =
411400
TargetReflectionContext<swift::reflection::ReflectionContext<
412401
swift::External<swift::WithObjCInterop<swift::RuntimeTarget<8>>>>>;
413402
using ReflectionContext64NoObjCInterop =
414403
TargetReflectionContext<swift::reflection::ReflectionContext<
415404
swift::External<swift::NoObjCInterop<swift::RuntimeTarget<8>>>>>;
416-
if (ObjCInterop)
417-
return std::make_unique<ReflectionContext64ObjCInterop>(
405+
if (ptr_size == 4) {
406+
if (ObjCInterop)
407+
return std::make_unique<ReflectionContext32ObjCInterop>(
408+
reader, swift_metadata_cache);
409+
return std::make_unique<ReflectionContext32NoObjCInterop>(
418410
reader, swift_metadata_cache);
419-
return std::make_unique<ReflectionContext64NoObjCInterop>(
420-
reader, swift_metadata_cache);
411+
}
412+
if (ptr_size == 8) {
413+
if (ObjCInterop)
414+
return std::make_unique<ReflectionContext64ObjCInterop>(
415+
reader, swift_metadata_cache);
416+
return std::make_unique<ReflectionContext64NoObjCInterop>(
417+
reader, swift_metadata_cache);
418+
}
419+
return {};
421420
}
422421

423422
SwiftLanguageRuntimeImpl::ReflectionContextInterface::

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,10 @@ class SwiftLanguageRuntimeImpl {
212212
/// a specific pointer width.
213213
class ReflectionContextInterface {
214214
public:
215-
/// Return a 32-bit reflection context.
215+
/// Return a reflection context.
216216
static std::unique_ptr<ReflectionContextInterface>
217-
CreateReflectionContext32(
218-
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop,
219-
SwiftMetadataCache *swift_metadata_cache);
220-
221-
/// Return a 64-bit reflection context.
222-
static std::unique_ptr<ReflectionContextInterface>
223-
CreateReflectionContext64(
224-
std::shared_ptr<swift::remote::MemoryReader> reader, bool ObjCInterop,
217+
CreateReflectionContext(uint8_t pointer_size,
218+
std::shared_ptr<swift::remote::MemoryReader> reader, bool objc_interop,
225219
SwiftMetadataCache *swift_metadata_cache);
226220

227221
virtual ~ReflectionContextInterface();

0 commit comments

Comments
 (0)