Skip to content

Commit 04fb099

Browse files
Merge pull request #8793 from adrian-prantl/128284599
Add error handling to GetChildCompilerTypeAtIndex()
2 parents 6c5891d + cc6b62c commit 04fb099

19 files changed

+368
-231
lines changed

lldb/include/lldb/Symbol/CompilerType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ class CompilerType {
381381
uint32_t *bitfield_bit_size_ptr = nullptr,
382382
bool *is_bitfield_ptr = nullptr) const;
383383

384-
CompilerType GetChildCompilerTypeAtIndex(
384+
llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
385385
ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
386386
bool omit_empty_base_classes, bool ignore_array_bounds,
387387
std::string &child_name, uint32_t &child_byte_size,

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class TypeSystem : public PluginInterface,
362362
GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx,
363363
uint32_t *bit_offset_ptr) = 0;
364364

365-
virtual CompilerType GetChildCompilerTypeAtIndex(
365+
virtual llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
366366
lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
367367
bool transparent_pointers, bool omit_empty_base_classes,
368368
bool ignore_array_bounds, std::string &child_name,

lldb/source/Core/ValueObject.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -600,15 +600,23 @@ ValueObject *ValueObject::CreateChildAtIndex(size_t idx,
600600
uint64_t language_flags = 0;
601601

602602
const bool transparent_pointers = !synthetic_array_member;
603-
CompilerType child_compiler_type;
604603

605604
ExecutionContext exe_ctx(GetExecutionContextRef());
606605

607-
child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex(
608-
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
609-
ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
610-
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
611-
child_is_deref_of_parent, this, language_flags);
606+
auto child_compiler_type_or_err =
607+
GetCompilerType().GetChildCompilerTypeAtIndex(
608+
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
609+
ignore_array_bounds, child_name_str, child_byte_size,
610+
child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset,
611+
child_is_base_class, child_is_deref_of_parent, this, language_flags);
612+
CompilerType child_compiler_type;
613+
if (!child_compiler_type_or_err)
614+
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
615+
child_compiler_type_or_err.takeError(),
616+
"could not find child: {0}");
617+
else
618+
child_compiler_type = *child_compiler_type_or_err;
619+
612620
if (child_compiler_type) {
613621
if (synthetic_index)
614622
child_byte_offset += child_byte_size * synthetic_index;
@@ -2735,16 +2743,23 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
27352743
bool child_is_deref_of_parent = false;
27362744
const bool transparent_pointers = false;
27372745
CompilerType compiler_type = GetCompilerType();
2738-
CompilerType child_compiler_type;
27392746
uint64_t language_flags = 0;
27402747

27412748
ExecutionContext exe_ctx(GetExecutionContextRef());
27422749

2743-
child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex(
2750+
CompilerType child_compiler_type;
2751+
auto child_compiler_type_or_err = compiler_type.GetChildCompilerTypeAtIndex(
27442752
&exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
27452753
ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
27462754
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
27472755
child_is_deref_of_parent, this, language_flags);
2756+
if (!child_compiler_type_or_err)
2757+
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
2758+
child_compiler_type_or_err.takeError(),
2759+
"could not find child: {0}");
2760+
else
2761+
child_compiler_type = *child_compiler_type_or_err;
2762+
27482763
if (child_compiler_type && child_byte_size) {
27492764
ConstString child_name;
27502765
if (!child_name_str.empty())

lldb/source/Core/ValueObjectConstResultImpl.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "lldb/Target/ExecutionContext.h"
1818
#include "lldb/Utility/DataBufferHeap.h"
1919
#include "lldb/Utility/Endian.h"
20+
#include "lldb/Utility/LLDBLog.h"
21+
#include "lldb/Utility/Log.h"
2022
#include "lldb/Utility/Scalar.h"
2123

2224
#include <string>
@@ -66,15 +68,21 @@ ValueObject *ValueObjectConstResultImpl::CreateChildAtIndex(
6668

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

7172
ExecutionContext exe_ctx(m_impl_backend->GetExecutionContextRef());
7273

73-
child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex(
74+
auto child_compiler_type_or_err = compiler_type.GetChildCompilerTypeAtIndex(
7475
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
7576
ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
7677
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
7778
child_is_deref_of_parent, m_impl_backend, language_flags);
79+
CompilerType child_compiler_type;
80+
if (!child_compiler_type_or_err)
81+
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
82+
child_compiler_type_or_err.takeError(),
83+
"could not find child: {0}");
84+
else
85+
child_compiler_type = *child_compiler_type_or_err;
7886

7987
// One might think we should check that the size of the children
8088
// is always strictly positive, hence we could avoid creating a

lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,8 @@ class ReturnValueExtractor {
903903
}
904904

905905
// get child
906-
CompilerType GetChildType(uint32_t i, std::string &name, uint32_t &size) {
906+
llvm::Expected<CompilerType> GetChildType(uint32_t i, std::string &name,
907+
uint32_t &size) {
907908
// GetChild constant inputs
908909
const bool transparent_pointers = false;
909910
const bool omit_empty_base_classes = true;

lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,18 @@ static bool ExtractBytesFromRegisters(
591591
bool child_is_base_class = false;
592592
bool child_is_deref_of_parent = false;
593593
uint64_t language_flags;
594-
CompilerType field_clang_type = clang_type.GetChildCompilerTypeAtIndex(
594+
CompilerType field_clang_type;
595+
auto field_clang_type_or_err = clang_type.GetChildCompilerTypeAtIndex(
595596
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
596597
ignore_array_bounds, name, child_byte_size, child_byte_offset,
597598
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
598599
child_is_deref_of_parent, nullptr, language_flags);
600+
if (!field_clang_type_or_err)
601+
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
602+
field_clang_type_or_err.takeError(),
603+
"could not find child #{1}: {0}", idx);
604+
else
605+
field_clang_type = *field_clang_type_or_err;
599606

600607
const uint64_t field_bit_offset = child_byte_offset * 8;
601608
const size_t field_bit_width =

lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
1313
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
1414
#include "lldb/Core/ValueObject.h"
15+
#include "lldb/Core/ValueObjectConstResult.h"
1516
#include "lldb/DataFormatters/FormattersHelpers.h"
1617
#include "lldb/Symbol/CompilerType.h"
1718
#include "lldb/Symbol/TypeSystem.h"
@@ -105,13 +106,16 @@ class BlockPointerSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
105106
bool child_is_deref_of_parent = false;
106107
uint64_t language_flags = 0;
107108

108-
const CompilerType child_type =
109-
m_block_struct_type.GetChildCompilerTypeAtIndex(
110-
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
111-
ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
112-
child_bitfield_bit_size, child_bitfield_bit_offset,
113-
child_is_base_class, child_is_deref_of_parent, value_object,
114-
language_flags);
109+
auto child_type_or_err = m_block_struct_type.GetChildCompilerTypeAtIndex(
110+
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
111+
ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
112+
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
113+
child_is_deref_of_parent, value_object, language_flags);
114+
if (!child_type_or_err)
115+
return ValueObjectConstResult::Create(
116+
exe_ctx.GetBestExecutionContextScope(),
117+
Status(child_type_or_err.takeError()));
118+
CompilerType child_type = *child_type_or_err;
115119

116120
ValueObjectSP struct_pointer_sp =
117121
m_backend.Cast(m_block_struct_type.GetPointerType());

lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,13 @@ void lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetValueOffset(
295295
bool child_is_base_class;
296296
bool child_is_deref_of_parent;
297297
uint64_t language_flags;
298-
if (tree_node_type
299-
.GetChildCompilerTypeAtIndex(
300-
nullptr, 4, true, true, true, child_name, child_byte_size,
301-
child_byte_offset, child_bitfield_bit_size,
302-
child_bitfield_bit_offset, child_is_base_class,
303-
child_is_deref_of_parent, nullptr, language_flags)
304-
.IsValid())
298+
auto child_type =
299+
llvm::expectedToStdOptional(tree_node_type.GetChildCompilerTypeAtIndex(
300+
nullptr, 4, true, true, true, child_name, child_byte_size,
301+
child_byte_offset, child_bitfield_bit_size,
302+
child_bitfield_bit_offset, child_is_base_class,
303+
child_is_deref_of_parent, nullptr, language_flags));
304+
if (child_type && child_type->IsValid())
305305
m_skip_size = (uint32_t)child_byte_offset;
306306
}
307307
}

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,12 +1670,17 @@ class ProjectionSyntheticChildren : public SyntheticChildren {
16701670
uint32_t child_bitfield_bit_offset;
16711671
uint64_t language_flags;
16721672

1673-
type = parent_type.GetChildCompilerTypeAtIndex(
1673+
auto type_or_err = parent_type.GetChildCompilerTypeAtIndex(
16741674
exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
16751675
ignore_array_bounds, child_name, child_byte_size, byte_offset,
16761676
child_bitfield_bit_size, child_bitfield_bit_offset,
16771677
child_is_base_class, child_is_deref_of_parent, valobj,
16781678
language_flags);
1679+
if (!type_or_err)
1680+
LLDB_LOG_ERROR(GetLog(LLDBLog::Types), type_or_err.takeError(),
1681+
"could not find child #{1}: {0}", idx);
1682+
else
1683+
type = *type_or_err;
16791684

16801685
if (child_is_base_class)
16811686
type.Clear(); // invalidate - base classes are dealt with outside of the
@@ -2445,7 +2450,7 @@ SwiftLanguageRuntime::GetIndexOfChildMemberWithName(
24452450
omit_empty_base_classes, child_indexes);
24462451
}
24472452

2448-
CompilerType SwiftLanguageRuntime::GetChildCompilerTypeAtIndex(
2453+
llvm::Expected<CompilerType> SwiftLanguageRuntime::GetChildCompilerTypeAtIndex(
24492454
CompilerType type, size_t idx, bool transparent_pointers,
24502455
bool omit_empty_base_classes, bool ignore_array_bounds,
24512456
std::string &child_name, uint32_t &child_byte_size,

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class SwiftLanguageRuntime : public LanguageRuntime {
356356
std::vector<uint32_t> &child_indexes);
357357

358358
/// Ask Remote Mirrors about a child of a composite type.
359-
CompilerType GetChildCompilerTypeAtIndex(
359+
llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
360360
CompilerType type, size_t idx, bool transparent_pointers,
361361
bool omit_empty_base_classes, bool ignore_array_bounds,
362362
std::string &child_name, uint32_t &child_byte_size,

0 commit comments

Comments
 (0)