blob: 2ec4a7bee24e22cd193d23dd8ae76cde0b8de038 [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 Granata85425d72013-02-07 18:23:56 +000022namespace {
23 class ValueListImpl
24 {
25 public:
26 ValueListImpl () :
27 m_values()
28 {
29 }
30
31 ValueListImpl (const ValueListImpl& rhs) :
32 m_values(rhs.m_values)
33 {
34 }
35
36 ValueListImpl&
37 operator = (const ValueListImpl& rhs)
38 {
39 if (this == &rhs)
40 return *this;
41 m_values = rhs.m_values;
42 return *this;
43 };
44
45 uint32_t
46 GetSize ()
47 {
48 return m_values.size();
49 }
50
51 void
52 Append (const lldb::SBValue& sb_value)
53 {
54 m_values.push_back(sb_value);
55 }
56
57 void
58 Append (const ValueListImpl& list)
59 {
60 for (auto val : list.m_values)
61 Append (val);
62 }
63
64 lldb::SBValue
65 GetValueAtIndex (uint32_t index)
66 {
67 if (index >= GetSize())
68 return lldb::SBValue();
69 return m_values[index];
70 }
71
72 lldb::SBValue
73 FindValueByUID (lldb::user_id_t uid)
74 {
75 for (auto val : m_values)
76 {
77 if (val.IsValid() && val.GetID() == uid)
78 return val;
79 }
80 return lldb::SBValue();
81 }
82
83 private:
84 std::vector<lldb::SBValue> m_values;
85 };
86}
87
88
Chris Lattner30fdc8d2010-06-08 16:52:24 +000089SBValueList::SBValueList () :
Greg Clayton66111032010-06-23 01:19:29 +000090 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091{
92}
93
94SBValueList::SBValueList (const SBValueList &rhs) :
Greg Clayton66111032010-06-23 01:19:29 +000095 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096{
Greg Claytondea8cb42011-06-29 22:09:02 +000097 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000098
Chris Lattner30fdc8d2010-06-08 16:52:24 +000099 if (rhs.IsValid())
Enrico Granata85425d72013-02-07 18:23:56 +0000100 m_opaque_ap.reset (new ValueListImpl (*rhs));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000101
102 if (log)
103 {
Caroline Tice750cd172010-10-26 23:49:36 +0000104 log->Printf ("SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p",
Greg Claytonaf67cec2010-12-20 20:49:23 +0000105 (rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL),
106 m_opaque_ap.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000107 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108}
109
Enrico Granata85425d72013-02-07 18:23:56 +0000110SBValueList::SBValueList (const ValueListImpl *lldb_object_ptr) :
Greg Clayton66111032010-06-23 01:19:29 +0000111 m_opaque_ap ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112{
Greg Claytondea8cb42011-06-29 22:09:02 +0000113 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000114
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115 if (lldb_object_ptr)
Enrico Granata85425d72013-02-07 18:23:56 +0000116 m_opaque_ap.reset (new ValueListImpl (*lldb_object_ptr));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000117
118 if (log)
119 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000120 log->Printf ("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p",
121 lldb_object_ptr,
Caroline Tice750cd172010-10-26 23:49:36 +0000122 m_opaque_ap.get());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000123 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124}
125
126SBValueList::~SBValueList ()
127{
128}
129
130bool
131SBValueList::IsValid () const
132{
Greg Clayton66111032010-06-23 01:19:29 +0000133 return (m_opaque_ap.get() != NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134}
135
Jim Ingham5d3bca42011-12-19 20:39:44 +0000136void
137SBValueList::Clear()
138{
139 m_opaque_ap.reset();
140}
141
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000142const SBValueList &
143SBValueList::operator = (const SBValueList &rhs)
144{
145 if (this != &rhs)
146 {
147 if (rhs.IsValid())
Enrico Granata85425d72013-02-07 18:23:56 +0000148 m_opaque_ap.reset (new ValueListImpl (*rhs));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149 else
Greg Clayton66111032010-06-23 01:19:29 +0000150 m_opaque_ap.reset ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151 }
152 return *this;
153}
154
Enrico Granata85425d72013-02-07 18:23:56 +0000155ValueListImpl *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156SBValueList::operator->()
157{
Greg Clayton66111032010-06-23 01:19:29 +0000158 return m_opaque_ap.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159}
160
Enrico Granata85425d72013-02-07 18:23:56 +0000161ValueListImpl &
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162SBValueList::operator*()
163{
Greg Clayton66111032010-06-23 01:19:29 +0000164 return *m_opaque_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165}
166
Enrico Granata85425d72013-02-07 18:23:56 +0000167const ValueListImpl *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168SBValueList::operator->() const
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 +0000173const ValueListImpl &
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174SBValueList::operator*() const
175{
Greg Clayton66111032010-06-23 01:19:29 +0000176 return *m_opaque_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177}
178
179void
180SBValueList::Append (const SBValue &val_obj)
181{
Enrico Granata85425d72013-02-07 18:23:56 +0000182 CreateIfNeeded ();
183 m_opaque_ap->Append (val_obj);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184}
185
186void
187SBValueList::Append (lldb::ValueObjectSP& val_obj_sp)
188{
189 if (val_obj_sp)
190 {
191 CreateIfNeeded ();
Enrico Granata85425d72013-02-07 18:23:56 +0000192 m_opaque_ap->Append (SBValue(val_obj_sp));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193 }
194}
195
Greg Claytondea8cb42011-06-29 22:09:02 +0000196void
197SBValueList::Append (const lldb::SBValueList& value_list)
198{
199 if (value_list.IsValid())
200 {
201 CreateIfNeeded ();
202 m_opaque_ap->Append (*value_list);
203 }
204}
205
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206
207SBValue
208SBValueList::GetValueAtIndex (uint32_t idx) const
209{
Greg Claytondea8cb42011-06-29 22:09:02 +0000210 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000211
Caroline Tice750cd172010-10-26 23:49:36 +0000212 //if (log)
213 // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000214
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000215 SBValue sb_value;
Greg Clayton66111032010-06-23 01:19:29 +0000216 if (m_opaque_ap.get())
Enrico Granata85425d72013-02-07 18:23:56 +0000217 sb_value = m_opaque_ap->GetValueAtIndex (idx);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000218
219 if (log)
220 {
221 SBStream sstr;
222 sb_value.GetDescription (sstr);
Caroline Tice750cd172010-10-26 23:49:36 +0000223 log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')",
Enrico Granata85425d72013-02-07 18:23:56 +0000224 m_opaque_ap.get(), idx, sb_value.GetSP().get(), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000225 }
226
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227 return sb_value;
228}
229
230uint32_t
231SBValueList::GetSize () const
232{
Greg Claytondea8cb42011-06-29 22:09:02 +0000233 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000234
Caroline Tice750cd172010-10-26 23:49:36 +0000235 //if (log)
236 // log->Printf ("SBValueList::GetSize ()");
Caroline Ticeceb6b132010-10-26 03:11:13 +0000237
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000238 uint32_t size = 0;
Greg Clayton66111032010-06-23 01:19:29 +0000239 if (m_opaque_ap.get())
240 size = m_opaque_ap->GetSize();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000241
242 if (log)
Caroline Tice750cd172010-10-26 23:49:36 +0000243 log->Printf ("SBValueList::GetSize (this.ap=%p) => %d", m_opaque_ap.get(), size);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000244
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000245 return size;
246}
247
248void
249SBValueList::CreateIfNeeded ()
250{
Greg Clayton66111032010-06-23 01:19:29 +0000251 if (m_opaque_ap.get() == NULL)
Enrico Granata85425d72013-02-07 18:23:56 +0000252 m_opaque_ap.reset (new ValueListImpl());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000253}
254
255
256SBValue
257SBValueList::FindValueObjectByUID (lldb::user_id_t uid)
258{
259 SBValue sb_value;
Greg Claytonaf67cec2010-12-20 20:49:23 +0000260 if (m_opaque_ap.get())
Enrico Granata85425d72013-02-07 18:23:56 +0000261 sb_value = m_opaque_ap->FindValueByUID(uid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262 return sb_value;
263}
264
Enrico Granata85425d72013-02-07 18:23:56 +0000265ValueListImpl *
Caroline Tice750cd172010-10-26 23:49:36 +0000266SBValueList::get ()
267{
268 return m_opaque_ap.get();
269}
270
Enrico Granata85425d72013-02-07 18:23:56 +0000271ValueListImpl &
Greg Claytondea8cb42011-06-29 22:09:02 +0000272SBValueList::ref ()
273{
274 CreateIfNeeded();
275 return *m_opaque_ap.get();
276}
277
278