Michael Buch f9999184dd
[lldb][Formatters] Consistently unwrap pointer element_type in std::shared_ptr formatters (#147340)
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.
2025-07-08 14:45:15 +01:00

31 lines
1.2 KiB
C++

//===-- LibCxx.h -----------------------------------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_GENERIC_H
#define LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_GENERIC_H
#include "lldb/DataFormatters/TypeSummary.h"
#include "lldb/Utility/Stream.h"
#include "lldb/ValueObject/ValueObject.h"
namespace lldb_private {
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 GetDesugaredSmartPointerValue(ValueObject &ptr,
ValueObject &container);
} // namespace formatters
} // namespace lldb_private
#endif // LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_GENERIC_H