15#include "llvm/ADT/ScopeExit.h"
69enum class LibcxxVariantIndexValidity { Valid,
Invalid, NPos };
71uint64_t VariantNposValue(uint64_t index_byte_size) {
72 switch (index_byte_size) {
74 return static_cast<uint8_t
>(-1);
76 return static_cast<uint16_t
>(-1);
78 return static_cast<uint32_t
>(-1);
80 lldbassert(
false &&
"Unknown index type size");
81 return static_cast<uint32_t
>(-1);
84LibcxxVariantIndexValidity
86 ValueObjectSP index_sp(impl_sp->GetChildMemberWithName(
"__index"));
89 return LibcxxVariantIndexValidity::Invalid;
100 llvm::Expected<uint64_t> index_type_bytes = index_type.
GetByteSize(
nullptr);
101 if (!index_type_bytes) {
103 index_type_bytes.takeError(),
"{0}");
104 if (!index_type_bytes)
105 return LibcxxVariantIndexValidity::Invalid;
107 uint64_t npos_value = VariantNposValue(*index_type_bytes);
108 uint64_t index_value = index_sp->GetValueAsUnsigned(0);
110 if (index_value == npos_value)
111 return LibcxxVariantIndexValidity::NPos;
113 return LibcxxVariantIndexValidity::Valid;
116std::optional<uint64_t> LibcxxVariantIndexValue(
ValueObjectSP &impl_sp) {
117 ValueObjectSP index_sp(impl_sp->GetChildMemberWithName(
"__index"));
122 return {index_sp->GetValueAsUnsigned(0)};
126 ValueObjectSP data_sp(impl_sp->GetChildMemberWithName(
"__data"));
132 for (uint64_t n = index; n != 0; --n) {
133 ValueObjectSP tail_sp(current_level->GetChildMemberWithName(
"__tail"));
138 current_level = tail_sp;
141 return current_level->GetChildMemberWithName(
"__head");
159 LibcxxVariantIndexValidity validity = LibcxxVariantGetIndexValidity(impl_sp);
161 if (validity == LibcxxVariantIndexValidity::Invalid)
164 if (validity == LibcxxVariantIndexValidity::NPos) {
165 stream.
Printf(
" No Value");
169 auto optional_index_value = LibcxxVariantIndexValue(impl_sp);
171 if (!optional_index_value)
174 uint64_t index_value = *optional_index_value;
176 ValueObjectSP nth_head = LibcxxVariantGetNthHead(impl_sp, index_value);
201 VariantFrontEnd(ValueObject &valobj) : SyntheticChildrenFrontEnd(valobj) {
205 llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name)
override {
208 return llvm::createStringError(
"Type has no child named '%s'",
211 return *optional_idx;
226 m_backend, {ConstString(
"__impl_"), ConstString(
"__impl")});
230 LibcxxVariantIndexValidity validity = LibcxxVariantGetIndexValidity(impl_sp);
232 if (validity == LibcxxVariantIndexValidity::Invalid)
235 if (validity == LibcxxVariantIndexValidity::NPos)
243ValueObjectSP VariantFrontEnd::GetChildAtIndex(uint32_t idx) {
248 m_backend, {ConstString(
"__impl_"), ConstString(
"__impl")});
252 auto optional_index_value = LibcxxVariantIndexValue(impl_sp);
254 if (!optional_index_value)
257 uint64_t index_value = *optional_index_value;
259 ValueObjectSP nth_head = LibcxxVariantGetNthHead(impl_sp, index_value);
264 CompilerType head_type = nth_head->GetCompilerType();
274 ValueObjectSP head_value(nth_head->GetChildMemberWithName(
"__value"));
279 return head_value->Clone(ConstString(
"Value"));
282SyntheticChildrenFrontEnd *
286 return new VariantFrontEnd(*valobj_sp);
#define LLDB_LOG_ERRORV(log, error,...)
static std::optional< size_t > CalculateNumChildren(CompilerType container_elem_type, uint64_t num_elements, CompilerType element_type)
Calculates the number of elements stored in a container (with element type 'container_elem_type') as ...
Generic representation of a type in a programming language.
CompilerType GetTypeTemplateArgument(size_t idx, bool expand_pack=false) const
ConstString GetDisplayTypeName() const
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
const char * GetCString() const
Get the string value as a C string.
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
virtual lldb::ValueObjectSP GetNonSyntheticValue()
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
ChildCacheState
Specifies if children need to be re-computed after a call to SyntheticChildrenFrontEnd::Update.
@ eRefetch
Children need to be recomputed dynamically.
@ eReuse
Children did not change and don't need to be recomputed; re-use what we computed the last time we cal...
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP