Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
1 change: 1 addition & 0 deletions lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN
CPlusPlusLanguage.cpp
CPlusPlusNameParser.cpp
CxxStringTypes.cpp
Generic.cpp
GenericBitset.cpp
GenericOptional.cpp
LibCxx.cpp
Expand Down
22 changes: 22 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/Generic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Generic.cpp ------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===---------------------------------------------------------------------===//

#include "Generic.h"

lldb::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());
}
5 changes: 5 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/Generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace formatters {
bool GenericOptionalSummaryProvider(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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

GetDesugaredSmartPointerValue ?

ValueObject &container);

} // namespace formatters
} // namespace lldb_private

Expand Down
15 changes: 8 additions & 7 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "lldb/ValueObject/ValueObjectConstResult.h"

#include "Plugins/Language/CPlusPlus/CxxStringTypes.h"
#include "Plugins/Language/CPlusPlus/Generic.h"
#include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h"
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include "lldb/lldb-enumerations.h"
Expand Down Expand Up @@ -264,11 +265,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 +290,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 +306,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
13 changes: 7 additions & 6 deletions lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "LibStdcpp.h"
#include "LibCxx.h"

#include "Plugins/Language/CPlusPlus/Generic.h"
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/DataFormatters/StringPrinter.h"
Expand Down Expand Up @@ -273,11 +274,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 +294,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