blob: 71fabe0dfc0a2bbb07c77dda854435ed64df4639 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBValueList.cpp -----------------------------------------*- C++ -*-===//
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
10
11#include "lldb/API/SBValueList.h"
12#include "lldb/API/SBValue.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000013#include "lldb/API/SBStream.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000014#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include "lldb/Core/ValueObjectList.h"
16
Enrico Granata85425d72013-02-07 18:23:56 +000017#include <vector>
18
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019using namespace lldb;
20using namespace lldb_private;
21
Enrico Granata19f0e8c2013-04-22 22:57:56 +000022class ValueListImpl
23{
24public:
25 ValueListImpl () :
26 m_values()
Enrico Granata85425d72013-02-07 18:23:56 +000027 {
Enrico Granata19f0e8c2013-04-22 22:57:56 +000028 }
29
30 ValueListImpl (const ValueListImpl& rhs) :
31 m_values(rhs.m_values)
32 {
33 }
34
35 ValueListImpl&
36 operator = (const ValueListImpl& rhs)
37 {
38 if (this == &rhs)
Enrico Granata85425d72013-02-07 18:23:56 +000039 return *this;
Enrico Granata19f0e8c2013-04-22 22:57:56 +000040 m_values = rhs.m_values;
41 return *this;
Enrico Granata85425d72013-02-07 18:23:56 +000042 };
Enrico Granata19f0e8c2013-04-22 22:57:56 +000043
44 uint32_t
45 GetSize ()
46 {
47 return m_values.size();
48 }
49
50 void
51 Append (const lldb::SBValue& sb_value)
52 {
53 m_values.push_back(sb_value);
54 }
55
56 void
57 Append (const ValueListImpl& list)
58 {
59 for (auto val : list.m_values)
60 Append (val);
61 }
62
63 lldb::SBValue
64 GetValueAtIndex (uint32_t index)
65 {
66 if (index >= GetSize())
67 return lldb::SBValue();
68 return m_values[index];
69 }
70
71 lldb::SBValue
72 FindValueByUID (lldb::user_id_t uid)
73 {
74 for (auto val : m_values)
75 {
76 if (val.IsValid() && val.GetID() == uid)
77 return val;
78 }
79 return lldb::SBValue();
80 }
Enrico Granatae9a09c72014-11-21 21:45:03 +000081
82 lldb::SBValue
Enrico Granata49a67462014-11-21 22:23:08 +000083 GetFirstValueByName (const char* name) const
Enrico Granatae9a09c72014-11-21 21:45:03 +000084 {
85 if (name)
86 {
87 for (auto val : m_values)
88 {
89 if (val.IsValid() && val.GetName() &&
90 strcmp(name,val.GetName()) == 0)
91 return val;
92 }
93 }
94 return lldb::SBValue();
95 }
Enrico Granata85425d72013-02-07 18:23:56 +000096
Enrico Granata19f0e8c2013-04-22 22:57:56 +000097private:
98 std::vector<lldb::SBValue> m_values;
99};
Enrico Granata85425d72013-02-07 18:23:56 +0000100
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101SBValueList::SBValueList () :
Greg Clayton66111032010-06-23 01:19:29 +0000102 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103{
104}
105
106SBValueList::SBValueList (const SBValueList &rhs) :
Greg Clayton66111032010-06-23 01:19:29 +0000107 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108{
Greg Clayton5160ce52013-03-27 23:08:40 +0000109 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000110
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111 if (rhs.IsValid())
Enrico Granata85425d72013-02-07 18:23:56 +0000112 m_opaque_ap.reset (new ValueListImpl (*rhs));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000113
114 if (log)
115 {
Caroline Tice750cd172010-10-26 23:49:36 +0000116 log->Printf ("SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000117 static_cast<void*>(rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL),
118 static_cast<void*>(m_opaque_ap.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000119 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000120}
121
Enrico Granata85425d72013-02-07 18:23:56 +0000122SBValueList::SBValueList (const ValueListImpl *lldb_object_ptr) :
Greg Clayton66111032010-06-23 01:19:29 +0000123 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124{
Greg Clayton5160ce52013-03-27 23:08:40 +0000125 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000126
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000127 if (lldb_object_ptr)
Enrico Granata85425d72013-02-07 18:23:56 +0000128 m_opaque_ap.reset (new ValueListImpl (*lldb_object_ptr));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000129
130 if (log)
131 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000132 log->Printf ("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p",
133 static_cast<const void*>(lldb_object_ptr),
134 static_cast<void*>(m_opaque_ap.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000135 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136}
137
138SBValueList::~SBValueList ()
139{
140}
141
142bool
143SBValueList::IsValid () const
144{
Greg Clayton66111032010-06-23 01:19:29 +0000145 return (m_opaque_ap.get() != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146}
147
Jim Ingham5d3bca42011-12-19 20:39:44 +0000148void
149SBValueList::Clear()
150{
151 m_opaque_ap.reset();
152}
153
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000154const SBValueList &
155SBValueList::operator = (const SBValueList &rhs)
156{
157 if (this != &rhs)
158 {
159 if (rhs.IsValid())
Enrico Granata85425d72013-02-07 18:23:56 +0000160 m_opaque_ap.reset (new ValueListImpl (*rhs));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161 else
Greg Clayton66111032010-06-23 01:19:29 +0000162 m_opaque_ap.reset ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163 }
164 return *this;
165}
166
Enrico Granata85425d72013-02-07 18:23:56 +0000167ValueListImpl *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168SBValueList::operator->()
169{
Greg Clayton66111032010-06-23 01:19:29 +0000170 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000171}
172
Enrico Granata85425d72013-02-07 18:23:56 +0000173ValueListImpl &
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174SBValueList::operator*()
175{
Greg Clayton66111032010-06-23 01:19:29 +0000176 return *m_opaque_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177}
178
Enrico Granata85425d72013-02-07 18:23:56 +0000179const ValueListImpl *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000180SBValueList::operator->() const
181{
Greg Clayton66111032010-06-23 01:19:29 +0000182 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000183}
184
Enrico Granata85425d72013-02-07 18:23:56 +0000185const ValueListImpl &
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186SBValueList::operator*() const
187{
Greg Clayton66111032010-06-23 01:19:29 +0000188 return *m_opaque_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189}
190
191void
192SBValueList::Append (const SBValue &val_obj)
193{
Enrico Granata85425d72013-02-07 18:23:56 +0000194 CreateIfNeeded ();
195 m_opaque_ap->Append (val_obj);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000196}
197
198void
199SBValueList::Append (lldb::ValueObjectSP& val_obj_sp)
200{
201 if (val_obj_sp)
202 {
203 CreateIfNeeded ();
Enrico Granata85425d72013-02-07 18:23:56 +0000204 m_opaque_ap->Append (SBValue(val_obj_sp));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205 }
206}
207
Greg Claytondea8cb42011-06-29 22:09:02 +0000208void
209SBValueList::Append (const lldb::SBValueList& value_list)
210{
211 if (value_list.IsValid())
212 {
213 CreateIfNeeded ();
214 m_opaque_ap->Append (*value_list);
215 }
216}
217
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000218
219SBValue
220SBValueList::GetValueAtIndex (uint32_t idx) const
221{
Greg Clayton5160ce52013-03-27 23:08:40 +0000222 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000223
Caroline Tice750cd172010-10-26 23:49:36 +0000224 //if (log)
225 // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000226
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227 SBValue sb_value;
Greg Clayton66111032010-06-23 01:19:29 +0000228 if (m_opaque_ap.get())
Enrico Granata85425d72013-02-07 18:23:56 +0000229 sb_value = m_opaque_ap->GetValueAtIndex (idx);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000230
231 if (log)
232 {
233 SBStream sstr;
234 sb_value.GetDescription (sstr);
Caroline Tice750cd172010-10-26 23:49:36 +0000235 log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000236 static_cast<void*>(m_opaque_ap.get()), idx,
237 static_cast<void*>(sb_value.GetSP().get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000238 }
239
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240 return sb_value;
241}
242
243uint32_t
244SBValueList::GetSize () const
245{
Greg Clayton5160ce52013-03-27 23:08:40 +0000246 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000247
Caroline Tice750cd172010-10-26 23:49:36 +0000248 //if (log)
249 // log->Printf ("SBValueList::GetSize ()");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000250
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000251 uint32_t size = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000252 if (m_opaque_ap.get())
253 size = m_opaque_ap->GetSize();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000254
255 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000256 log->Printf ("SBValueList::GetSize (this.ap=%p) => %d",
257 static_cast<void*>(m_opaque_ap.get()), size);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000258
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000259 return size;
260}
261
262void
263SBValueList::CreateIfNeeded ()
264{
Greg Clayton66111032010-06-23 01:19:29 +0000265 if (m_opaque_ap.get() == NULL)
Enrico Granata85425d72013-02-07 18:23:56 +0000266 m_opaque_ap.reset (new ValueListImpl());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000267}
268
269
270SBValue
271SBValueList::FindValueObjectByUID (lldb::user_id_t uid)
272{
273 SBValue sb_value;
Greg Claytonaf67cec2010-12-20 20:49:23 +0000274 if (m_opaque_ap.get())
Enrico Granata85425d72013-02-07 18:23:56 +0000275 sb_value = m_opaque_ap->FindValueByUID(uid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276 return sb_value;
277}
278
Enrico Granatae9a09c72014-11-21 21:45:03 +0000279SBValue
Enrico Granata49a67462014-11-21 22:23:08 +0000280SBValueList::GetFirstValueByName (const char* name) const
Enrico Granatae9a09c72014-11-21 21:45:03 +0000281{
282 SBValue sb_value;
283 if (m_opaque_ap.get())
Enrico Granata49a67462014-11-21 22:23:08 +0000284 sb_value = m_opaque_ap->GetFirstValueByName(name);
Enrico Granatae9a09c72014-11-21 21:45:03 +0000285 return sb_value;
286}
287
Enrico Granatad96f0682013-02-07 22:22:27 +0000288void *
Enrico Granata08ec0b62013-02-07 22:57:46 +0000289SBValueList::opaque_ptr ()
Caroline Tice750cd172010-10-26 23:49:36 +0000290{
291 return m_opaque_ap.get();
292}
293
Enrico Granata85425d72013-02-07 18:23:56 +0000294ValueListImpl &
Greg Claytondea8cb42011-06-29 22:09:02 +0000295SBValueList::ref ()
296{
297 CreateIfNeeded();
298 return *m_opaque_ap.get();
299}
300
301