29 ListEntry() =
default;
30 ListEntry(ValueObjectSP entry_sp) : m_entry_sp(std::move(entry_sp)) {}
32 : m_entry_sp(entry ? entry->GetSP() : ValueObjectSP()) {}
37 return ListEntry(m_entry_sp->GetChildMemberWithName(
"__next_",
true));
43 return ListEntry(m_entry_sp->GetChildMemberWithName(
"__prev_",
true));
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(); }
56 ValueObjectSP GetEntry() {
return m_entry_sp; }
58 void SetEntry(ValueObjectSP entry) { m_entry_sp = entry; }
60 bool operator==(
const ListEntry &rhs)
const {
return value() == rhs.value(); }
62 bool operator!=(
const ListEntry &rhs)
const {
return !(*
this == rhs); }
65 ValueObjectSP m_entry_sp;
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) {}
75 ValueObjectSP value() {
return m_entry.GetEntry(); }
77 ValueObjectSP advance(
size_t count) {
79 return m_entry.GetEntry();
82 return m_entry.GetEntry();
88 return lldb::ValueObjectSP();
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);
132 ValueObjectSP GetItem(
size_t idx);
135class ForwardListFrontEnd :
public AbstractListFrontEnd {
140 ValueObjectSP GetChildAtIndex(
size_t idx)
override;
141 bool Update()
override;
144class ListFrontEnd :
public AbstractListFrontEnd {
146 ListFrontEnd(lldb::ValueObjectSP valobj_sp);
148 ~ListFrontEnd()
override =
default;
152 lldb::ValueObjectSP GetChildAtIndex(
size_t idx)
override;
154 bool Update()
override;
163bool AbstractListFrontEnd::Update() {
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;
223ValueObjectSP AbstractListFrontEnd::GetItem(
size_t idx) {
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;
233 ValueObjectSP value_sp = current.advance(advance);
234 m_iterators[idx] = current;
238ForwardListFrontEnd::ForwardListFrontEnd(
ValueObject &valobj)
239 : AbstractListFrontEnd(valobj) {
243size_t ForwardListFrontEnd::CalculateNumChildren() {
247 ListEntry current(m_head);
249 while (current && m_count < m_list_capping_size) {
251 current = current.next();
256ValueObjectSP ForwardListFrontEnd::GetChildAtIndex(
size_t idx) {
263 if (HasLoop(idx + 1))
266 ValueObjectSP current_sp = GetItem(idx);
270 current_sp = current_sp->GetChildAtIndex(1,
true);
278 current_sp->GetData(data,
error);
282 return CreateValueObjectFromData(llvm::formatv(
"[{0}]", idx).str(), data,
283 m_backend.GetExecutionContextRef(),
287bool ForwardListFrontEnd::Update() {
288 AbstractListFrontEnd::Update();
291 ValueObjectSP backend_addr(m_backend.AddressOf(err));
292 if (err.
Fail() || !backend_addr)
295 ValueObjectSP impl_sp(
296 m_backend.GetChildMemberWithName(
"__before_begin_",
true));
302 m_head = impl_sp->GetChildMemberWithName(
"__next_",
true).get();
306ListFrontEnd::ListFrontEnd(lldb::ValueObjectSP valobj_sp)
307 : AbstractListFrontEnd(*valobj_sp) {
312size_t ListFrontEnd::CalculateNumChildren() {
315 if (!m_head || !m_tail || m_node_address == 0)
317 ValueObjectSP size_alloc(
318 m_backend.GetChildMemberWithName(
"__size_alloc_",
true));
322 m_count = value->GetValueAsUnsigned(
UINT32_MAX);
328 uint64_t next_val = m_head->GetValueAsUnsigned(0);
329 uint64_t prev_val = m_tail->GetValueAsUnsigned(0);
330 if (next_val == 0 || prev_val == 0)
332 if (next_val == m_node_address)
334 if (next_val == prev_val)
337 ListEntry current(m_head);
338 while (current.next() && current.next().value() != m_node_address) {
340 current = current.next();
341 if (size > m_list_capping_size)
344 return m_count = (size - 1);
348lldb::ValueObjectSP ListFrontEnd::GetChildAtIndex(
size_t idx) {
353 return lldb::ValueObjectSP();
355 if (!m_head || !m_tail || m_node_address == 0)
356 return lldb::ValueObjectSP();
358 if (HasLoop(idx + 1))
359 return lldb::ValueObjectSP();
361 ValueObjectSP current_sp = GetItem(idx);
363 return lldb::ValueObjectSP();
365 current_sp = current_sp->GetChildAtIndex(1,
true);
367 return lldb::ValueObjectSP();
369 if (current_sp->GetName() == g_next) {
370 ProcessSP process_sp(current_sp->GetProcessSP());
372 return lldb::ValueObjectSP();
375 lldb::addr_t addr = current_sp->GetParent()->GetPointerValue();
376 addr = addr + 2 * process_sp->GetAddressByteSize();
379 CreateValueObjectFromAddress(
"__value_", addr, exe_ctx, m_element_type);
381 return lldb::ValueObjectSP();
388 current_sp->GetData(data,
error);
390 return lldb::ValueObjectSP();
393 name.
Printf(
"[%" PRIu64
"]", (uint64_t)idx);
394 return CreateValueObjectFromData(name.
GetString(), data,
395 m_backend.GetExecutionContextRef(),
399bool ListFrontEnd::Update() {
400 AbstractListFrontEnd::Update();
405 ValueObjectSP backend_addr(m_backend.AddressOf(err));
406 if (err.
Fail() || !backend_addr)
408 m_node_address = backend_addr->GetValueAsUnsigned(0);
411 ValueObjectSP impl_sp(m_backend.GetChildMemberWithName(
"__end_",
true));
414 m_head = impl_sp->GetChildMemberWithName(
"__next_",
true).get();
415 m_tail = impl_sp->GetChildMemberWithName(
"__prev_",
true).get();
421 return (valobj_sp ?
new ListFrontEnd(valobj_sp) :
nullptr);
427 return valobj_sp ?
new ForwardListFrontEnd(*valobj_sp) :
nullptr;
static llvm::raw_ostream & error(Stream &strm)
static size_t CalculateNumChildren(CompilerType container_type, CompilerType element_type, lldb_private::ExecutionContextScope *exe_scope=nullptr)
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 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)
bool LLDB_API operator==(const SBAddress &lhs, const SBAddress &rhs)