Skip to content

Commit c338e17

Browse files
committed
[lldb] Add nullptr checks in all usages of ThreadSafeReflectionContext
rdar://116528842
1 parent 7f8a88f commit c338e17

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
@@ -249,6 +249,8 @@ SwiftLanguageRuntimeImpl::GetMemoryReader() {
249249
m_process, [&](swift::remote::RemoteAbsolutePointer pointer) {
250250
ThreadSafeReflectionContext reflection_context =
251251
GetReflectionContext();
252+
if (!reflection_context)
253+
return pointer;
252254
return reflection_context->StripSignedPointer(pointer);
253255
}));
254256
}
@@ -663,6 +665,9 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
663665
return {};
664666

665667
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
668+
if (!reflection_ctx)
669+
return {};
670+
666671
LLDBTypeInfoProvider tip(*this, *ts);
667672
auto *cti = reflection_ctx->GetClassInstanceTypeInfo(tr, &tip);
668673
if (auto *rti =
@@ -736,6 +741,9 @@ SwiftLanguageRuntimeImpl::GetNumFields(CompilerType type,
736741
return 0;
737742
case ReferenceKind::Strong:
738743
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
744+
if (!reflection_ctx)
745+
return {};
746+
739747
LLDBTypeInfoProvider tip(*this, *ts);
740748
auto *cti = reflection_ctx->GetClassInstanceTypeInfo(tr, &tip);
741749
if (auto *rti = llvm::dyn_cast_or_null<RecordTypeInfo>(cti)) {
@@ -868,6 +876,9 @@ SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
868876
child_indexes);
869877
case ReferenceKind::Strong: {
870878
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
879+
if (!reflection_ctx)
880+
return {false, {}};
881+
871882
LLDBTypeInfoProvider tip(*this, *ts);
872883
// `current_tr` iterates the class hierarchy, from the current class, each
873884
// superclass, and ends on null.
@@ -1565,6 +1576,9 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Class(
15651576
}
15661577
Log *log(GetLog(LLDBLog::Types));
15671578
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
1579+
if (!reflection_ctx)
1580+
return false;
1581+
15681582
const auto *typeref =
15691583
reflection_ctx->ReadTypeFromInstance(instance_ptr, true);
15701584
if (!typeref) {
@@ -1717,6 +1731,9 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Protocol(
17171731
swift::remote::RemoteAddress remote_existential(existential_address);
17181732

17191733
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
1734+
if (!reflection_ctx)
1735+
return false;
1736+
17201737
auto pair = reflection_ctx->ProjectExistentialAndUnwrapClass(
17211738
remote_existential, *protocol_typeref);
17221739
if (use_local_buffer)
@@ -2108,22 +2125,23 @@ SwiftLanguageRuntimeImpl::GetValueType(ValueObject &in_value,
21082125
// Read the value witness table and check if the data is inlined in
21092126
// the existential container or not.
21102127
swift::remote::RemoteAddress remote_existential(existential_address);
2111-
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
2112-
llvm::Optional<bool> is_inlined =
2113-
reflection_ctx->IsValueInlinedInExistentialContainer(
2114-
remote_existential);
2115-
2116-
if (use_local_buffer)
2117-
PopLocalBuffer();
2118-
2119-
// An error has occurred when trying to read value witness table,
2120-
// default to treating it as pointer.
2121-
if (!is_inlined.has_value())
2122-
return Value::ValueType::LoadAddress;
2123-
2124-
// Inlined data, same as static data.
2125-
if (*is_inlined)
2126-
return static_value_type;
2128+
if (ThreadSafeReflectionContext reflection_ctx = GetReflectionContext()) {
2129+
llvm::Optional<bool> is_inlined =
2130+
reflection_ctx->IsValueInlinedInExistentialContainer(
2131+
remote_existential);
2132+
2133+
if (use_local_buffer)
2134+
PopLocalBuffer();
2135+
2136+
// An error has occurred when trying to read value witness table,
2137+
// default to treating it as pointer.
2138+
if (!is_inlined.has_value())
2139+
return Value::ValueType::LoadAddress;
2140+
2141+
// Inlined data, same as static data.
2142+
if (*is_inlined)
2143+
return static_value_type;
2144+
}
21272145

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

0 commit comments

Comments
 (0)