Skip to content

Commit 08834d4

Browse files
committed
[lldb][TypeSystemClang] Add a function IsValidDereferenceType to TypeSystem to allow arrays to be dereferenced in C/C++.
1 parent 72b2d4d commit 08834d4

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

489+
virtual bool IsValidDereferenceType(lldb::opaque_compiler_type_t type) = 0;
490+
489491
virtual bool
490492
ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type) {
491493
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
@@ -2850,8 +2850,9 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
28502850
if (m_deref_valobj)
28512851
return m_deref_valobj->GetSP();
28522852

2853-
const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
2854-
if (is_pointer_or_reference_type) {
2853+
const bool is_valid_dereference_type =
2854+
GetCompilerType().IsValidDereferenceType();
2855+
if (is_valid_dereference_type) {
28552856
bool omit_empty_base_classes = true;
28562857
bool ignore_array_bounds = false;
28572858

@@ -2930,7 +2931,7 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
29302931
StreamString strm;
29312932
GetExpressionPath(strm);
29322933

2933-
if (is_pointer_or_reference_type)
2934+
if (is_valid_dereference_type)
29342935
error = Status::FromErrorStringWithFormat(
29352936
"dereference failed: (%s) %s",
29362937
GetTypeName().AsCString("<invalid type>"), strm.GetData());

0 commit comments

Comments
 (0)