diff options
Diffstat (limited to 'source/DataFormatters/LibCxxMap.cpp')
-rw-r--r-- | source/DataFormatters/LibCxxMap.cpp | 215 |
1 files changed, 127 insertions, 88 deletions
diff --git a/source/DataFormatters/LibCxxMap.cpp b/source/DataFormatters/LibCxxMap.cpp index e665f29622d8..82e747e2db08 100644 --- a/source/DataFormatters/LibCxxMap.cpp +++ b/source/DataFormatters/LibCxxMap.cpp @@ -25,40 +25,84 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; +namespace lldb_private { + namespace formatters { + class LibcxxStdMapSyntheticFrontEnd : public SyntheticChildrenFrontEnd + { + public: + LibcxxStdMapSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp); + + virtual size_t + CalculateNumChildren (); + + virtual lldb::ValueObjectSP + GetChildAtIndex (size_t idx); + + virtual bool + Update(); + + virtual bool + MightHaveChildren (); + + virtual size_t + GetIndexOfChildWithName (const ConstString &name); + + virtual + ~LibcxxStdMapSyntheticFrontEnd (); + private: + bool + GetDataType(); + + void + GetValueOffset (const lldb::ValueObjectSP& node); + + ValueObject* m_tree; + ValueObject* m_root_node; + ClangASTType m_element_type; + uint32_t m_skip_size; + size_t m_count; + std::map<size_t,lldb::ValueObjectSP> m_children; + }; + } +} + class MapEntry { public: MapEntry () {} - MapEntry (ValueObjectSP entry_sp) : m_entry_sp(entry_sp) {} + explicit MapEntry (ValueObjectSP entry_sp) : m_entry_sp(entry_sp) {} MapEntry (const MapEntry& rhs) : m_entry_sp(rhs.m_entry_sp) {} - MapEntry (ValueObject* entry) : m_entry_sp(entry ? entry->GetSP() : ValueObjectSP()) {} + explicit MapEntry (ValueObject* entry) : m_entry_sp(entry ? entry->GetSP() : ValueObjectSP()) {} ValueObjectSP - left () + left () const { + static ConstString g_left("__left_"); if (!m_entry_sp) return m_entry_sp; - return m_entry_sp->GetChildMemberWithName(ConstString("__left_"), true); + return m_entry_sp->GetChildMemberWithName(g_left, true); } ValueObjectSP - right () + right () const { + static ConstString g_right("__right_"); if (!m_entry_sp) return m_entry_sp; - return m_entry_sp->GetChildMemberWithName(ConstString("__right_"), true); + return m_entry_sp->GetChildMemberWithName(g_right, true); } ValueObjectSP - parent () + parent () const { + static ConstString g_parent("__parent_"); if (!m_entry_sp) return m_entry_sp; - return m_entry_sp->GetChildMemberWithName(ConstString("__parent_"), true); + return m_entry_sp->GetChildMemberWithName(g_parent, true); } uint64_t - value () + value () const { if (!m_entry_sp) return 0; @@ -66,7 +110,7 @@ public: } bool - error () + error () const { if (!m_entry_sp) return true; @@ -74,13 +118,13 @@ public: } bool - null() + null() const { return (value() == 0); } ValueObjectSP - GetEntry () + GetEntry () const { return m_entry_sp; } @@ -119,27 +163,18 @@ public: ValueObjectSP advance (size_t count) { + ValueObjectSP fail(nullptr); if (m_error) - return lldb::ValueObjectSP(); - if (count == 0) - return m_entry.GetEntry(); - if (count == 1) - { - next (); - return m_entry.GetEntry(); - } + return fail; size_t steps = 0; while (count > 0) { - if (m_error) - return lldb::ValueObjectSP(); - next (); - count--; - if (m_entry.null()) - return lldb::ValueObjectSP(); - steps++; - if (steps > m_max_depth) - return lldb::ValueObjectSP(); + next(); + count--, steps++; + if (m_error || + m_entry.null() || + (steps > m_max_depth)) + return fail; } return m_entry.GetEntry(); } @@ -147,16 +182,39 @@ protected: void next () { - m_entry.SetEntry(increment(m_entry.GetEntry())); + if (m_entry.null()) + return; + MapEntry right(m_entry.right()); + if (right.null() == false) + { + m_entry = tree_min(std::move(right)); + return; + } + size_t steps = 0; + while (!is_left_child(m_entry)) + { + if (m_entry.error()) + { + m_error = true; + return; + } + m_entry.SetEntry(m_entry.parent()); + steps++; + if (steps > m_max_depth) + { + m_entry = MapEntry(); + return; + } + } + m_entry = MapEntry(m_entry.parent()); } private: - ValueObjectSP - tree_min (ValueObjectSP x_sp) + MapEntry + tree_min (MapEntry&& x) { - MapEntry x(x_sp); if (x.null()) - return ValueObjectSP(); + return MapEntry(); MapEntry left(x.left()); size_t steps = 0; while (left.null() == false) @@ -164,42 +222,20 @@ private: if (left.error()) { m_error = true; - return lldb::ValueObjectSP(); + return MapEntry(); } - x.SetEntry(left.GetEntry()); + x = left; left.SetEntry(x.left()); steps++; if (steps > m_max_depth) - return lldb::ValueObjectSP(); - } - return x.GetEntry(); - } - - ValueObjectSP - tree_max (ValueObjectSP x_sp) - { - MapEntry x(x_sp); - if (x.null()) - return ValueObjectSP(); - MapEntry right(x.right()); - size_t steps = 0; - while (right.null() == false) - { - if (right.error()) - return lldb::ValueObjectSP(); - x.SetEntry(right.GetEntry()); - right.SetEntry(x.right()); - steps++; - if (steps > m_max_depth) - return lldb::ValueObjectSP(); + return MapEntry(); } - return x.GetEntry(); + return x; } - + bool - is_left_child (ValueObjectSP x_sp) + is_left_child (const MapEntry& x) { - MapEntry x(x_sp); if (x.null()) return false; MapEntry rhs(x.parent()); @@ -207,31 +243,6 @@ private: return x.value() == rhs.value(); } - ValueObjectSP - increment (ValueObjectSP x_sp) - { - MapEntry node(x_sp); - if (node.null()) - return ValueObjectSP(); - MapEntry right(node.right()); - if (right.null() == false) - return tree_min(right.GetEntry()); - size_t steps = 0; - while (!is_left_child(node.GetEntry())) - { - if (node.error()) - { - m_error = true; - return lldb::ValueObjectSP(); - } - node.SetEntry(node.parent()); - steps++; - if (steps > m_max_depth) - return lldb::ValueObjectSP(); - } - return node.parent(); - } - MapEntry m_entry; size_t m_max_depth; bool m_error; @@ -302,6 +313,10 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetValueOffset (const l lldb::ValueObjectSP lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex (size_t idx) { + static ConstString g___cc("__cc"); + static ConstString g___nc("__nc"); + + if (idx >= CalculateNumChildren()) return lldb::ValueObjectSP(); if (m_tree == NULL || m_root_node == NULL) @@ -375,7 +390,31 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex (size_t } StreamString name; name.Printf("[%" PRIu64 "]", (uint64_t)idx); - return (m_children[idx] = ValueObject::CreateValueObjectFromData(name.GetData(), data, m_backend.GetExecutionContextRef(), m_element_type)); + auto potential_child_sp = CreateValueObjectFromData(name.GetData(), data, m_backend.GetExecutionContextRef(), m_element_type); + if (potential_child_sp) + { + switch (potential_child_sp->GetNumChildren()) + { + case 1: + { + auto child0_sp = potential_child_sp->GetChildAtIndex(0, true); + if (child0_sp && child0_sp->GetName() == g___cc) + potential_child_sp = child0_sp; + break; + } + case 2: + { + auto child0_sp = potential_child_sp->GetChildAtIndex(0, true); + auto child1_sp = potential_child_sp->GetChildAtIndex(1, true); + if (child0_sp && child0_sp->GetName() == g___cc && + child1_sp && child1_sp->GetName() == g___nc) + potential_child_sp = child0_sp; + break; + } + } + potential_child_sp->SetName(ConstString(name.GetData())); + } + return (m_children[idx] = potential_child_sp); } bool |