Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBValueList.cpp -----------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 9 | #include "lldb/API/SBValueList.h" |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 10 | #include "SBReproducerPrivate.h" |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBStream.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBValue.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Core/ValueObjectList.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 14 | #include "lldb/Utility/Log.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | |
Enrico Granata | 85425d7 | 2013-02-07 18:23:56 +0000 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | class ValueListImpl { |
Enrico Granata | 19f0e8c | 2013-04-22 22:57:56 +0000 | [diff] [blame] | 22 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | ValueListImpl() : m_values() {} |
| 24 | |
| 25 | ValueListImpl(const ValueListImpl &rhs) : m_values(rhs.m_values) {} |
| 26 | |
| 27 | ValueListImpl &operator=(const ValueListImpl &rhs) { |
| 28 | if (this == &rhs) |
| 29 | return *this; |
| 30 | m_values = rhs.m_values; |
| 31 | return *this; |
| 32 | } |
| 33 | |
| 34 | uint32_t GetSize() { return m_values.size(); } |
| 35 | |
| 36 | void Append(const lldb::SBValue &sb_value) { m_values.push_back(sb_value); } |
| 37 | |
| 38 | void Append(const ValueListImpl &list) { |
| 39 | for (auto val : list.m_values) |
| 40 | Append(val); |
| 41 | } |
| 42 | |
| 43 | lldb::SBValue GetValueAtIndex(uint32_t index) { |
| 44 | if (index >= GetSize()) |
| 45 | return lldb::SBValue(); |
| 46 | return m_values[index]; |
| 47 | } |
| 48 | |
| 49 | lldb::SBValue FindValueByUID(lldb::user_id_t uid) { |
| 50 | for (auto val : m_values) { |
| 51 | if (val.IsValid() && val.GetID() == uid) |
| 52 | return val; |
Enrico Granata | 19f0e8c | 2013-04-22 22:57:56 +0000 | [diff] [blame] | 53 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | return lldb::SBValue(); |
| 55 | } |
| 56 | |
| 57 | lldb::SBValue GetFirstValueByName(const char *name) const { |
| 58 | if (name) { |
| 59 | for (auto val : m_values) { |
| 60 | if (val.IsValid() && val.GetName() && strcmp(name, val.GetName()) == 0) |
| 61 | return val; |
| 62 | } |
Enrico Granata | 19f0e8c | 2013-04-22 22:57:56 +0000 | [diff] [blame] | 63 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | return lldb::SBValue(); |
| 65 | } |
Enrico Granata | 85425d7 | 2013-02-07 18:23:56 +0000 | [diff] [blame] | 66 | |
Enrico Granata | 19f0e8c | 2013-04-22 22:57:56 +0000 | [diff] [blame] | 67 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | std::vector<lldb::SBValue> m_values; |
Enrico Granata | 19f0e8c | 2013-04-22 22:57:56 +0000 | [diff] [blame] | 69 | }; |
Enrico Granata | 85425d7 | 2013-02-07 18:23:56 +0000 | [diff] [blame] | 70 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 71 | SBValueList::SBValueList() : m_opaque_up() { |
| 72 | LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBValueList); |
| 73 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 75 | SBValueList::SBValueList(const SBValueList &rhs) : m_opaque_up() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 76 | LLDB_RECORD_CONSTRUCTOR(SBValueList, (const lldb::SBValueList &), rhs); |
| 77 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 79 | |
| 80 | if (rhs.IsValid()) |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 81 | m_opaque_up.reset(new ValueListImpl(*rhs)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 82 | |
| 83 | if (log) { |
| 84 | log->Printf( |
| 85 | "SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p", |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 86 | static_cast<void *>(rhs.IsValid() ? rhs.m_opaque_up.get() : NULL), |
| 87 | static_cast<void *>(m_opaque_up.get())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 91 | SBValueList::SBValueList(const ValueListImpl *lldb_object_ptr) : m_opaque_up() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 93 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | if (lldb_object_ptr) |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 95 | m_opaque_up.reset(new ValueListImpl(*lldb_object_ptr)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | |
| 97 | if (log) { |
| 98 | log->Printf("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p", |
| 99 | static_cast<const void *>(lldb_object_ptr), |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 100 | static_cast<void *>(m_opaque_up.get())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
| 104 | SBValueList::~SBValueList() {} |
| 105 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 106 | bool SBValueList::IsValid() const { |
| 107 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBValueList, IsValid); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 108 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 109 | return (m_opaque_up != NULL); |
| 110 | } |
| 111 | |
| 112 | void SBValueList::Clear() { |
| 113 | LLDB_RECORD_METHOD_NO_ARGS(void, SBValueList, Clear); |
| 114 | |
| 115 | m_opaque_up.reset(); |
| 116 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 117 | |
| 118 | const SBValueList &SBValueList::operator=(const SBValueList &rhs) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 119 | LLDB_RECORD_METHOD(const lldb::SBValueList &, |
| 120 | SBValueList, operator=,(const lldb::SBValueList &), rhs); |
| 121 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 122 | if (this != &rhs) { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | if (rhs.IsValid()) |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 124 | m_opaque_up.reset(new ValueListImpl(*rhs)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 125 | else |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 126 | m_opaque_up.reset(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 127 | } |
| 128 | return *this; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 131 | ValueListImpl *SBValueList::operator->() { return m_opaque_up.get(); } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 132 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 133 | ValueListImpl &SBValueList::operator*() { return *m_opaque_up; } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 134 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 135 | const ValueListImpl *SBValueList::operator->() const { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 136 | return m_opaque_up.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 139 | const ValueListImpl &SBValueList::operator*() const { return *m_opaque_up; } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 140 | |
| 141 | void SBValueList::Append(const SBValue &val_obj) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 142 | LLDB_RECORD_METHOD(void, SBValueList, Append, (const lldb::SBValue &), |
| 143 | val_obj); |
| 144 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 145 | CreateIfNeeded(); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 146 | m_opaque_up->Append(val_obj); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 149 | void SBValueList::Append(lldb::ValueObjectSP &val_obj_sp) { |
| 150 | if (val_obj_sp) { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 151 | CreateIfNeeded(); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 152 | m_opaque_up->Append(SBValue(val_obj_sp)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
| 156 | void SBValueList::Append(const lldb::SBValueList &value_list) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 157 | LLDB_RECORD_METHOD(void, SBValueList, Append, (const lldb::SBValueList &), |
| 158 | value_list); |
| 159 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 160 | if (value_list.IsValid()) { |
| 161 | CreateIfNeeded(); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 162 | m_opaque_up->Append(*value_list); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | SBValue SBValueList::GetValueAtIndex(uint32_t idx) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 167 | LLDB_RECORD_METHOD_CONST(lldb::SBValue, SBValueList, GetValueAtIndex, |
| 168 | (uint32_t), idx); |
| 169 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 170 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 171 | |
| 172 | // if (log) |
| 173 | // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", |
| 174 | // idx); |
| 175 | |
| 176 | SBValue sb_value; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 177 | if (m_opaque_up) |
| 178 | sb_value = m_opaque_up->GetValueAtIndex(idx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 179 | |
| 180 | if (log) { |
| 181 | SBStream sstr; |
| 182 | sb_value.GetDescription(sstr); |
| 183 | log->Printf("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue " |
| 184 | "(this.sp = %p, '%s')", |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 185 | static_cast<void *>(m_opaque_up.get()), idx, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 186 | static_cast<void *>(sb_value.GetSP().get()), sstr.GetData()); |
| 187 | } |
| 188 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 189 | return LLDB_RECORD_RESULT(sb_value); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | uint32_t SBValueList::GetSize() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 193 | LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBValueList, GetSize); |
| 194 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 195 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 196 | |
| 197 | // if (log) |
| 198 | // log->Printf ("SBValueList::GetSize ()"); |
| 199 | |
| 200 | uint32_t size = 0; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 201 | if (m_opaque_up) |
| 202 | size = m_opaque_up->GetSize(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 203 | |
| 204 | if (log) |
| 205 | log->Printf("SBValueList::GetSize (this.ap=%p) => %d", |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 206 | static_cast<void *>(m_opaque_up.get()), size); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 207 | |
| 208 | return size; |
| 209 | } |
| 210 | |
| 211 | void SBValueList::CreateIfNeeded() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 212 | if (m_opaque_up == NULL) |
| 213 | m_opaque_up.reset(new ValueListImpl()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | SBValue SBValueList::FindValueObjectByUID(lldb::user_id_t uid) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 217 | LLDB_RECORD_METHOD(lldb::SBValue, SBValueList, FindValueObjectByUID, |
| 218 | (lldb::user_id_t), uid); |
| 219 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | SBValue sb_value; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 221 | if (m_opaque_up) |
| 222 | sb_value = m_opaque_up->FindValueByUID(uid); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 223 | return LLDB_RECORD_RESULT(sb_value); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | SBValue SBValueList::GetFirstValueByName(const char *name) const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 227 | LLDB_RECORD_METHOD_CONST(lldb::SBValue, SBValueList, GetFirstValueByName, |
| 228 | (const char *), name); |
| 229 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 230 | SBValue sb_value; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 231 | if (m_opaque_up) |
| 232 | sb_value = m_opaque_up->GetFirstValueByName(name); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 233 | return LLDB_RECORD_RESULT(sb_value); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 236 | void *SBValueList::opaque_ptr() { return m_opaque_up.get(); } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 237 | |
| 238 | ValueListImpl &SBValueList::ref() { |
| 239 | CreateIfNeeded(); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 240 | return *m_opaque_up; |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 241 | } |