Skip to content

Change GetChildCompilerTypeAtIndex to return Expected (NFC) #92979

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
May 22, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lldb/include/lldb/Symbol/CompilerType.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ class CompilerType {
uint32_t *bitfield_bit_size_ptr = nullptr,
bool *is_bitfield_ptr = nullptr) const;

CompilerType GetChildCompilerTypeAtIndex(
llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
bool omit_empty_base_classes, bool ignore_array_bounds,
std::string &child_name, uint32_t &child_byte_size,
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Symbol/TypeSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class TypeSystem : public PluginInterface,
return CompilerDecl();
}

virtual CompilerType GetChildCompilerTypeAtIndex(
virtual llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
bool transparent_pointers, bool omit_empty_base_classes,
bool ignore_array_bounds, std::string &child_name,
Expand Down
31 changes: 23 additions & 8 deletions lldb/source/Core/ValueObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,23 @@ ValueObject *ValueObject::CreateChildAtIndex(size_t idx,
uint64_t language_flags = 0;

const bool transparent_pointers = !synthetic_array_member;
CompilerType child_compiler_type;

ExecutionContext exe_ctx(GetExecutionContextRef());

child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex(
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
child_is_deref_of_parent, this, language_flags);
auto child_compiler_type_or_err =
GetCompilerType().GetChildCompilerTypeAtIndex(
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
ignore_array_bounds, child_name_str, child_byte_size,
child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset,
child_is_base_class, child_is_deref_of_parent, this, language_flags);
CompilerType child_compiler_type;
if (!child_compiler_type_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
child_compiler_type_or_err.takeError(),
"could not find child: {0}");
else
child_compiler_type = *child_compiler_type_or_err;

if (child_compiler_type) {
if (synthetic_index)
child_byte_offset += child_byte_size * synthetic_index;
Expand Down Expand Up @@ -2624,16 +2632,23 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
bool child_is_deref_of_parent = false;
const bool transparent_pointers = false;
CompilerType compiler_type = GetCompilerType();
CompilerType child_compiler_type;
uint64_t language_flags = 0;

ExecutionContext exe_ctx(GetExecutionContextRef());

child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex(
CompilerType child_compiler_type;
auto child_compiler_type_or_err = compiler_type.GetChildCompilerTypeAtIndex(
&exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
child_is_deref_of_parent, this, language_flags);
if (!child_compiler_type_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
child_compiler_type_or_err.takeError(),
"could not find child: {0}");
else
child_compiler_type = *child_compiler_type_or_err;

if (child_compiler_type && child_byte_size) {
ConstString child_name;
if (!child_name_str.empty())
Expand Down
12 changes: 10 additions & 2 deletions lldb/source/Core/ValueObjectConstResultImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/Endian.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Scalar.h"

#include <string>
Expand Down Expand Up @@ -66,15 +68,21 @@ ValueObject *ValueObjectConstResultImpl::CreateChildAtIndex(

const bool transparent_pointers = !synthetic_array_member;
CompilerType compiler_type = m_impl_backend->GetCompilerType();
CompilerType child_compiler_type;

ExecutionContext exe_ctx(m_impl_backend->GetExecutionContextRef());

child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex(
auto child_compiler_type_or_err = compiler_type.GetChildCompilerTypeAtIndex(
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
child_is_deref_of_parent, m_impl_backend, language_flags);
CompilerType child_compiler_type;
if (!child_compiler_type_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
child_compiler_type_or_err.takeError(),
"could not find child: {0}");
else
child_compiler_type = *child_compiler_type_or_err;

// One might think we should check that the size of the children
// is always strictly positive, hence we could avoid creating a
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ class ReturnValueExtractor {
}

// get child
CompilerType GetChildType(uint32_t i, std::string &name, uint32_t &size) {
llvm::Expected<CompilerType> GetChildType(uint32_t i, std::string &name,
uint32_t &size) {
// GetChild constant inputs
const bool transparent_pointers = false;
const bool omit_empty_base_classes = true;
Expand Down
18 changes: 11 additions & 7 deletions lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Core/ValueObjectConstResult.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/TypeSystem.h"
Expand Down Expand Up @@ -105,13 +106,16 @@ class BlockPointerSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
bool child_is_deref_of_parent = false;
uint64_t language_flags = 0;

const CompilerType child_type =
m_block_struct_type.GetChildCompilerTypeAtIndex(
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
child_bitfield_bit_size, child_bitfield_bit_offset,
child_is_base_class, child_is_deref_of_parent, value_object,
language_flags);
auto child_type_or_err = m_block_struct_type.GetChildCompilerTypeAtIndex(
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
child_is_deref_of_parent, value_object, language_flags);
if (!child_type_or_err)
return ValueObjectConstResult::Create(
exe_ctx.GetBestExecutionContextScope(),
Status(child_type_or_err.takeError()));
CompilerType child_type = *child_type_or_err;

ValueObjectSP struct_pointer_sp =
m_backend.Cast(m_block_struct_type.GetPointerType());
Expand Down
14 changes: 7 additions & 7 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,13 @@ void lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetValueOffset(
bool child_is_base_class;
bool child_is_deref_of_parent;
uint64_t language_flags;
if (tree_node_type
.GetChildCompilerTypeAtIndex(
nullptr, 4, true, true, true, child_name, child_byte_size,
child_byte_offset, child_bitfield_bit_size,
child_bitfield_bit_offset, child_is_base_class,
child_is_deref_of_parent, nullptr, language_flags)
.IsValid())
auto child_type =
llvm::expectedToStdOptional(tree_node_type.GetChildCompilerTypeAtIndex(
nullptr, 4, true, true, true, child_name, child_byte_size,
child_byte_offset, child_bitfield_bit_size,
child_bitfield_bit_offset, child_is_base_class,
child_is_deref_of_parent, nullptr, language_flags));
if (child_type && child_type->IsValid())
m_skip_size = (uint32_t)child_byte_offset;
}
}
Expand Down
18 changes: 10 additions & 8 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6130,7 +6130,7 @@ uint32_t TypeSystemClang::GetNumPointeeChildren(clang::QualType type) {
return 0;
}

CompilerType TypeSystemClang::GetChildCompilerTypeAtIndex(
llvm::Expected<CompilerType> TypeSystemClang::GetChildCompilerTypeAtIndex(
lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
bool transparent_pointers, bool omit_empty_base_classes,
bool ignore_array_bounds, std::string &child_name,
Expand All @@ -6156,11 +6156,8 @@ CompilerType TypeSystemClang::GetChildCompilerTypeAtIndex(

auto num_children_or_err =
GetNumChildren(type, omit_empty_base_classes, exe_ctx);
if (!num_children_or_err) {
LLDB_LOG_ERRORV(GetLog(LLDBLog::Types), num_children_or_err.takeError(),
"{0}");
return {};
}
if (!num_children_or_err)
return num_children_or_err.takeError();

const bool idx_is_valid = idx < *num_children_or_err;
int32_t bit_offset;
Expand Down Expand Up @@ -6242,7 +6239,10 @@ CompilerType TypeSystemClang::GetChildCompilerTypeAtIndex(
std::optional<uint64_t> size =
base_class_clang_type.GetBitSize(get_exe_scope());
if (!size)
return {};
return llvm::make_error<llvm::StringError>(
"no size info for base class",
llvm::inconvertibleErrorCode());

uint64_t base_class_clang_type_bit_size = *size;

// Base classes bit sizes should be a multiple of 8 bits in size
Expand Down Expand Up @@ -6274,7 +6274,9 @@ CompilerType TypeSystemClang::GetChildCompilerTypeAtIndex(
std::optional<uint64_t> size =
field_clang_type.GetByteSize(get_exe_scope());
if (!size)
return {};
return llvm::make_error<llvm::StringError>(
"no size info for field", llvm::inconvertibleErrorCode());

child_byte_size = *size;
const uint32_t child_bit_size = child_byte_size * 8;

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ class TypeSystemClang : public TypeSystem {

static uint32_t GetNumPointeeChildren(clang::QualType type);

CompilerType GetChildCompilerTypeAtIndex(
llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
bool transparent_pointers, bool omit_empty_base_classes,
bool ignore_array_bounds, std::string &child_name,
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Symbol/CompilerType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ uint32_t CompilerType::GetIndexOfFieldWithName(
return UINT32_MAX;
}

CompilerType CompilerType::GetChildCompilerTypeAtIndex(
llvm::Expected<CompilerType> CompilerType::GetChildCompilerTypeAtIndex(
ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
bool omit_empty_base_classes, bool ignore_array_bounds,
std::string &child_name, uint32_t &child_byte_size,
Expand Down
Loading