Follow-up to https://github.com/llvm/llvm-project/pull/147165#pullrequestreview-2992585513 Currently when we explicitly dereference a std::shared_ptr, both the libstdc++ and libc++ formatters will cast the type of the synthetic pointer child to whatever the `std::shared_ptr::element_type` is aliased to. E.g., ``` (lldb) v p (std::shared_ptr<int>) p = 10 strong=1 weak=0 { pointer = 0x000000010016c6a0 } (lldb) v *p (int) *p = 10 ``` However, when we print (or dereference) `p.pointer`, the type devolves to something less user-friendly: ``` (lldb) v p.pointer (std::shared_ptr<int>::element_type *) p.pointer = 0x000000010016c6a0 (lldb) v *p.pointer (std::shared_ptr<int>::element_type) *p.pointer = 10 ``` This patch changes both formatters to store the casted type. Then `GetChildAtIndex` will consistently use the unwrapped type.
23 lines
766 B
C++
23 lines
766 B
C++
//===-- 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::GetDesugaredSmartPointerValue(
|
|
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());
|
|
}
|