Skip to content

Commit ca45436

Browse files
committed
Add a function GetDereferencedType instead.
1 parent 08834d4 commit ca45436

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,
@@ -486,8 +495,6 @@ class TypeSystem : public PluginInterface,
486495
virtual bool IsReferenceType(lldb::opaque_compiler_type_t type,
487496
CompilerType *pointee_type, bool *is_rvalue) = 0;
488497

489-
virtual bool IsValidDereferenceType(lldb::opaque_compiler_type_t type) = 0;
490-
491498
virtual bool
492499
ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type) {
493500
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) {
@@ -6208,6 +6201,25 @@ uint32_t TypeSystemClang::GetNumPointeeChildren(clang::QualType type) {
62086201
return 0;
62096202
}
62106203

6204+
llvm::Expected<CompilerType> TypeSystemClang::GetDereferencedType(
6205+
lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
6206+
bool transparent_pointers, bool omit_empty_base_classes,
6207+
bool ignore_array_bounds, std::string &child_name,
6208+
uint32_t &child_byte_size, int32_t &child_byte_offset,
6209+
uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
6210+
bool &child_is_base_class, bool &child_is_deref_of_parent,
6211+
ValueObject *valobj, uint64_t &language_flags, bool &type_valid) {
6212+
type_valid = IsPointerOrReferenceType(type, nullptr) ||
6213+
IsArrayType(type, nullptr, nullptr, nullptr);
6214+
if (!type_valid)
6215+
return CompilerType();
6216+
return GetChildCompilerTypeAtIndex(
6217+
type, exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
6218+
ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
6219+
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
6220+
child_is_deref_of_parent, valobj, language_flags);
6221+
}
6222+
62116223
llvm::Expected<CompilerType> TypeSystemClang::GetChildCompilerTypeAtIndex(
62126224
lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
62136225
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
@@ -2850,38 +2850,38 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
28502850
if (m_deref_valobj)
28512851
return m_deref_valobj->GetSP();
28522852

2853-
const bool is_valid_dereference_type =
2854-
GetCompilerType().IsValidDereferenceType();
2855-
if (is_valid_dereference_type) {
2856-
bool omit_empty_base_classes = true;
2857-
bool ignore_array_bounds = false;
2858-
2859-
std::string child_name_str;
2860-
uint32_t child_byte_size = 0;
2861-
int32_t child_byte_offset = 0;
2862-
uint32_t child_bitfield_bit_size = 0;
2863-
uint32_t child_bitfield_bit_offset = 0;
2864-
bool child_is_base_class = false;
2865-
bool child_is_deref_of_parent = false;
2866-
const bool transparent_pointers = false;
2867-
CompilerType compiler_type = GetCompilerType();
2868-
uint64_t language_flags = 0;
2853+
bool omit_empty_base_classes = true;
2854+
bool ignore_array_bounds = false;
2855+
std::string child_name_str;
2856+
uint32_t child_byte_size = 0;
2857+
int32_t child_byte_offset = 0;
2858+
uint32_t child_bitfield_bit_size = 0;
2859+
uint32_t child_bitfield_bit_offset = 0;
2860+
bool child_is_base_class = false;
2861+
bool child_is_deref_of_parent = false;
2862+
const bool transparent_pointers = false;
2863+
CompilerType compiler_type = GetCompilerType();
2864+
uint64_t language_flags = 0;
2865+
bool is_valid_dereference_type = false;
28692866

2870-
ExecutionContext exe_ctx(GetExecutionContextRef());
2867+
ExecutionContext exe_ctx(GetExecutionContextRef());
28712868

2872-
CompilerType child_compiler_type;
2873-
auto child_compiler_type_or_err = compiler_type.GetChildCompilerTypeAtIndex(
2874-
&exe_ctx, 0, transparent_pointers, omit_empty_base_classes,
2875-
ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
2876-
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
2877-
child_is_deref_of_parent, this, language_flags);
2878-
if (!child_compiler_type_or_err)
2879-
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
2880-
child_compiler_type_or_err.takeError(),
2881-
"could not find child: {0}");
2882-
else
2883-
child_compiler_type = *child_compiler_type_or_err;
2869+
CompilerType child_compiler_type;
2870+
auto child_compiler_type_or_err = compiler_type.GetDereferencedType(
2871+
&exe_ctx, transparent_pointers, omit_empty_base_classes,
2872+
ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset,
2873+
child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
2874+
child_is_deref_of_parent, this, language_flags,
2875+
is_valid_dereference_type);
28842876

2877+
if (!child_compiler_type_or_err && is_valid_dereference_type)
2878+
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
2879+
child_compiler_type_or_err.takeError(),
2880+
"could not find child: {0}");
2881+
else
2882+
child_compiler_type = *child_compiler_type_or_err;
2883+
2884+
if (is_valid_dereference_type) {
28852885
if (child_compiler_type && child_byte_size) {
28862886
ConstString child_name;
28872887
if (!child_name_str.empty())
@@ -2916,7 +2916,6 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
29162916
}
29172917
}
29182918
}
2919-
29202919
} else if (HasSyntheticValue()) {
29212920
m_deref_valobj =
29222921
GetSyntheticValue()->GetChildMemberWithName("$$dereference$$").get();

0 commit comments

Comments
 (0)