blob: 5069ed3f5624daaa458dd14aa9c4364d3bc745f9 [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 Granata85425d72013-02-07 18:23:56 +000081
Enrico Granata19f0e8c2013-04-22 22:57:56 +000082private:
83 std::vector<lldb::SBValue> m_values;
84};
Enrico Granata85425d72013-02-07 18:23:56 +000085
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086SBValueList::SBValueList () :
Greg Clayton66111032010-06-23 01:19:29 +000087 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000088{
89}
90
91SBValueList::SBValueList (const SBValueList &rhs) :
Greg Clayton66111032010-06-23 01:19:29 +000092 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093{
Greg Clayton5160ce52013-03-27 23:08:40 +000094 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000095
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096 if (rhs.IsValid())
Enrico Granata85425d72013-02-07 18:23:56 +000097 m_opaque_ap.reset (new ValueListImpl (*rhs));
Caroline Ticeceb6b132010-10-26 03:11:13 +000098
99 if (log)
100 {
Caroline Tice750cd172010-10-26 23:49:36 +0000101 log->Printf ("SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000102 static_cast<void*>(rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL),
103 static_cast<void*>(m_opaque_ap.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000104 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105}
106
Enrico Granata85425d72013-02-07 18:23:56 +0000107SBValueList::SBValueList (const ValueListImpl *lldb_object_ptr) :
Greg Clayton66111032010-06-23 01:19:29 +0000108 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109{
Greg Clayton5160ce52013-03-27 23:08:40 +0000110 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000111
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112 if (lldb_object_ptr)
Enrico Granata85425d72013-02-07 18:23:56 +0000113 m_opaque_ap.reset (new ValueListImpl (*lldb_object_ptr));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000114
115 if (log)
116 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000117 log->Printf ("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p",
118 static_cast<const void*>(lldb_object_ptr),
119 static_cast<void*>(m_opaque_ap.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000120 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000121}
122
123SBValueList::~SBValueList ()
124{
125}
126
127bool
128SBValueList::IsValid () const
129{
Greg Clayton66111032010-06-23 01:19:29 +0000130 return (m_opaque_ap.get() != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131}
132
Jim Ingham5d3bca42011-12-19 20:39:44 +0000133void
134SBValueList::Clear()
135{
136 m_opaque_ap.reset();
137}
138
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000139const SBValueList &
140SBValueList::operator = (const SBValueList &rhs)
141{
142 if (this != &rhs)
143 {
144 if (rhs.IsValid())
Enrico Granata85425d72013-02-07 18:23:56 +0000145 m_opaque_ap.reset (new ValueListImpl (*rhs));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146 else
Greg Clayton66111032010-06-23 01:19:29 +0000147 m_opaque_ap.reset ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148 }
149 return *this;
150}
151
Enrico Granata85425d72013-02-07 18:23:56 +0000152ValueListImpl *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000153SBValueList::operator->()
154{
Greg Clayton66111032010-06-23 01:19:29 +0000155 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156}
157
Enrico Granata85425d72013-02-07 18:23:56 +0000158ValueListImpl &
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159SBValueList::operator*()
160{
Greg Clayton66111032010-06-23 01:19:29 +0000161 return *m_opaque_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162}
163
Enrico Granata85425d72013-02-07 18:23:56 +0000164const ValueListImpl *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165SBValueList::operator->() const
166{
Greg Clayton66111032010-06-23 01:19:29 +0000167 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168}
169
Enrico Granata85425d72013-02-07 18:23:56 +0000170const ValueListImpl &
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000171SBValueList::operator*() const
172{
Greg Clayton66111032010-06-23 01:19:29 +0000173 return *m_opaque_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174}
175
176void
177SBValueList::Append (const SBValue &val_obj)
178{
Enrico Granata85425d72013-02-07 18:23:56 +0000179 CreateIfNeeded ();
180 m_opaque_ap->Append (val_obj);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000181}
182
183void
184SBValueList::Append (lldb::ValueObjectSP& val_obj_sp)
185{
186 if (val_obj_sp)
187 {
188 CreateIfNeeded ();
Enrico Granata85425d72013-02-07 18:23:56 +0000189 m_opaque_ap->Append (SBValue(val_obj_sp));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000190 }
191}
192
Greg Claytondea8cb42011-06-29 22:09:02 +0000193void
194SBValueList::Append (const lldb::SBValueList& value_list)
195{
196 if (value_list.IsValid())
197 {
198 CreateIfNeeded ();
199 m_opaque_ap->Append (*value_list);
200 }
201}
202
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000203
204SBValue
205SBValueList::GetValueAtIndex (uint32_t idx) const
206{
Greg Clayton5160ce52013-03-27 23:08:40 +0000207 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000208
Caroline Tice750cd172010-10-26 23:49:36 +0000209 //if (log)
210 // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000211
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000212 SBValue sb_value;
Greg Clayton66111032010-06-23 01:19:29 +0000213 if (m_opaque_ap.get())
Enrico Granata85425d72013-02-07 18:23:56 +0000214 sb_value = m_opaque_ap->GetValueAtIndex (idx);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000215
216 if (log)
217 {
218 SBStream sstr;
219 sb_value.GetDescription (sstr);
Caroline Tice750cd172010-10-26 23:49:36 +0000220 log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000221 static_cast<void*>(m_opaque_ap.get()), idx,
222 static_cast<void*>(sb_value.GetSP().get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000223 }
224
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000225 return sb_value;
226}
227
228uint32_t
229SBValueList::GetSize () const
230{
Greg Clayton5160ce52013-03-27 23:08:40 +0000231 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000232
Caroline Tice750cd172010-10-26 23:49:36 +0000233 //if (log)
234 // log->Printf ("SBValueList::GetSize ()");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000235
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000236 uint32_t size = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000237 if (m_opaque_ap.get())
238 size = m_opaque_ap->GetSize();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000239
240 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000241 log->Printf ("SBValueList::GetSize (this.ap=%p) => %d",
242 static_cast<void*>(m_opaque_ap.get()), size);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000243
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000244 return size;
245}
246
247void
248SBValueList::CreateIfNeeded ()
249{
Greg Clayton66111032010-06-23 01:19:29 +0000250 if (m_opaque_ap.get() == NULL)
Enrico Granata85425d72013-02-07 18:23:56 +0000251 m_opaque_ap.reset (new ValueListImpl());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252}
253
254
255SBValue
256SBValueList::FindValueObjectByUID (lldb::user_id_t uid)
257{
258 SBValue sb_value;
Greg Claytonaf67cec2010-12-20 20:49:23 +0000259 if (m_opaque_ap.get())
Enrico Granata85425d72013-02-07 18:23:56 +0000260 sb_value = m_opaque_ap->FindValueByUID(uid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000261 return sb_value;
262}
263
Enrico Granatad96f0682013-02-07 22:22:27 +0000264void *
Enrico Granata08ec0b62013-02-07 22:57:46 +0000265SBValueList::opaque_ptr ()
Caroline Tice750cd172010-10-26 23:49:36 +0000266{
267 return m_opaque_ap.get();
268}
269
Enrico Granata85425d72013-02-07 18:23:56 +0000270ValueListImpl &
Greg Claytondea8cb42011-06-29 22:09:02 +0000271SBValueList::ref ()
272{
273 CreateIfNeeded();
274 return *m_opaque_ap.get();
275}
276
277