Skip to content

[lldb] Add nullptr checks in all usages of ThreadSafeReflectionContext #8036

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 24, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ SwiftLanguageRuntimeImpl::GetMemoryReader() {
m_process, [&](swift::remote::RemoteAbsolutePointer pointer) {
ThreadSafeReflectionContext reflection_context =
GetReflectionContext();
if (!reflection_context)
return pointer;
return reflection_context->StripSignedPointer(pointer);
}));
}
Expand Down Expand Up @@ -653,6 +655,9 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
return {};

ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
if (!reflection_ctx)
return {};

LLDBTypeInfoProvider tip(*this, *ts);
auto *cti = reflection_ctx->GetClassInstanceTypeInfo(
tr, &tip, ts->GetDescriptorFinder());
Expand Down Expand Up @@ -728,6 +733,9 @@ SwiftLanguageRuntimeImpl::GetNumFields(CompilerType type,
return 0;
case ReferenceKind::Strong:
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
if (!reflection_ctx)
return {};

LLDBTypeInfoProvider tip(*this, *ts);
auto *cti = reflection_ctx->GetClassInstanceTypeInfo(
tr, &tip, ts->GetDescriptorFinder());
Expand Down Expand Up @@ -861,6 +869,9 @@ SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
child_indexes);
case ReferenceKind::Strong: {
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
if (!reflection_ctx)
return {false, {}};

LLDBTypeInfoProvider tip(*this, *ts);
// `current_tr` iterates the class hierarchy, from the current class, each
// superclass, and ends on null.
Expand Down Expand Up @@ -1721,6 +1732,9 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Protocol(
swift::remote::RemoteAddress remote_existential(existential_address);

ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
if (!reflection_ctx)
return false;

auto pair = reflection_ctx->ProjectExistentialAndUnwrapClass(
remote_existential, *protocol_typeref,
tss->GetTypeSystemSwiftTypeRef().GetDescriptorFinder());
Expand Down Expand Up @@ -2184,22 +2198,23 @@ SwiftLanguageRuntimeImpl::GetValueType(ValueObject &in_value,
// Read the value witness table and check if the data is inlined in
// the existential container or not.
swift::remote::RemoteAddress remote_existential(existential_address);
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext();
llvm::Optional<bool> is_inlined =
reflection_ctx->IsValueInlinedInExistentialContainer(
remote_existential);

if (use_local_buffer)
PopLocalBuffer();

// An error has occurred when trying to read value witness table,
// default to treating it as pointer.
if (!is_inlined.has_value())
return Value::ValueType::LoadAddress;

// Inlined data, same as static data.
if (*is_inlined)
return static_value_type;
if (ThreadSafeReflectionContext reflection_ctx = GetReflectionContext()) {
llvm::Optional<bool> is_inlined =
reflection_ctx->IsValueInlinedInExistentialContainer(
remote_existential);

if (use_local_buffer)
PopLocalBuffer();

// An error has occurred when trying to read value witness table,
// default to treating it as pointer.
if (!is_inlined.has_value())
return Value::ValueType::LoadAddress;

// Inlined data, same as static data.
if (*is_inlined)
return static_value_type;
}

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