27#include "llvm/Support/ErrorExtras.h"
60 llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name)
override;
63 ExecutionContextRef m_exe_ctx_ref;
65 CompilerType m_pair_type;
79 llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name)
override;
87 ValueObject *m_ptr_obj =
nullptr;
92LibstdcppMapIteratorSyntheticFrontEnd::LibstdcppMapIteratorSyntheticFrontEnd(
105 TargetSP target_sp(valobj_sp->GetTargetSP());
110 bool is_64bit = (target_sp->GetArchitecture().GetAddressByteSize() == 8);
114 m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
116 ValueObjectSP _M_node_sp(valobj_sp->GetChildMemberWithName(
"_M_node"));
120 m_pair_address = _M_node_sp->GetValueAsUnsigned(0);
121 if (m_pair_address == 0)
124 m_pair_address += (is_64bit ? 32 : 16);
126 CompilerType my_type(valobj_sp->GetCompilerType());
127 if (my_type.GetNumTemplateArguments() >= 1) {
128 CompilerType pair_type = my_type.GetTypeTemplateArgument(0);
131 m_pair_type = pair_type;
138llvm::Expected<uint32_t>
139LibstdcppMapIteratorSyntheticFrontEnd::CalculateNumChildren() {
144LibstdcppMapIteratorSyntheticFrontEnd::GetChildAtIndex(uint32_t idx) {
145 if (m_pair_address != 0 && m_pair_type) {
147 m_pair_sp = CreateChildValueObjectFromAddress(
"pair", m_pair_address,
148 m_exe_ctx_ref, m_pair_type);
150 return m_pair_sp->GetChildAtIndex(idx);
155llvm::Expected<size_t>
156LibstdcppMapIteratorSyntheticFrontEnd::GetIndexOfChildWithName(
160 if (name ==
"second")
162 return llvm::createStringErrorV(
"type has no child named '{0}'", name);
165SyntheticChildrenFrontEnd *
168 return (valobj_sp ?
new LibstdcppMapIteratorSyntheticFrontEnd(valobj_sp)
182SyntheticChildrenFrontEnd *
185 return (valobj_sp ?
new VectorIteratorSyntheticFrontEnd(
186 valobj_sp, {ConstString(
"_M_current")})
192 llvm::ArrayRef<ConstString> item_names)
210 if (item_ptr->GetValueAsUnsigned(0) == 0)
216 item_ptr->GetCompilerType().GetPointeeType());
222llvm::Expected<uint32_t>
234llvm::Expected<size_t>
238 return llvm::createStringErrorV(
"type has no child named '{0}'", name);
244 if (!ptr || !ptr->GetError().Success())
245 stream <<
"Summary Unavailable";
247 stream << ptr->GetSummaryAsCString();
252template <StringPr
inter::StringElementType element_type>
255 std::string prefix_token) {
258 if (!data_sp || !size_sp)
261 bool success =
false;
262 uint64_t size = size_sp->GetValueAsUnsigned(0, &success);
264 stream <<
"Summary Unavailable";
270 scratch_stream, summary_options, data_sp, size, prefix_token);
273 stream << scratch_stream.
GetData();
275 stream <<
"Summary Unavailable";
285 switch (*wchar_t_size) {
299template <StringElementType element_type>
301 switch (element_type) {
302 case StringElementType::ASCII:
304 case StringElementType::UTF8:
306 case StringElementType::UTF16:
308 case StringElementType::UTF32:
311 llvm_unreachable(
"invalid element type");
314template <StringPr
inter::StringElementType element_type>
334LibStdcppSharedPtrSyntheticFrontEnd::LibStdcppSharedPtrSyntheticFrontEnd(
341llvm::Expected<uint32_t>
342LibStdcppSharedPtrSyntheticFrontEnd::CalculateNumChildren() {
347LibStdcppSharedPtrSyntheticFrontEnd::GetChildAtIndex(uint32_t idx) {
352 return m_ptr_obj->
GetSP();
368 auto backend = m_backend.GetSP();
372 auto valobj_sp = backend->GetNonSyntheticValue();
376 auto ptr_obj_sp = valobj_sp->GetChildMemberWithName(
"_M_ptr");
384 m_ptr_obj = cast_ptr_sp->
Clone(ConstString(
"pointer")).get();
389llvm::Expected<size_t>
390LibStdcppSharedPtrSyntheticFrontEnd::GetIndexOfChildWithName(ConstString name) {
391 if (name ==
"pointer")
394 if (name ==
"object" || name ==
"$$dereference$$")
397 return llvm::createStringErrorV(
"type has no child named '{0}'", name);
400SyntheticChildrenFrontEnd *
403 return (valobj_sp ?
new LibStdcppSharedPtrSyntheticFrontEnd(valobj_sp)
413 ValueObjectSP ptr_sp(valobj_sp->GetChildMemberWithName(
"_M_ptr"));
419 ValueObjectSP pi_sp = valobj_sp->GetChildAtNamePath({
"_M_refcount",
"_M_pi"});
424 uint64_t pi_addr = pi_sp->GetValueAsUnsigned(0, &success);
426 if (!success || pi_addr == 0)
429 int64_t shared_count = 0;
430 if (
auto count_sp = pi_sp->GetChildMemberWithName(
"_M_use_count")) {
432 shared_count = count_sp->GetValueAsSigned(0, &success);
436 stream.
Printf(
" strong=%" PRId64, shared_count);
440 if (
auto weak_count_sp = pi_sp->GetChildMemberWithName(
"_M_weak_count")) {
442 int64_t count = weak_count_sp->GetValueAsUnsigned(0, &success);
446 stream.
Printf(
" weak=%" PRId64, count - (shared_count != 0));
453 switch (index_byte_size) {
469 ValueObjectSP index_obj = valobj_sp->GetChildMemberWithName(
"_M_index");
470 ValueObjectSP data_obj = valobj_sp->GetChildMemberWithName(
"_M_u");
471 if (!index_obj || !data_obj)
474 auto index_bytes_or_err = index_obj->GetByteSize();
475 if (!index_bytes_or_err) {
477 index_bytes_or_err.takeError(),
478 "failed to get variant index byte size: {0}");
482 auto index = index_obj->GetValueAsUnsigned(0);
483 if (index == npos_value) {
484 stream.
Printf(
" No Value");
489 valobj_sp->GetCompilerType().GetCanonicalType().GetNonReferenceType();
492 if (index >= variant_type.GetNumTemplateArguments(
true)) {
493 stream.
Printf(
" <Invalid>");
497 auto active_type = variant_type.GetTypeTemplateArgument(index,
true);
498 stream <<
" Active Type = " << active_type.GetDisplayTypeName() <<
" ";
502static std::optional<int64_t>
508 int64_t value = value_sp->GetValueAsSigned(0, &success);
524 stream <<
"equivalent";
531 stream <<
"unordered";
549 stream <<
"equivalent";
static bool formatStringViewImpl(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options, std::string prefix_token)
static constexpr const char * getPrefixToken()
static std::optional< int64_t > LibStdcppExtractOrderingValue(ValueObject &valobj)
static uint64_t LibStdcppVariantNposValue(size_t index_byte_size)
#define LLDB_LOG_ERROR(log, error,...)
StringPrinter::StringElementType StringElementType
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 ...
A uniqued constant string class.
bool Fail() const
Test for error condition.
bool Success() const
Test for success condition.
const char * GetData() const
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.
lldb::ValueObjectSP CreateChildValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type, bool do_deref=true)
SyntheticChildrenFrontEnd(ValueObject &backend)
lldb::ValueObjectSP GetSP()
virtual lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name, bool can_create=true)
lldb::ValueObjectSP GetChildAtNamePath(llvm::ArrayRef< llvm::StringRef > names)
virtual lldb::ValueObjectSP Clone(ConstString new_name)
Creates a copy of the ValueObject with a new name and setting the current ValueObject as its parent.
virtual lldb::ValueObjectSP Dereference(Status &error)
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
std::shared_ptr< lldb_private::Target > TargetSP