Skip to content

Commit 541f571

Browse files
authored
Merge pull request #7583 from augusto2112/check-ThreadSafeReflectionContext
[lldb] Add nullptr checks in all usages of ThreadSafeReflectionContext
2 parents 0bbc472 + c338e17 commit 541f571

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

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

Lines changed: 34 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
}
@@ -651,6 +653,9 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
651653
return {};
652654

653655
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
656+
if (!reflection_ctx)
657+
return {};
658+
654659
LLDBTypeInfoProvider tip(*this, *ts);
655660
auto *cti = reflection_ctx->GetClassInstanceTypeInfo(tr, &tip);
656661
if (auto *rti =
@@ -724,6 +729,9 @@ SwiftLanguageRuntimeImpl::GetNumFields(CompilerType type,
724729
return 0;
725730
case ReferenceKind::Strong:
726731
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
732+
if (!reflection_ctx)
733+
return {};
734+
727735
LLDBTypeInfoProvider tip(*this, *ts);
728736
auto *cti = reflection_ctx->GetClassInstanceTypeInfo(tr, &tip);
729737
if (auto *rti = llvm::dyn_cast_or_null<RecordTypeInfo>(cti)) {
@@ -856,6 +864,9 @@ SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
856864
child_indexes);
857865
case ReferenceKind::Strong: {
858866
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
867+
if (!reflection_ctx)
868+
return {false, {}};
869+
859870
LLDBTypeInfoProvider tip(*this, *ts);
860871
// `current_tr` iterates the class hierarchy, from the current class, each
861872
// superclass, and ends on null.
@@ -1553,6 +1564,9 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Class(
15531564
}
15541565
Log *log(GetLog(LLDBLog::Types));
15551566
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
1567+
if (!reflection_ctx)
1568+
return false;
1569+
15561570
const auto *typeref =
15571571
reflection_ctx->ReadTypeFromInstance(instance_ptr, true);
15581572
if (!typeref) {
@@ -1705,6 +1719,9 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Protocol(
17051719
swift::remote::RemoteAddress remote_existential(existential_address);
17061720

17071721
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
1722+
if (!reflection_ctx)
1723+
return false;
1724+
17081725
auto pair = reflection_ctx->ProjectExistentialAndUnwrapClass(
17091726
remote_existential, *protocol_typeref);
17101727
if (use_local_buffer)
@@ -2159,22 +2176,23 @@ SwiftLanguageRuntimeImpl::GetValueType(ValueObject &in_value,
21592176
// Read the value witness table and check if the data is inlined in
21602177
// the existential container or not.
21612178
swift::remote::RemoteAddress remote_existential(existential_address);
2162-
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
2163-
llvm::Optional<bool> is_inlined =
2164-
reflection_ctx->IsValueInlinedInExistentialContainer(
2165-
remote_existential);
2166-
2167-
if (use_local_buffer)
2168-
PopLocalBuffer();
2169-
2170-
// An error has occurred when trying to read value witness table,
2171-
// default to treating it as pointer.
2172-
if (!is_inlined.has_value())
2173-
return Value::ValueType::LoadAddress;
2174-
2175-
// Inlined data, same as static data.
2176-
if (*is_inlined)
2177-
return static_value_type;
2179+
if (ThreadSafeReflectionContext reflection_ctx = GetReflectionContext()) {
2180+
llvm::Optional<bool> is_inlined =
2181+
reflection_ctx->IsValueInlinedInExistentialContainer(
2182+
remote_existential);
2183+
2184+
if (use_local_buffer)
2185+
PopLocalBuffer();
2186+
2187+
// An error has occurred when trying to read value witness table,
2188+
// default to treating it as pointer.
2189+
if (!is_inlined.has_value())
2190+
return Value::ValueType::LoadAddress;
2191+
2192+
// Inlined data, same as static data.
2193+
if (*is_inlined)
2194+
return static_value_type;
2195+
}
21782196

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

0 commit comments

Comments
 (0)