Skip to content

Add error handling to GetChildCompilerTypeAtIndex() #8793

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 2 commits into from
May 23, 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 @@ -381,7 +381,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 @@ -362,7 +362,7 @@ class TypeSystem : public PluginInterface,
GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx,
uint32_t *bit_offset_ptr) = 0;

virtual CompilerType GetChildCompilerTypeAtIndex(
virtual llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you upstreaming these changes to the generic code?

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 @@ -600,15 +600,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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extreme bikeshed, but I'd switch the success case to be first

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 @@ -2735,16 +2743,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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also very inconsequential, but I'd but this closer to the "if" below

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
9 changes: 8 additions & 1 deletion lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,18 @@ static bool ExtractBytesFromRegisters(
bool child_is_base_class = false;
bool child_is_deref_of_parent = false;
uint64_t language_flags;
CompilerType field_clang_type = clang_type.GetChildCompilerTypeAtIndex(
CompilerType field_clang_type;
auto field_clang_type_or_err = clang_type.GetChildCompilerTypeAtIndex(
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
ignore_array_bounds, 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 (!field_clang_type_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
field_clang_type_or_err.takeError(),
"could not find child #{1}: {0}", idx);
else
field_clang_type = *field_clang_type_or_err;

const uint64_t field_bit_offset = child_byte_offset * 8;
const size_t field_bit_width =
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
Original file line number Diff line number Diff line change
Expand Up @@ -1670,12 +1670,17 @@ class ProjectionSyntheticChildren : public SyntheticChildren {
uint32_t child_bitfield_bit_offset;
uint64_t language_flags;

type = parent_type.GetChildCompilerTypeAtIndex(
auto type_or_err = parent_type.GetChildCompilerTypeAtIndex(
exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
ignore_array_bounds, child_name, child_byte_size, byte_offset,
child_bitfield_bit_size, child_bitfield_bit_offset,
child_is_base_class, child_is_deref_of_parent, valobj,
language_flags);
if (!type_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Types), type_or_err.takeError(),
"could not find child #{1}: {0}", idx);
else
type = *type_or_err;

if (child_is_base_class)
type.Clear(); // invalidate - base classes are dealt with outside of the
Expand Down Expand Up @@ -2445,7 +2450,7 @@ SwiftLanguageRuntime::GetIndexOfChildMemberWithName(
omit_empty_base_classes, child_indexes);
}

CompilerType SwiftLanguageRuntime::GetChildCompilerTypeAtIndex(
llvm::Expected<CompilerType> SwiftLanguageRuntime::GetChildCompilerTypeAtIndex(
CompilerType type, 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
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class SwiftLanguageRuntime : public LanguageRuntime {
std::vector<uint32_t> &child_indexes);

/// Ask Remote Mirrors about a child of a composite type.
CompilerType GetChildCompilerTypeAtIndex(
llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
CompilerType type, 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