blob: 46866eb374242f872f06bdaa14d334f75419a234 [file] [log] [blame]
Chris Lattner24943d22010-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 Tice7826c882010-10-26 03:11:13 +000013#include "lldb/API/SBStream.h"
Caroline Tice7826c882010-10-26 03:11:13 +000014#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015#include "lldb/Core/ValueObjectList.h"
16
Enrico Granata5c1700a2013-02-07 18:23:56 +000017#include <vector>
18
Chris Lattner24943d22010-06-08 16:52:24 +000019using namespace lldb;
20using namespace lldb_private;
21
Enrico Granatabf26ea62013-04-22 22:57:56 +000022class ValueListImpl
23{
24public:
25 ValueListImpl () :
26 m_values()
Enrico Granata5c1700a2013-02-07 18:23:56 +000027 {
Enrico Granatabf26ea62013-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 Granata5c1700a2013-02-07 18:23:56 +000039 return *this;
Enrico Granatabf26ea62013-04-22 22:57:56 +000040 m_values = rhs.m_values;
41 return *this;
Enrico Granata5c1700a2013-02-07 18:23:56 +000042 };
Enrico Granatabf26ea62013-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 Granata5c1700a2013-02-07 18:23:56 +000081
Enrico Granatabf26ea62013-04-22 22:57:56 +000082private:
83 std::vector<lldb::SBValue> m_values;
84};
Enrico Granata5c1700a2013-02-07 18:23:56 +000085
Chris Lattner24943d22010-06-08 16:52:24 +000086SBValueList::SBValueList () :
Greg Clayton63094e02010-06-23 01:19:29 +000087 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000088{
89}
90
91SBValueList::SBValueList (const SBValueList &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000092 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000093{
Greg Clayton952e9dc2013-03-27 23:08:40 +000094 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000095
Chris Lattner24943d22010-06-08 16:52:24 +000096 if (rhs.IsValid())
Enrico Granata5c1700a2013-02-07 18:23:56 +000097 m_opaque_ap.reset (new ValueListImpl (*rhs));
Caroline Tice7826c882010-10-26 03:11:13 +000098
99 if (log)
100 {
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000101 log->Printf ("SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p",
Greg Claytonbdcda462010-12-20 20:49:23 +0000102 (rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL),
103 m_opaque_ap.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000104 }
Chris Lattner24943d22010-06-08 16:52:24 +0000105}
106
Enrico Granata5c1700a2013-02-07 18:23:56 +0000107SBValueList::SBValueList (const ValueListImpl *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +0000108 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +0000109{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000110 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000111
Chris Lattner24943d22010-06-08 16:52:24 +0000112 if (lldb_object_ptr)
Enrico Granata5c1700a2013-02-07 18:23:56 +0000113 m_opaque_ap.reset (new ValueListImpl (*lldb_object_ptr));
Caroline Tice7826c882010-10-26 03:11:13 +0000114
115 if (log)
116 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000117 log->Printf ("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p",
118 lldb_object_ptr,
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000119 m_opaque_ap.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000120 }
Chris Lattner24943d22010-06-08 16:52:24 +0000121}
122
123SBValueList::~SBValueList ()
124{
125}
126
127bool
128SBValueList::IsValid () const
129{
Greg Clayton63094e02010-06-23 01:19:29 +0000130 return (m_opaque_ap.get() != NULL);
Chris Lattner24943d22010-06-08 16:52:24 +0000131}
132
Jim Inghame0bd5712011-12-19 20:39:44 +0000133void
134SBValueList::Clear()
135{
136 m_opaque_ap.reset();
137}
138
Chris Lattner24943d22010-06-08 16:52:24 +0000139const SBValueList &
140SBValueList::operator = (const SBValueList &rhs)
141{
142 if (this != &rhs)
143 {
144 if (rhs.IsValid())
Enrico Granata5c1700a2013-02-07 18:23:56 +0000145 m_opaque_ap.reset (new ValueListImpl (*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +0000146 else
Greg Clayton63094e02010-06-23 01:19:29 +0000147 m_opaque_ap.reset ();
Chris Lattner24943d22010-06-08 16:52:24 +0000148 }
149 return *this;
150}
151
Enrico Granata5c1700a2013-02-07 18:23:56 +0000152ValueListImpl *
Chris Lattner24943d22010-06-08 16:52:24 +0000153SBValueList::operator->()
154{
Greg Clayton63094e02010-06-23 01:19:29 +0000155 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000156}
157
Enrico Granata5c1700a2013-02-07 18:23:56 +0000158ValueListImpl &
Chris Lattner24943d22010-06-08 16:52:24 +0000159SBValueList::operator*()
160{
Greg Clayton63094e02010-06-23 01:19:29 +0000161 return *m_opaque_ap;
Chris Lattner24943d22010-06-08 16:52:24 +0000162}
163
Enrico Granata5c1700a2013-02-07 18:23:56 +0000164const ValueListImpl *
Chris Lattner24943d22010-06-08 16:52:24 +0000165SBValueList::operator->() const
166{
Greg Clayton63094e02010-06-23 01:19:29 +0000167 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000168}
169
Enrico Granata5c1700a2013-02-07 18:23:56 +0000170const ValueListImpl &
Chris Lattner24943d22010-06-08 16:52:24 +0000171SBValueList::operator*() const
172{
Greg Clayton63094e02010-06-23 01:19:29 +0000173 return *m_opaque_ap;
Chris Lattner24943d22010-06-08 16:52:24 +0000174}
175
176void
177SBValueList::Append (const SBValue &val_obj)
178{
Enrico Granata5c1700a2013-02-07 18:23:56 +0000179 CreateIfNeeded ();
180 m_opaque_ap->Append (val_obj);
Chris Lattner24943d22010-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 Granata5c1700a2013-02-07 18:23:56 +0000189 m_opaque_ap->Append (SBValue(val_obj_sp));
Chris Lattner24943d22010-06-08 16:52:24 +0000190 }
191}
192
Greg Clayton917c0002011-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 Lattner24943d22010-06-08 16:52:24 +0000203
204SBValue
205SBValueList::GetValueAtIndex (uint32_t idx) const
206{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000207 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000208
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000209 //if (log)
210 // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx);
Caroline Tice7826c882010-10-26 03:11:13 +0000211
Chris Lattner24943d22010-06-08 16:52:24 +0000212 SBValue sb_value;
Greg Clayton63094e02010-06-23 01:19:29 +0000213 if (m_opaque_ap.get())
Enrico Granata5c1700a2013-02-07 18:23:56 +0000214 sb_value = m_opaque_ap->GetValueAtIndex (idx);
Caroline Tice7826c882010-10-26 03:11:13 +0000215
216 if (log)
217 {
218 SBStream sstr;
219 sb_value.GetDescription (sstr);
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000220 log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')",
Enrico Granata5c1700a2013-02-07 18:23:56 +0000221 m_opaque_ap.get(), idx, sb_value.GetSP().get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000222 }
223
Chris Lattner24943d22010-06-08 16:52:24 +0000224 return sb_value;
225}
226
227uint32_t
228SBValueList::GetSize () const
229{
Greg Clayton952e9dc2013-03-27 23:08:40 +0000230 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000231
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000232 //if (log)
233 // log->Printf ("SBValueList::GetSize ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000234
Chris Lattner24943d22010-06-08 16:52:24 +0000235 uint32_t size = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000236 if (m_opaque_ap.get())
237 size = m_opaque_ap->GetSize();
Caroline Tice7826c882010-10-26 03:11:13 +0000238
239 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000240 log->Printf ("SBValueList::GetSize (this.ap=%p) => %d", m_opaque_ap.get(), size);
Caroline Tice7826c882010-10-26 03:11:13 +0000241
Chris Lattner24943d22010-06-08 16:52:24 +0000242 return size;
243}
244
245void
246SBValueList::CreateIfNeeded ()
247{
Greg Clayton63094e02010-06-23 01:19:29 +0000248 if (m_opaque_ap.get() == NULL)
Enrico Granata5c1700a2013-02-07 18:23:56 +0000249 m_opaque_ap.reset (new ValueListImpl());
Chris Lattner24943d22010-06-08 16:52:24 +0000250}
251
252
253SBValue
254SBValueList::FindValueObjectByUID (lldb::user_id_t uid)
255{
256 SBValue sb_value;
Greg Claytonbdcda462010-12-20 20:49:23 +0000257 if (m_opaque_ap.get())
Enrico Granata5c1700a2013-02-07 18:23:56 +0000258 sb_value = m_opaque_ap->FindValueByUID(uid);
Chris Lattner24943d22010-06-08 16:52:24 +0000259 return sb_value;
260}
261
Enrico Granataac669202013-02-07 22:22:27 +0000262void *
Enrico Granata9c7108f2013-02-07 22:57:46 +0000263SBValueList::opaque_ptr ()
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000264{
265 return m_opaque_ap.get();
266}
267
Enrico Granata5c1700a2013-02-07 18:23:56 +0000268ValueListImpl &
Greg Clayton917c0002011-06-29 22:09:02 +0000269SBValueList::ref ()
270{
271 CreateIfNeeded();
272 return *m_opaque_ap.get();
273}
274
275