Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lldb/include/lldb/DataFormatters/FormattersHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ void DumpCxxSmartPtrPointerSummary(Stream &stream, ValueObject &ptr,
bool ContainerSizeSummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options);

/// Return the ValueObjectSP of the underlying pointer member whose type
/// is a desugared 'std::shared_ptr::element_type *'.
lldb::ValueObjectSP GetCxxSmartPtrElementPointerType(ValueObject &ptr,
ValueObject &container);

Address GetArrayAddressOrPointerValue(ValueObject &valobj);

time_t GetOSXEpoch();
Expand Down
13 changes: 13 additions & 0 deletions lldb/source/DataFormatters/FormattersHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,16 @@ bool lldb_private::formatters::ContainerSizeSummaryProvider(
return FormatEntity::FormatStringRef("size=${svar%#}", stream, nullptr,
nullptr, nullptr, &valobj, false, false);
}

ValueObjectSP lldb_private::formatters::GetCxxSmartPtrElementPointerType(
ValueObject &ptr, ValueObject &container) {
auto container_type = container.GetCompilerType().GetNonReferenceType();
if (!container_type)
return nullptr;

auto arg = container_type.GetTypeTemplateArgument(0);
if (!arg)
return nullptr;

return ptr.Cast(arg.GetPointerType());
}
14 changes: 7 additions & 7 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,7 @@ lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEnd::GetChildAtIndex(

if (idx == 1) {
Status status;
auto value_type_sp = valobj_sp->GetCompilerType()
.GetTypeTemplateArgument(0)
.GetPointerType();
ValueObjectSP cast_ptr_sp = m_ptr_obj->Cast(value_type_sp);
ValueObjectSP value_sp = cast_ptr_sp->Dereference(status);
ValueObjectSP value_sp = m_ptr_obj->Dereference(status);
if (status.Success())
return value_sp;
}
Expand All @@ -293,7 +289,11 @@ lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEnd::Update() {
if (!ptr_obj_sp)
return lldb::ChildCacheState::eRefetch;

m_ptr_obj = ptr_obj_sp->Clone(ConstString("pointer")).get();
auto cast_ptr_sp = GetCxxSmartPtrElementPointerType(*ptr_obj_sp, *valobj_sp);
if (!cast_ptr_sp)
return lldb::ChildCacheState::eRefetch;

m_ptr_obj = cast_ptr_sp->Clone(ConstString("pointer")).get();

lldb::ValueObjectSP cntrl_sp(valobj_sp->GetChildMemberWithName("__cntrl_"));

Expand All @@ -305,7 +305,7 @@ lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEnd::Update() {
llvm::Expected<size_t>
lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEnd::
GetIndexOfChildWithName(ConstString name) {
if (name == "__ptr_" || name == "pointer")
if (name == "pointer")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __ptr_ here feels redundant. Happy to do this in a separate PR though.

return 0;

if (name == "object" || name == "$$dereference$$")
Expand Down
12 changes: 6 additions & 6 deletions lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,7 @@ LibStdcppSharedPtrSyntheticFrontEnd::GetChildAtIndex(uint32_t idx) {
return nullptr;

Status status;
auto value_type_sp = valobj_sp->GetCompilerType()
.GetTypeTemplateArgument(0)
.GetPointerType();
ValueObjectSP cast_ptr_sp = m_ptr_obj->Cast(value_type_sp);
ValueObjectSP value_sp = cast_ptr_sp->Dereference(status);
ValueObjectSP value_sp = m_ptr_obj->Dereference(status);
if (status.Success())
return value_sp;
}
Expand All @@ -297,7 +293,11 @@ lldb::ChildCacheState LibStdcppSharedPtrSyntheticFrontEnd::Update() {
if (!ptr_obj_sp)
return lldb::ChildCacheState::eRefetch;

m_ptr_obj = ptr_obj_sp->Clone(ConstString("pointer")).get();
auto cast_ptr_sp = GetCxxSmartPtrElementPointerType(*ptr_obj_sp, *valobj_sp);
if (!cast_ptr_sp)
return lldb::ChildCacheState::eRefetch;

m_ptr_obj = cast_ptr_sp->Clone(ConstString("pointer")).get();

return lldb::ChildCacheState::eRefetch;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def do_test(self):
"wie", type="std::weak_ptr<int>", summary="nullptr strong=2 weak=2"
)

self.expect_var_path("si.pointer", type="int *")
self.expect_var_path("*si.pointer", type="int", value="47")
self.expect_var_path("si.object", type="int", value="47")

self.runCmd("settings set target.experimental.use-DIL true")
self.expect_var_path("ptr_node->value", value="1")
self.expect_var_path("ptr_node->next->value", value="2")
Expand Down
Loading