Skip to content

Commit 7d3ebcc

Browse files
committed
Add a function GetDereferencedType instead.
1 parent b49356d commit 7d3ebcc

File tree

6 files changed

+94
-50
lines changed

6 files changed

+94
-50
lines changed

lldb/include/lldb/Symbol/CompilerType.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ class CompilerType {
186186
bool IsReferenceType(CompilerType *pointee_type = nullptr,
187187
bool *is_rvalue = nullptr) const;
188188

189-
bool IsValidDereferenceType() const;
190-
191189
bool ShouldTreatScalarValueAsAddress() const;
192190

193191
bool IsScalarType() const;
@@ -435,6 +433,15 @@ class CompilerType {
435433

436434
CompilerDecl GetStaticFieldWithName(llvm::StringRef name) const;
437435

436+
llvm::Expected<CompilerType> GetDereferencedType(
437+
ExecutionContext *exe_ctx, bool transparent_pointers,
438+
bool omit_empty_base_classes, bool ignore_array_bounds,
439+
std::string &child_name, uint32_t &child_byte_size,
440+
int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size,
441+
uint32_t &child_bitfield_bit_offset, bool &child_is_base_class,
442+
bool &child_is_deref_of_parent, ValueObject *valobj,
443+
uint64_t &language_flags, bool &type_valid) const;
444+
438445
llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
439446
ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
440447
bool omit_empty_base_classes, bool ignore_array_bounds,

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,15 @@ class TypeSystem : public PluginInterface,
364364
return CompilerDecl();
365365
}
366366

367+
virtual llvm::Expected<CompilerType> GetDereferencedType(
368+
lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
369+
bool transparent_pointers, bool omit_empty_base_classes,
370+
bool ignore_array_bounds, std::string &child_name,
371+
uint32_t &child_byte_size, int32_t &child_byte_offset,
372+
uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
373+
bool &child_is_base_class, bool &child_is_deref_of_parent,
374+
ValueObject *valobj, uint64_t &language_flags, bool &type_valid) = 0;
375+
367376
virtual llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
368377
lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
369378
bool transparent_pointers, bool omit_empty_base_classes,
@@ -489,8 +498,6 @@ class TypeSystem : public PluginInterface,
489498
virtual bool IsReferenceType(lldb::opaque_compiler_type_t type,
490499
CompilerType *pointee_type, bool *is_rvalue) = 0;
491500

492-
virtual bool IsValidDereferenceType(lldb::opaque_compiler_type_t type) = 0;
493-
494501
virtual bool
495502
ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type) {
496503
return IsPointerOrReferenceType(type, nullptr);

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,13 +3443,6 @@ bool TypeSystemClang::IsReferenceType(lldb::opaque_compiler_type_t type,
34433443
return false;
34443444
}
34453445

3446-
bool TypeSystemClang::IsValidDereferenceType(
3447-
lldb::opaque_compiler_type_t type) {
3448-
CompilerType compiler_type = GetType(clang::QualType::getFromOpaquePtr(type));
3449-
return compiler_type.IsPointerOrReferenceType() ||
3450-
compiler_type.IsArrayType();
3451-
}
3452-
34533446
bool TypeSystemClang::IsFloatingPointType(lldb::opaque_compiler_type_t type,
34543447
uint32_t &count, bool &is_complex) {
34553448
if (type) {
@@ -6191,6 +6184,25 @@ uint32_t TypeSystemClang::GetNumPointeeChildren(clang::QualType type) {
61916184
return 0;
61926185
}
61936186

6187+
llvm::Expected<CompilerType> TypeSystemClang::GetDereferencedType(
6188+
lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
6189+
bool transparent_pointers, bool omit_empty_base_classes,
6190+
bool ignore_array_bounds, std::string &child_name,
6191+
uint32_t &child_byte_size, int32_t &child_byte_offset,
6192+
uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
6193+
bool &child_is_base_class, bool &child_is_deref_of_parent,
6194+
ValueObject *valobj, uint64_t &language_flags, bool &type_valid) {
6195+
type_valid = IsPointerOrReferenceType(type, nullptr) ||
6196+
IsArrayType(type, nullptr, nullptr, nullptr);
6197+
if (!type_valid)
6198+
return CompilerType();
6199+
return GetChildCompilerTypeAtIndex(
6200+
type, exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
6201+
ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6202+
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
6203+
child_is_deref_of_parent, valobj, language_flags);
6204+
}
6205+
61946206
llvm::Expected<CompilerType> TypeSystemClang::GetChildCompilerTypeAtIndex(
61956207
lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
61966208
bool transparent_pointers, bool omit_empty_base_classes,

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,6 @@ class TypeSystemClang : public TypeSystem {
716716
bool IsReferenceType(lldb::opaque_compiler_type_t type,
717717
CompilerType *pointee_type, bool *is_rvalue) override;
718718

719-
bool IsValidDereferenceType(lldb::opaque_compiler_type_t type) override;
720-
721719
bool IsScalarType(lldb::opaque_compiler_type_t type) override;
722720

723721
bool IsTypedefType(lldb::opaque_compiler_type_t type) override;
@@ -891,6 +889,15 @@ class TypeSystemClang : public TypeSystem {
891889

892890
static uint32_t GetNumPointeeChildren(clang::QualType type);
893891

892+
llvm::Expected<CompilerType> GetDereferencedType(
893+
lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
894+
bool transparent_pointers, bool omit_empty_base_classes,
895+
bool ignore_array_bounds, std::string &child_name,
896+
uint32_t &child_byte_size, int32_t &child_byte_offset,
897+
uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
898+
bool &child_is_base_class, bool &child_is_deref_of_parent,
899+
ValueObject *valobj, uint64_t &language_flags, bool &type_valid) override;
900+
894901
llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
895902
lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
896903
bool transparent_pointers, bool omit_empty_base_classes,

lldb/source/Symbol/CompilerType.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,6 @@ bool CompilerType::IsReferenceType(CompilerType *pointee_type,
233233
return false;
234234
}
235235

236-
bool CompilerType::IsValidDereferenceType() const {
237-
if (IsValid())
238-
if (auto type_system_sp = GetTypeSystem())
239-
return type_system_sp->IsValidDereferenceType(m_type);
240-
return false;
241-
}
242-
243236
bool CompilerType::ShouldTreatScalarValueAsAddress() const {
244237
if (IsValid())
245238
if (auto type_system_sp = GetTypeSystem())
@@ -900,6 +893,25 @@ CompilerDecl CompilerType::GetStaticFieldWithName(llvm::StringRef name) const {
900893
return CompilerDecl();
901894
}
902895

896+
llvm::Expected<CompilerType> CompilerType::GetDereferencedType(
897+
ExecutionContext *exe_ctx, bool transparent_pointers,
898+
bool omit_empty_base_classes, bool ignore_array_bounds,
899+
std::string &child_name, uint32_t &child_byte_size,
900+
int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size,
901+
uint32_t &child_bitfield_bit_offset, bool &child_is_base_class,
902+
bool &child_is_deref_of_parent, ValueObject *valobj,
903+
uint64_t &language_flags, bool &type_valid) const {
904+
if (IsValid())
905+
if (auto type_system_sp = GetTypeSystem())
906+
return type_system_sp->GetDereferencedType(
907+
m_type, exe_ctx, transparent_pointers, omit_empty_base_classes,
908+
ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
909+
child_bitfield_bit_size, child_bitfield_bit_offset,
910+
child_is_base_class, child_is_deref_of_parent, valobj, language_flags,
911+
type_valid);
912+
return CompilerType();
913+
}
914+
903915
llvm::Expected<CompilerType> CompilerType::GetChildCompilerTypeAtIndex(
904916
ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
905917
bool omit_empty_base_classes, bool ignore_array_bounds,

lldb/source/ValueObject/ValueObject.cpp

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,38 +2794,38 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
27942794
if (m_deref_valobj)
27952795
return m_deref_valobj->GetSP();
27962796

2797-
const bool is_valid_dereference_type =
2798-
GetCompilerType().IsValidDereferenceType();
2799-
if (is_valid_dereference_type) {
2800-
bool omit_empty_base_classes = true;
2801-
bool ignore_array_bounds = false;
2802-
2803-
std::string child_name_str;
2804-
uint32_t child_byte_size = 0;
2805-
int32_t child_byte_offset = 0;
2806-
uint32_t child_bitfield_bit_size = 0;
2807-
uint32_t child_bitfield_bit_offset = 0;
2808-
bool child_is_base_class = false;
2809-
bool child_is_deref_of_parent = false;
2810-
const bool transparent_pointers = false;
2811-
CompilerType compiler_type = GetCompilerType();
2812-
uint64_t language_flags = 0;
2797+
bool omit_empty_base_classes = true;
2798+
bool ignore_array_bounds = false;
2799+
std::string child_name_str;
2800+
uint32_t child_byte_size = 0;
2801+
int32_t child_byte_offset = 0;
2802+
uint32_t child_bitfield_bit_size = 0;
2803+
uint32_t child_bitfield_bit_offset = 0;
2804+
bool child_is_base_class = false;
2805+
bool child_is_deref_of_parent = false;
2806+
const bool transparent_pointers = false;
2807+
CompilerType compiler_type = GetCompilerType();
2808+
uint64_t language_flags = 0;
2809+
bool is_valid_dereference_type = false;
28132810

2814-
ExecutionContext exe_ctx(GetExecutionContextRef());
2811+
ExecutionContext exe_ctx(GetExecutionContextRef());
28152812

2816-
CompilerType child_compiler_type;
2817-
auto child_compiler_type_or_err = compiler_type.GetChildCompilerTypeAtIndex(
2818-
&exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
2819-
ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
2820-
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
2821-
child_is_deref_of_parent, this, language_flags);
2822-
if (!child_compiler_type_or_err)
2823-
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
2824-
child_compiler_type_or_err.takeError(),
2825-
"could not find child: {0}");
2826-
else
2827-
child_compiler_type = *child_compiler_type_or_err;
2813+
CompilerType child_compiler_type;
2814+
auto child_compiler_type_or_err = compiler_type.GetDereferencedType(
2815+
&exe_ctx, transparent_pointers, omit_empty_base_classes,
2816+
ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
2817+
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
2818+
child_is_deref_of_parent, this, language_flags,
2819+
is_valid_dereference_type);
28282820

2821+
if (!child_compiler_type_or_err && is_valid_dereference_type)
2822+
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
2823+
child_compiler_type_or_err.takeError(),
2824+
"could not find child: {0}");
2825+
else
2826+
child_compiler_type = *child_compiler_type_or_err;
2827+
2828+
if (is_valid_dereference_type) {
28292829
if (child_compiler_type && child_byte_size) {
28302830
ConstString child_name;
28312831
if (!child_name_str.empty())
@@ -2860,7 +2860,6 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
28602860
}
28612861
}
28622862
}
2863-
28642863
} else if (IsSynthetic()) {
28652864
m_deref_valobj = GetChildMemberWithName("$$dereference$$").get();
28662865
}

0 commit comments

Comments
 (0)