Skip to content

Commit 49dd75f

Browse files
committed
[lldb] Add nullptr checks in all usages of ThreadSafeReflectionContext
rdar://116528842 (cherry picked from commit c338e17)
1 parent 3c0e564 commit 49dd75f

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

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

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ SwiftLanguageRuntimeImpl::GetMemoryReader() {
237237
m_process, [&](swift::remote::RemoteAbsolutePointer pointer) {
238238
ThreadSafeReflectionContext reflection_context =
239239
GetReflectionContext();
240+
if (!reflection_context)
241+
return pointer;
240242
return reflection_context->StripSignedPointer(pointer);
241243
}));
242244
}
@@ -653,6 +655,9 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
653655
return {};
654656

655657
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
658+
if (!reflection_ctx)
659+
return {};
660+
656661
LLDBTypeInfoProvider tip(*this, *ts);
657662
auto *cti = reflection_ctx->GetClassInstanceTypeInfo(
658663
tr, &tip, ts->GetDescriptorFinder());
@@ -728,6 +733,9 @@ SwiftLanguageRuntimeImpl::GetNumFields(CompilerType type,
728733
return 0;
729734
case ReferenceKind::Strong:
730735
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
736+
if (!reflection_ctx)
737+
return {};
738+
731739
LLDBTypeInfoProvider tip(*this, *ts);
732740
auto *cti = reflection_ctx->GetClassInstanceTypeInfo(
733741
tr, &tip, ts->GetDescriptorFinder());
@@ -861,6 +869,9 @@ SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
861869
child_indexes);
862870
case ReferenceKind::Strong: {
863871
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
872+
if (!reflection_ctx)
873+
return {false, {}};
874+
864875
LLDBTypeInfoProvider tip(*this, *ts);
865876
// `current_tr` iterates the class hierarchy, from the current class, each
866877
// superclass, and ends on null.
@@ -1721,6 +1732,9 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Protocol(
17211732
swift::remote::RemoteAddress remote_existential(existential_address);
17221733

17231734
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
1735+
if (!reflection_ctx)
1736+
return false;
1737+
17241738
auto pair = reflection_ctx->ProjectExistentialAndUnwrapClass(
17251739
remote_existential, *protocol_typeref,
17261740
tss->GetTypeSystemSwiftTypeRef().GetDescriptorFinder());
@@ -2184,22 +2198,23 @@ SwiftLanguageRuntimeImpl::GetValueType(ValueObject &in_value,
21842198
// Read the value witness table and check if the data is inlined in
21852199
// the existential container or not.
21862200
swift::remote::RemoteAddress remote_existential(existential_address);
2187-
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
2188-
llvm::Optional<bool> is_inlined =
2189-
reflection_ctx->IsValueInlinedInExistentialContainer(
2190-
remote_existential);
2191-
2192-
if (use_local_buffer)
2193-
PopLocalBuffer();
2194-
2195-
// An error has occurred when trying to read value witness table,
2196-
// default to treating it as pointer.
2197-
if (!is_inlined.has_value())
2198-
return Value::ValueType::LoadAddress;
2199-
2200-
// Inlined data, same as static data.
2201-
if (*is_inlined)
2202-
return static_value_type;
2201+
if (ThreadSafeReflectionContext reflection_ctx = GetReflectionContext()) {
2202+
llvm::Optional<bool> is_inlined =
2203+
reflection_ctx->IsValueInlinedInExistentialContainer(
2204+
remote_existential);
2205+
2206+
if (use_local_buffer)
2207+
PopLocalBuffer();
2208+
2209+
// An error has occurred when trying to read value witness table,
2210+
// default to treating it as pointer.
2211+
if (!is_inlined.has_value())
2212+
return Value::ValueType::LoadAddress;
2213+
2214+
// Inlined data, same as static data.
2215+
if (*is_inlined)
2216+
return static_value_type;
2217+
}
22032218

22042219
// If the data is not inlined, we have a pointer.
22052220
return Value::ValueType::LoadAddress;

0 commit comments

Comments
 (0)