Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 1 | //===-- LibCxxList.cpp ------------------------------------------*- C++ -*-===// |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
| 13 | // Project includes |
Enrico Granata | 33e97e6 | 2015-09-04 21:01:18 +0000 | [diff] [blame] | 14 | #include "LibCxx.h" |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 15 | |
| 16 | #include "lldb/Core/DataBufferHeap.h" |
| 17 | #include "lldb/Core/Error.h" |
| 18 | #include "lldb/Core/Stream.h" |
| 19 | #include "lldb/Core/ValueObject.h" |
| 20 | #include "lldb/Core/ValueObjectConstResult.h" |
Enrico Granata | 419d791 | 2015-09-04 00:33:51 +0000 | [diff] [blame] | 21 | #include "lldb/DataFormatters/FormattersHelpers.h" |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 22 | #include "lldb/Host/Endian.h" |
| 23 | #include "lldb/Symbol/ClangASTContext.h" |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Target.h" |
| 25 | |
| 26 | using namespace lldb; |
| 27 | using namespace lldb_private; |
| 28 | using namespace lldb_private::formatters; |
| 29 | |
| 30 | class MapEntry |
| 31 | { |
| 32 | public: |
Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 33 | MapEntry() = default; |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 34 | explicit MapEntry (ValueObjectSP entry_sp) : m_entry_sp(entry_sp) {} |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 35 | MapEntry(const MapEntry& rhs) = default; |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 36 | explicit MapEntry (ValueObject* entry) : m_entry_sp(entry ? entry->GetSP() : ValueObjectSP()) {} |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 37 | |
| 38 | ValueObjectSP |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 39 | left () const |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 40 | { |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 41 | static ConstString g_left("__left_"); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 42 | if (!m_entry_sp) |
| 43 | return m_entry_sp; |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 44 | return m_entry_sp->GetChildMemberWithName(g_left, true); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | ValueObjectSP |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 48 | right () const |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 49 | { |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 50 | static ConstString g_right("__right_"); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 51 | if (!m_entry_sp) |
| 52 | return m_entry_sp; |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 53 | return m_entry_sp->GetChildMemberWithName(g_right, true); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | ValueObjectSP |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 57 | parent () const |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 58 | { |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 59 | static ConstString g_parent("__parent_"); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 60 | if (!m_entry_sp) |
| 61 | return m_entry_sp; |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 62 | return m_entry_sp->GetChildMemberWithName(g_parent, true); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | uint64_t |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 66 | value () const |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 67 | { |
| 68 | if (!m_entry_sp) |
| 69 | return 0; |
| 70 | return m_entry_sp->GetValueAsUnsigned(0); |
| 71 | } |
| 72 | |
| 73 | bool |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 74 | error () const |
Enrico Granata | d03a273 | 2013-05-03 19:04:35 +0000 | [diff] [blame] | 75 | { |
Enrico Granata | 4ffff27 | 2013-05-03 19:07:20 +0000 | [diff] [blame] | 76 | if (!m_entry_sp) |
| 77 | return true; |
Enrico Granata | d03a273 | 2013-05-03 19:04:35 +0000 | [diff] [blame] | 78 | return m_entry_sp->GetError().Fail(); |
| 79 | } |
| 80 | |
| 81 | bool |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 82 | null() const |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 83 | { |
| 84 | return (value() == 0); |
| 85 | } |
| 86 | |
| 87 | ValueObjectSP |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 88 | GetEntry () const |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 89 | { |
| 90 | return m_entry_sp; |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | SetEntry (ValueObjectSP entry) |
| 95 | { |
| 96 | m_entry_sp = entry; |
| 97 | } |
| 98 | |
| 99 | bool |
| 100 | operator == (const MapEntry& rhs) const |
| 101 | { |
| 102 | return (rhs.m_entry_sp.get() == m_entry_sp.get()); |
| 103 | } |
| 104 | |
| 105 | private: |
| 106 | ValueObjectSP m_entry_sp; |
| 107 | }; |
| 108 | |
| 109 | class MapIterator |
| 110 | { |
| 111 | public: |
Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 112 | MapIterator() = default; |
Enrico Granata | d03a273 | 2013-05-03 19:04:35 +0000 | [diff] [blame] | 113 | MapIterator (MapEntry entry, size_t depth = 0) : m_entry(entry), m_max_depth(depth), m_error(false) {} |
| 114 | MapIterator (ValueObjectSP entry, size_t depth = 0) : m_entry(entry), m_max_depth(depth), m_error(false) {} |
| 115 | MapIterator (const MapIterator& rhs) : m_entry(rhs.m_entry),m_max_depth(rhs.m_max_depth), m_error(false) {} |
| 116 | MapIterator (ValueObject* entry, size_t depth = 0) : m_entry(entry), m_max_depth(depth), m_error(false) {} |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 117 | |
| 118 | ValueObjectSP |
| 119 | value () |
| 120 | { |
| 121 | return m_entry.GetEntry(); |
| 122 | } |
| 123 | |
| 124 | ValueObjectSP |
| 125 | advance (size_t count) |
| 126 | { |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 127 | ValueObjectSP fail; |
Enrico Granata | d03a273 | 2013-05-03 19:04:35 +0000 | [diff] [blame] | 128 | if (m_error) |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 129 | return fail; |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 130 | size_t steps = 0; |
| 131 | while (count > 0) |
| 132 | { |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 133 | next(); |
| 134 | count--, steps++; |
| 135 | if (m_error || |
| 136 | m_entry.null() || |
| 137 | (steps > m_max_depth)) |
| 138 | return fail; |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 139 | } |
| 140 | return m_entry.GetEntry(); |
| 141 | } |
Enrico Granata | a0b75d7 | 2015-12-04 22:25:52 +0000 | [diff] [blame] | 142 | |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 143 | protected: |
| 144 | void |
| 145 | next () |
| 146 | { |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 147 | if (m_entry.null()) |
| 148 | return; |
| 149 | MapEntry right(m_entry.right()); |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 150 | if (!right.null()) |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 151 | { |
| 152 | m_entry = tree_min(std::move(right)); |
| 153 | return; |
| 154 | } |
| 155 | size_t steps = 0; |
| 156 | while (!is_left_child(m_entry)) |
| 157 | { |
| 158 | if (m_entry.error()) |
| 159 | { |
| 160 | m_error = true; |
| 161 | return; |
| 162 | } |
| 163 | m_entry.SetEntry(m_entry.parent()); |
| 164 | steps++; |
| 165 | if (steps > m_max_depth) |
| 166 | { |
| 167 | m_entry = MapEntry(); |
| 168 | return; |
| 169 | } |
| 170 | } |
| 171 | m_entry = MapEntry(m_entry.parent()); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 172 | } |
Enrico Granata | a0b75d7 | 2015-12-04 22:25:52 +0000 | [diff] [blame] | 173 | |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 174 | private: |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 175 | MapEntry |
| 176 | tree_min (MapEntry&& x) |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 177 | { |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 178 | if (x.null()) |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 179 | return MapEntry(); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 180 | MapEntry left(x.left()); |
| 181 | size_t steps = 0; |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 182 | while (!left.null()) |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 183 | { |
Enrico Granata | d03a273 | 2013-05-03 19:04:35 +0000 | [diff] [blame] | 184 | if (left.error()) |
| 185 | { |
| 186 | m_error = true; |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 187 | return MapEntry(); |
Enrico Granata | d03a273 | 2013-05-03 19:04:35 +0000 | [diff] [blame] | 188 | } |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 189 | x = left; |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 190 | left.SetEntry(x.left()); |
| 191 | steps++; |
| 192 | if (steps > m_max_depth) |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 193 | return MapEntry(); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 194 | } |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 195 | return x; |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 196 | } |
Enrico Granata | a0b75d7 | 2015-12-04 22:25:52 +0000 | [diff] [blame] | 197 | |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 198 | bool |
Enrico Granata | 395939a | 2014-12-16 21:28:16 +0000 | [diff] [blame] | 199 | is_left_child (const MapEntry& x) |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 200 | { |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 201 | if (x.null()) |
| 202 | return false; |
| 203 | MapEntry rhs(x.parent()); |
| 204 | rhs.SetEntry(rhs.left()); |
| 205 | return x.value() == rhs.value(); |
| 206 | } |
| 207 | |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 208 | MapEntry m_entry; |
| 209 | size_t m_max_depth; |
Enrico Granata | d03a273 | 2013-05-03 19:04:35 +0000 | [diff] [blame] | 210 | bool m_error; |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 211 | }; |
| 212 | |
Enrico Granata | a0b75d7 | 2015-12-04 22:25:52 +0000 | [diff] [blame] | 213 | namespace lldb_private { |
| 214 | namespace formatters { |
| 215 | class LibcxxStdMapSyntheticFrontEnd : public SyntheticChildrenFrontEnd |
| 216 | { |
| 217 | public: |
| 218 | LibcxxStdMapSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp); |
| 219 | |
| 220 | ~LibcxxStdMapSyntheticFrontEnd() override = default; |
| 221 | |
| 222 | size_t |
| 223 | CalculateNumChildren() override; |
| 224 | |
| 225 | lldb::ValueObjectSP |
| 226 | GetChildAtIndex(size_t idx) override; |
| 227 | |
| 228 | bool |
| 229 | Update() override; |
| 230 | |
| 231 | bool |
| 232 | MightHaveChildren() override; |
| 233 | |
| 234 | size_t |
| 235 | GetIndexOfChildWithName(const ConstString &name) override; |
| 236 | |
| 237 | private: |
| 238 | bool |
| 239 | GetDataType(); |
| 240 | |
| 241 | void |
| 242 | GetValueOffset (const lldb::ValueObjectSP& node); |
| 243 | |
| 244 | ValueObject* m_tree; |
| 245 | ValueObject* m_root_node; |
| 246 | CompilerType m_element_type; |
| 247 | uint32_t m_skip_size; |
| 248 | size_t m_count; |
Enrico Granata | a0b75d7 | 2015-12-04 22:25:52 +0000 | [diff] [blame] | 249 | std::map<size_t, MapIterator> m_iterators; |
| 250 | }; |
| 251 | } // namespace formatters |
| 252 | } // namespace lldb_private |
| 253 | |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 254 | lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::LibcxxStdMapSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) : |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 255 | SyntheticChildrenFrontEnd(*valobj_sp), |
| 256 | m_tree(nullptr), |
| 257 | m_root_node(nullptr), |
| 258 | m_element_type(), |
| 259 | m_skip_size(UINT32_MAX), |
| 260 | m_count(UINT32_MAX), |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 261 | m_iterators() |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 262 | { |
| 263 | if (valobj_sp) |
| 264 | Update(); |
| 265 | } |
| 266 | |
| 267 | size_t |
| 268 | lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::CalculateNumChildren () |
| 269 | { |
Enrico Granata | 4c2bf56 | 2015-12-04 22:49:27 +0000 | [diff] [blame] | 270 | static ConstString g___pair3_("__pair3_"); |
| 271 | static ConstString g___first_("__first_"); |
| 272 | |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 273 | if (m_count != UINT32_MAX) |
| 274 | return m_count; |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 275 | if (m_tree == nullptr) |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 276 | return 0; |
Enrico Granata | 4c2bf56 | 2015-12-04 22:49:27 +0000 | [diff] [blame] | 277 | ValueObjectSP m_item(m_tree->GetChildMemberWithName(g___pair3_, true)); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 278 | if (!m_item) |
| 279 | return 0; |
Enrico Granata | 4c2bf56 | 2015-12-04 22:49:27 +0000 | [diff] [blame] | 280 | m_item = m_item->GetChildMemberWithName(g___first_, true); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 281 | if (!m_item) |
| 282 | return 0; |
| 283 | m_count = m_item->GetValueAsUnsigned(0); |
| 284 | return m_count; |
| 285 | } |
| 286 | |
| 287 | bool |
| 288 | lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetDataType() |
| 289 | { |
Enrico Granata | 4c2bf56 | 2015-12-04 22:49:27 +0000 | [diff] [blame] | 290 | static ConstString g___value_("__value_"); |
| 291 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 292 | if (m_element_type.GetOpaqueQualType() && m_element_type.GetTypeSystem()) |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 293 | return true; |
| 294 | m_element_type.Clear(); |
| 295 | ValueObjectSP deref; |
| 296 | Error error; |
| 297 | deref = m_root_node->Dereference(error); |
| 298 | if (!deref || error.Fail()) |
| 299 | return false; |
Enrico Granata | 4c2bf56 | 2015-12-04 22:49:27 +0000 | [diff] [blame] | 300 | deref = deref->GetChildMemberWithName(g___value_, true); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 301 | if (!deref) |
| 302 | return false; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 303 | m_element_type = deref->GetCompilerType(); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 304 | return true; |
| 305 | } |
| 306 | |
| 307 | void |
| 308 | lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetValueOffset (const lldb::ValueObjectSP& node) |
| 309 | { |
| 310 | if (m_skip_size != UINT32_MAX) |
| 311 | return; |
| 312 | if (!node) |
| 313 | return; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 314 | CompilerType node_type(node->GetCompilerType()); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 315 | uint64_t bit_offset; |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 316 | if (node_type.GetIndexOfFieldWithName("__value_", nullptr, &bit_offset) == UINT32_MAX) |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 317 | return; |
| 318 | m_skip_size = bit_offset / 8u; |
| 319 | } |
| 320 | |
| 321 | lldb::ValueObjectSP |
| 322 | lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex (size_t idx) |
| 323 | { |
Enrico Granata | 340fa53 | 2014-09-12 00:55:37 +0000 | [diff] [blame] | 324 | static ConstString g___cc("__cc"); |
| 325 | static ConstString g___nc("__nc"); |
Enrico Granata | 4c2bf56 | 2015-12-04 22:49:27 +0000 | [diff] [blame] | 326 | static ConstString g___value_("__value_"); |
Enrico Granata | 340fa53 | 2014-09-12 00:55:37 +0000 | [diff] [blame] | 327 | |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 328 | if (idx >= CalculateNumChildren()) |
| 329 | return lldb::ValueObjectSP(); |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 330 | if (m_tree == nullptr || m_root_node == nullptr) |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 331 | return lldb::ValueObjectSP(); |
| 332 | |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 333 | MapIterator iterator(m_root_node, CalculateNumChildren()); |
Enrico Granata | a0b75d7 | 2015-12-04 22:25:52 +0000 | [diff] [blame] | 334 | |
| 335 | const bool need_to_skip = (idx > 0); |
| 336 | size_t actual_advancde = idx; |
| 337 | if (need_to_skip) |
| 338 | { |
| 339 | auto cached_iterator = m_iterators.find(idx-1); |
| 340 | if (cached_iterator != m_iterators.end()) |
| 341 | { |
| 342 | iterator = cached_iterator->second; |
| 343 | actual_advancde = 1; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | ValueObjectSP iterated_sp(iterator.advance(actual_advancde)); |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 348 | if (!iterated_sp) |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 349 | { |
| 350 | // this tree is garbage - stop |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 351 | m_tree = nullptr; // this will stop all future searches until an Update() happens |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 352 | return iterated_sp; |
| 353 | } |
| 354 | if (GetDataType()) |
| 355 | { |
| 356 | if (!need_to_skip) |
| 357 | { |
| 358 | Error error; |
| 359 | iterated_sp = iterated_sp->Dereference(error); |
| 360 | if (!iterated_sp || error.Fail()) |
| 361 | { |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 362 | m_tree = nullptr; |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 363 | return lldb::ValueObjectSP(); |
| 364 | } |
| 365 | GetValueOffset(iterated_sp); |
Enrico Granata | 4c2bf56 | 2015-12-04 22:49:27 +0000 | [diff] [blame] | 366 | iterated_sp = iterated_sp->GetChildMemberWithName(g___value_, true); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 367 | if (!iterated_sp) |
| 368 | { |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 369 | m_tree = nullptr; |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 370 | return lldb::ValueObjectSP(); |
| 371 | } |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | // because of the way our debug info is made, we need to read item 0 first |
| 376 | // so that we can cache information used to generate other elements |
| 377 | if (m_skip_size == UINT32_MAX) |
| 378 | GetChildAtIndex(0); |
| 379 | if (m_skip_size == UINT32_MAX) |
| 380 | { |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 381 | m_tree = nullptr; |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 382 | return lldb::ValueObjectSP(); |
| 383 | } |
| 384 | iterated_sp = iterated_sp->GetSyntheticChildAtOffset(m_skip_size, m_element_type, true); |
| 385 | if (!iterated_sp) |
| 386 | { |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 387 | m_tree = nullptr; |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 388 | return lldb::ValueObjectSP(); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | else |
| 393 | { |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 394 | m_tree = nullptr; |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 395 | return lldb::ValueObjectSP(); |
| 396 | } |
| 397 | // at this point we have a valid |
| 398 | // we need to copy current_sp into a new object otherwise we will end up with all items named __value_ |
| 399 | DataExtractor data; |
Sean Callanan | 866e91c | 2014-02-28 22:27:53 +0000 | [diff] [blame] | 400 | Error error; |
| 401 | iterated_sp->GetData(data, error); |
| 402 | if (error.Fail()) |
| 403 | { |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 404 | m_tree = nullptr; |
Sean Callanan | 866e91c | 2014-02-28 22:27:53 +0000 | [diff] [blame] | 405 | return lldb::ValueObjectSP(); |
| 406 | } |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 407 | StreamString name; |
Deepak Panickal | 99fbc07 | 2014-03-03 15:39:47 +0000 | [diff] [blame] | 408 | name.Printf("[%" PRIu64 "]", (uint64_t)idx); |
Enrico Granata | e29df23 | 2014-12-09 19:51:20 +0000 | [diff] [blame] | 409 | auto potential_child_sp = CreateValueObjectFromData(name.GetData(), data, m_backend.GetExecutionContextRef(), m_element_type); |
Enrico Granata | 340fa53 | 2014-09-12 00:55:37 +0000 | [diff] [blame] | 410 | if (potential_child_sp) |
| 411 | { |
| 412 | switch (potential_child_sp->GetNumChildren()) |
| 413 | { |
| 414 | case 1: |
| 415 | { |
| 416 | auto child0_sp = potential_child_sp->GetChildAtIndex(0, true); |
| 417 | if (child0_sp && child0_sp->GetName() == g___cc) |
| 418 | potential_child_sp = child0_sp; |
| 419 | break; |
| 420 | } |
| 421 | case 2: |
| 422 | { |
| 423 | auto child0_sp = potential_child_sp->GetChildAtIndex(0, true); |
| 424 | auto child1_sp = potential_child_sp->GetChildAtIndex(1, true); |
| 425 | if (child0_sp && child0_sp->GetName() == g___cc && |
| 426 | child1_sp && child1_sp->GetName() == g___nc) |
| 427 | potential_child_sp = child0_sp; |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | potential_child_sp->SetName(ConstString(name.GetData())); |
| 432 | } |
Enrico Granata | a0b75d7 | 2015-12-04 22:25:52 +0000 | [diff] [blame] | 433 | m_iterators[idx] = iterator; |
Enrico Granata | 106aae5 | 2016-07-06 21:24:28 +0000 | [diff] [blame] | 434 | return potential_child_sp; |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | bool |
| 438 | lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::Update() |
| 439 | { |
Enrico Granata | 4c2bf56 | 2015-12-04 22:49:27 +0000 | [diff] [blame] | 440 | static ConstString g___tree_("__tree_"); |
| 441 | static ConstString g___begin_node_("__begin_node_"); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 442 | m_count = UINT32_MAX; |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 443 | m_tree = m_root_node = nullptr; |
Enrico Granata | a0b75d7 | 2015-12-04 22:25:52 +0000 | [diff] [blame] | 444 | m_iterators.clear(); |
Enrico Granata | 4c2bf56 | 2015-12-04 22:49:27 +0000 | [diff] [blame] | 445 | m_tree = m_backend.GetChildMemberWithName(g___tree_, true).get(); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 446 | if (!m_tree) |
Matt Kopec | ef14371 | 2013-06-03 18:00:07 +0000 | [diff] [blame] | 447 | return false; |
Enrico Granata | 4c2bf56 | 2015-12-04 22:49:27 +0000 | [diff] [blame] | 448 | m_root_node = m_tree->GetChildMemberWithName(g___begin_node_, true).get(); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 449 | return false; |
| 450 | } |
| 451 | |
| 452 | bool |
| 453 | lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::MightHaveChildren () |
| 454 | { |
| 455 | return true; |
| 456 | } |
| 457 | |
| 458 | size_t |
| 459 | lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name) |
| 460 | { |
| 461 | return ExtractIndexFromString(name.GetCString()); |
| 462 | } |
| 463 | |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 464 | SyntheticChildrenFrontEnd* |
| 465 | lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp) |
| 466 | { |
Eugene Zelenko | bbd1681 | 2016-02-29 19:41:30 +0000 | [diff] [blame] | 467 | return (valobj_sp ? new LibcxxStdMapSyntheticFrontEnd(valobj_sp) : nullptr); |
Enrico Granata | 9237353 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 468 | } |