29 ListEntry() =
default;
30 ListEntry(
ValueObjectSP entry_sp) : m_entry_sp(std::move(entry_sp)) {}
37 return ListEntry(m_entry_sp->GetChildMemberWithName(
"__next_"));
43 return ListEntry(m_entry_sp->GetChildMemberWithName(
"__prev_"));
46 uint64_t value()
const {
49 return m_entry_sp->GetValueAsUnsigned(0);
52 bool null() {
return (value() == 0); }
54 explicit operator bool() {
return GetEntry() && !null(); }
60 bool operator==(
const ListEntry &rhs)
const {
return value() == rhs.value(); }
62 bool operator!=(
const ListEntry &rhs)
const {
return !(*
this == rhs); }
70 ListIterator() =
default;
71 ListIterator(ListEntry entry) : m_entry(std::move(entry)) {}
72 ListIterator(
ValueObjectSP entry) : m_entry(std::move(entry)) {}
73 ListIterator(
ValueObject *entry) : m_entry(entry) {}
79 return m_entry.GetEntry();
82 return m_entry.GetEntry();
90 return m_entry.GetEntry();
93 bool operator==(
const ListIterator &rhs)
const {
94 return (rhs.m_entry == m_entry);
98 void next() { m_entry = m_entry.next(); }
100 void prev() { m_entry = m_entry.prev(); }
121 static constexpr bool g_use_loop_detect =
true;
122 size_t m_loop_detected = 0;
124 ListEntry m_slow_runner;
125 ListEntry m_fast_runner;
127 size_t m_list_capping_size = 0;
129 std::map<size_t, ListIterator> m_iterators;
131 bool HasLoop(
size_t count);
135class ForwardListFrontEnd :
public AbstractListFrontEnd {
144class ListFrontEnd :
public AbstractListFrontEnd {
148 ~ListFrontEnd()
override =
default;
167 m_list_capping_size = 0;
168 m_slow_runner.SetEntry(
nullptr);
169 m_fast_runner.SetEntry(
nullptr);
172 if (m_backend.GetTargetSP())
173 m_list_capping_size =
174 m_backend.GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
175 if (m_list_capping_size == 0)
176 m_list_capping_size = 255;
189bool AbstractListFrontEnd::HasLoop(
size_t count) {
190 if (!g_use_loop_detect)
196 if (m_loop_detected == 0) {
199 m_slow_runner = ListEntry(m_head).next();
200 m_fast_runner = m_slow_runner.next();
208 const size_t steps_to_run = std::min(count, m_count);
209 while (m_loop_detected < steps_to_run && m_slow_runner && m_fast_runner &&
210 m_slow_runner != m_fast_runner) {
212 m_slow_runner = m_slow_runner.next();
213 m_fast_runner = m_fast_runner.next().next();
216 if (count <= m_loop_detected)
218 if (!m_slow_runner || !m_fast_runner)
220 return m_slow_runner == m_fast_runner;
224 size_t advance = idx;
225 ListIterator current(m_head);
227 auto cached_iterator = m_iterators.find(idx - 1);
228 if (cached_iterator != m_iterators.end()) {
229 current = cached_iterator->second;
234 m_iterators[idx] = current;
238ForwardListFrontEnd::ForwardListFrontEnd(
ValueObject &valobj)
239 : AbstractListFrontEnd(valobj) {
243llvm::Expected<uint32_t> ForwardListFrontEnd::CalculateNumChildren() {
247 ListEntry current(m_head);
249 while (current && m_count < m_list_capping_size) {
251 current = current.next();
256ValueObjectSP ForwardListFrontEnd::GetChildAtIndex(uint32_t idx) {
257 if (idx >= CalculateNumChildrenIgnoringErrors())
263 if (HasLoop(idx + 1))
270 current_sp = current_sp->GetChildAtIndex(1);
278 current_sp->GetData(data,
error);
282 return CreateValueObjectFromData(llvm::formatv(
"[{0}]", idx).str(), data,
283 m_backend.GetExecutionContextRef(),
288 AbstractListFrontEnd::Update();
292 if (err.
Fail() || !backend_addr)
295 ValueObjectSP impl_sp(m_backend.GetChildMemberWithName(
"__before_begin_"));
301 m_head = impl_sp->GetChildMemberWithName(
"__next_").get();
306 : AbstractListFrontEnd(*valobj_sp) {
311llvm::Expected<uint32_t> ListFrontEnd::CalculateNumChildren() {
314 if (!m_head || !m_tail || m_node_address == 0)
316 ValueObjectSP size_alloc(m_backend.GetChildMemberWithName(
"__size_alloc_"));
320 m_count = value->GetValueAsUnsigned(
UINT32_MAX);
326 uint64_t next_val = m_head->GetValueAsUnsigned(0);
327 uint64_t prev_val = m_tail->GetValueAsUnsigned(0);
328 if (next_val == 0 || prev_val == 0)
330 if (next_val == m_node_address)
332 if (next_val == prev_val)
335 ListEntry current(m_head);
336 while (current.next() && current.next().value() != m_node_address) {
338 current = current.next();
339 if (size > m_list_capping_size)
342 return m_count = (size - 1);
350 if (idx >= CalculateNumChildrenIgnoringErrors())
353 if (!m_head || !m_tail || m_node_address == 0)
356 if (HasLoop(idx + 1))
363 current_sp = current_sp->GetChildAtIndex(1);
367 if (current_sp->GetName() == g_next) {
368 ProcessSP process_sp(current_sp->GetProcessSP());
373 lldb::addr_t addr = current_sp->GetParent()->GetPointerValue();
374 addr = addr + 2 * process_sp->GetAddressByteSize();
377 CreateValueObjectFromAddress(
"__value_", addr, exe_ctx, m_element_type);
386 current_sp->GetData(data,
error);
391 name.
Printf(
"[%" PRIu64
"]", (uint64_t)idx);
392 return CreateValueObjectFromData(name.
GetString(), data,
393 m_backend.GetExecutionContextRef(),
398 AbstractListFrontEnd::Update();
404 if (err.
Fail() || !backend_addr)
406 m_node_address = backend_addr->GetValueAsUnsigned(0);
409 ValueObjectSP impl_sp(m_backend.GetChildMemberWithName(
"__end_"));
412 m_head = impl_sp->GetChildMemberWithName(
"__next_").get();
413 m_tail = impl_sp->GetChildMemberWithName(
"__prev_").get();
419 return (valobj_sp ?
new ListFrontEnd(valobj_sp) :
nullptr);
425 return valobj_sp ?
new ForwardListFrontEnd(*valobj_sp) :
nullptr;
static llvm::raw_ostream & error(Stream &strm)
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
size_t GetNumTemplateArguments(bool expand_pack=false) const
Return the number of template arguments the type has.
CompilerType GetNonReferenceType() const
If this type is a reference to a type (L value or R value reference), return a new type with the refe...
bool IsReferenceType(CompilerType *pointee_type=nullptr, bool *is_rvalue=nullptr) const
A uniqued constant string class.
const char * GetCString() const
Get the string value as a C string.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool Fail() const
Test for error condition.
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
virtual lldb::ChildCacheState Update()=0
This function is assumed to always succeed and if it fails, the front-end should know to deal with it...
virtual bool MightHaveChildren()=0
virtual size_t GetIndexOfChildWithName(ConstString name)=0
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
bool operator!=(const Address &lhs, const Address &rhs)
ChildCacheState
Specifies if children need to be re-computed after a call to SyntheticChildrenFrontEnd::Update.
@ eRefetch
Children need to be recomputed dynamically.
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::Process > ProcessSP
bool LLDB_API operator==(const SBAddress &lhs, const SBAddress &rhs)