Skip to content

[lldb] Adapt error handling API in ReflectionContext. #10843

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
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
25 changes: 12 additions & 13 deletions lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ class TargetReflectionContext : public ReflectionContextInterface {
std::shared_ptr<swift::reflection::MemoryReader> reader,
SwiftMetadataCache *swift_metadata_cache)
: m_reflection_ctx(reader, swift_metadata_cache, &m_forwader),
m_type_converter(m_reflection_ctx.getBuilder()) {}
m_type_converter(m_reflection_ctx.getBuilder()) {
m_type_converter.enableErrorCache();
}

std::optional<uint32_t> AddImage(
llvm::function_ref<std::pair<swift::remote::RemoteRef<void>, uint64_t>(
Expand Down Expand Up @@ -180,8 +182,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
auto *rti =
m_type_converter.getClassInstanceTypeInfo(&type_ref, *start, provider);
if (!rti)
return llvm::createStringError(
"converter returned nullptr typeinfo but no error");
return llvm::createStringError(m_type_converter.takeLastError());
return *rti;
}

Expand All @@ -201,23 +202,21 @@ class TargetReflectionContext : public ReflectionContextInterface {
provider ? provider->getId() : 0, ss.str());
}

auto type_info = m_reflection_ctx.getTypeInfo(&type_ref, provider);
if (!type_info) {
std::stringstream ss;
ss << "Could not find type info for ";
type_ref.dump(ss);
ss << " in reflection metadata";
return llvm::createStringError(ss.str());
}
auto type_info_or_err = m_reflection_ctx.getTypeInfo(type_ref, provider);
if (!type_info_or_err)
return llvm::joinErrors(
llvm::createStringError(
"Could not find reflection metadata for type"),
type_info_or_err.takeError());

if (log && log->GetVerbose()) {
std::stringstream ss;
type_info->dump(ss);
type_info_or_err->dump(ss);
LLDB_LOG(log,
"[TargetReflectionContext::getTypeInfo] Found type info {0}",
ss.str());
}
return *type_info;
return *type_info_or_err;
}

llvm::Expected<const swift::reflection::TypeInfo &> GetTypeInfoFromInstance(
Expand Down