Skip to content

Commit 889900e

Browse files
committed
[lldb][TypeSystemClang] Add a function IsValidDereferenceType to TypeSystem to allow arrays to be dereferenced in C/C++.
1 parent 3192ecf commit 889900e

File tree

6 files changed

+26
-3
lines changed

6 files changed

+26
-3
lines changed

lldb/include/lldb/Symbol/CompilerType.h

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

189+
bool IsValidDereferenceType() const;
190+
189191
bool ShouldTreatScalarValueAsAddress() const;
190192

191193
bool IsScalarType() const;

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ class TypeSystem : public PluginInterface,
494494
virtual bool IsReferenceType(lldb::opaque_compiler_type_t type,
495495
CompilerType *pointee_type, bool *is_rvalue) = 0;
496496

497+
virtual bool IsValidDereferenceType(lldb::opaque_compiler_type_t type) = 0;
498+
497499
virtual bool
498500
ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type) {
499501
return IsPointerOrReferenceType(type, nullptr);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,6 +3443,13 @@ 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+
34463453
bool TypeSystemClang::IsFloatingPointType(lldb::opaque_compiler_type_t type,
34473454
uint32_t &count, bool &is_complex) {
34483455
if (type) {
@@ -6565,6 +6572,8 @@ llvm::Expected<CompilerType> TypeSystemClang::GetChildCompilerTypeAtIndex(
65656572
return size_or_err.takeError();
65666573
child_byte_size = *size_or_err;
65676574
child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6575+
if (idx == 0)
6576+
child_is_deref_of_parent = true;
65686577
return element_type;
65696578
}
65706579
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,8 @@ 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+
719721
bool IsScalarType(lldb::opaque_compiler_type_t type) override;
720722

721723
bool IsTypedefType(lldb::opaque_compiler_type_t type) override;

lldb/source/Symbol/CompilerType.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ 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+
236243
bool CompilerType::ShouldTreatScalarValueAsAddress() const {
237244
if (IsValid())
238245
if (auto type_system_sp = GetTypeSystem())

lldb/source/ValueObject/ValueObject.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,8 +2844,9 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
28442844
if (m_deref_valobj)
28452845
return m_deref_valobj->GetSP();
28462846

2847-
const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
2848-
if (is_pointer_or_reference_type) {
2847+
const bool is_valid_dereference_type =
2848+
GetCompilerType().IsValidDereferenceType();
2849+
if (is_valid_dereference_type) {
28492850
bool omit_empty_base_classes = true;
28502851
bool ignore_array_bounds = false;
28512852

@@ -2924,7 +2925,7 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
29242925
StreamString strm;
29252926
GetExpressionPath(strm);
29262927

2927-
if (is_pointer_or_reference_type)
2928+
if (is_valid_dereference_type)
29282929
error = Status::FromErrorStringWithFormat(
29292930
"dereference failed: (%s) %s",
29302931
GetTypeName().AsCString("<invalid type>"), strm.GetData());

0 commit comments

Comments
 (0)