Skip to content

Commit 06769af

Browse files
committed
Add a function GetDereferencedType instead.
1 parent 889900e commit 06769af

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;
@@ -441,6 +439,15 @@ class CompilerType {
441439
uint32_t *bitfield_bit_size_ptr = nullptr,
442440
bool *is_bitfield_ptr = nullptr) const;
443441

442+
llvm::Expected<CompilerType> GetDereferencedType(
443+
ExecutionContext *exe_ctx, bool transparent_pointers,
444+
bool omit_empty_base_classes, bool ignore_array_bounds,
445+
std::string &child_name, uint32_t &child_byte_size,
446+
int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size,
447+
uint32_t &child_bitfield_bit_offset, bool &child_is_base_class,
448+
bool &child_is_deref_of_parent, ValueObject *valobj,
449+
uint64_t &language_flags, bool &type_valid) const;
450+
444451
llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
445452
ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
446453
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,
@@ -494,8 +503,6 @@ class TypeSystem : public PluginInterface,
494503
virtual bool IsReferenceType(lldb::opaque_compiler_type_t type,
495504
CompilerType *pointee_type, bool *is_rvalue) = 0;
496505

497-
virtual bool IsValidDereferenceType(lldb::opaque_compiler_type_t type) = 0;
498-
499506
virtual bool
500507
ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type) {
501508
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())
@@ -919,6 +912,25 @@ uint32_t CompilerType::GetIndexOfFieldWithName(
919912
return UINT32_MAX;
920913
}
921914

915+
llvm::Expected<CompilerType> CompilerType::GetDereferencedType(
916+
ExecutionContext *exe_ctx, bool transparent_pointers,
917+
bool omit_empty_base_classes, bool ignore_array_bounds,
918+
std::string &child_name, uint32_t &child_byte_size,
919+
int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size,
920+
uint32_t &child_bitfield_bit_offset, bool &child_is_base_class,
921+
bool &child_is_deref_of_parent, ValueObject *valobj,
922+
uint64_t &language_flags, bool &type_valid) const {
923+
if (IsValid())
924+
if (auto type_system_sp = GetTypeSystem())
925+
return type_system_sp->GetDereferencedType(
926+
m_type, exe_ctx, transparent_pointers, omit_empty_base_classes,
927+
ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
928+
child_bitfield_bit_size, child_bitfield_bit_offset,
929+
child_is_base_class, child_is_deref_of_parent, valobj, language_flags,
930+
type_valid);
931+
return CompilerType();
932+
}
933+
922934
llvm::Expected<CompilerType> CompilerType::GetChildCompilerTypeAtIndex(
923935
ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
924936
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
@@ -2844,38 +2844,38 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
28442844
if (m_deref_valobj)
28452845
return m_deref_valobj->GetSP();
28462846

2847-
const bool is_valid_dereference_type =
2848-
GetCompilerType().IsValidDereferenceType();
2849-
if (is_valid_dereference_type) {
2850-
bool omit_empty_base_classes = true;
2851-
bool ignore_array_bounds = false;
2852-
2853-
std::string child_name_str;
2854-
uint32_t child_byte_size = 0;
2855-
int32_t child_byte_offset = 0;
2856-
uint32_t child_bitfield_bit_size = 0;
2857-
uint32_t child_bitfield_bit_offset = 0;
2858-
bool child_is_base_class = false;
2859-
bool child_is_deref_of_parent = false;
2860-
const bool transparent_pointers = false;
2861-
CompilerType compiler_type = GetCompilerType();
2862-
uint64_t language_flags = 0;
2847+
bool omit_empty_base_classes = true;
2848+
bool ignore_array_bounds = false;
2849+
std::string child_name_str;
2850+
uint32_t child_byte_size = 0;
2851+
int32_t child_byte_offset = 0;
2852+
uint32_t child_bitfield_bit_size = 0;
2853+
uint32_t child_bitfield_bit_offset = 0;
2854+
bool child_is_base_class = false;
2855+
bool child_is_deref_of_parent = false;
2856+
const bool transparent_pointers = false;
2857+
CompilerType compiler_type = GetCompilerType();
2858+
uint64_t language_flags = 0;
2859+
bool is_valid_dereference_type = false;
28632860

2864-
ExecutionContext exe_ctx(GetExecutionContextRef());
2861+
ExecutionContext exe_ctx(GetExecutionContextRef());
28652862

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

2871+
if (!child_compiler_type_or_err && is_valid_dereference_type)
2872+
LLDB_LOG_ERROR(GetLog(LLDBLog::Types),
2873+
child_compiler_type_or_err.takeError(),
2874+
"could not find child: {0}");
2875+
else
2876+
child_compiler_type = *child_compiler_type_or_err;
2877+
2878+
if (is_valid_dereference_type) {
28792879
if (child_compiler_type && child_byte_size) {
28802880
ConstString child_name;
28812881
if (!child_name_str.empty())
@@ -2910,7 +2910,6 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
29102910
}
29112911
}
29122912
}
2913-
29142913
} else if (HasSyntheticValue()) {
29152914
m_deref_valobj =
29162915
GetSyntheticValue()->GetChildMemberWithName("$$dereference$$").get();

0 commit comments

Comments
 (0)