Skip to content

Commit 7cca4bf

Browse files
committed
[lldb][TypeSystemClang] Add a function IsValidDereferenceType to TypeSystem to allow arrays to be dereferenced in C/C++.
1 parent c26db58 commit 7cca4bf

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

492+
virtual bool IsValidDereferenceType(lldb::opaque_compiler_type_t type) = 0;
493+
492494
virtual bool
493495
ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type) {
494496
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) {
@@ -6544,6 +6551,8 @@ llvm::Expected<CompilerType> TypeSystemClang::GetChildCompilerTypeAtIndex(
65446551
return size_or_err.takeError();
65456552
child_byte_size = *size_or_err;
65466553
child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6554+
if (idx == 0)
6555+
child_is_deref_of_parent = true;
65476556
return element_type;
65486557
}
65496558
}

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
@@ -2794,8 +2794,9 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
27942794
if (m_deref_valobj)
27952795
return m_deref_valobj->GetSP();
27962796

2797-
const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
2798-
if (is_pointer_or_reference_type) {
2797+
const bool is_valid_dereference_type =
2798+
GetCompilerType().IsValidDereferenceType();
2799+
if (is_valid_dereference_type) {
27992800
bool omit_empty_base_classes = true;
28002801
bool ignore_array_bounds = false;
28012802

@@ -2871,7 +2872,7 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
28712872
StreamString strm;
28722873
GetExpressionPath(strm);
28732874

2874-
if (is_pointer_or_reference_type)
2875+
if (is_valid_dereference_type)
28752876
error = Status::FromErrorStringWithFormat(
28762877
"dereference failed: (%s) %s",
28772878
GetTypeName().AsCString("<invalid type>"), strm.GetData());

0 commit comments

Comments
 (0)