LLDB  mainline
SBValueList.cpp
Go to the documentation of this file.
1 //===-- SBValueList.cpp -----------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lldb/API/SBValueList.h"
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/API/SBValue.h"
14 
15 #include <vector>
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
21 public:
22  ValueListImpl() : m_values() {}
23 
24  ValueListImpl(const ValueListImpl &rhs) : m_values(rhs.m_values) {}
25 
27  if (this == &rhs)
28  return *this;
29  m_values = rhs.m_values;
30  return *this;
31  }
32 
33  uint32_t GetSize() { return m_values.size(); }
34 
35  void Append(const lldb::SBValue &sb_value) { m_values.push_back(sb_value); }
36 
37  void Append(const ValueListImpl &list) {
38  for (auto val : list.m_values)
39  Append(val);
40  }
41 
43  if (index >= GetSize())
44  return lldb::SBValue();
45  return m_values[index];
46  }
47 
49  for (auto val : m_values) {
50  if (val.IsValid() && val.GetID() == uid)
51  return val;
52  }
53  return lldb::SBValue();
54  }
55 
56  lldb::SBValue GetFirstValueByName(const char *name) const {
57  if (name) {
58  for (auto val : m_values) {
59  if (val.IsValid() && val.GetName() && strcmp(name, val.GetName()) == 0)
60  return val;
61  }
62  }
63  return lldb::SBValue();
64  }
65 
66 private:
67  std::vector<lldb::SBValue> m_values;
68 };
69 
70 SBValueList::SBValueList() : m_opaque_up() {
72 }
73 
74 SBValueList::SBValueList(const SBValueList &rhs) : m_opaque_up() {
76 
77  if (rhs.IsValid())
78  m_opaque_up.reset(new ValueListImpl(*rhs));
79 }
80 
81 SBValueList::SBValueList(const ValueListImpl *lldb_object_ptr) : m_opaque_up() {
82  if (lldb_object_ptr)
83  m_opaque_up.reset(new ValueListImpl(*lldb_object_ptr));
84 }
85 
87 
88 bool SBValueList::IsValid() const {
90  return this->operator bool();
91 }
92 SBValueList::operator bool() const {
93  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBValueList, operator bool);
94 
95  return (m_opaque_up != NULL);
96 }
97 
100 
101  m_opaque_up.reset();
102 }
103 
106  SBValueList, operator=,(const lldb::SBValueList &), rhs);
107 
108  if (this != &rhs) {
109  if (rhs.IsValid())
110  m_opaque_up.reset(new ValueListImpl(*rhs));
111  else
112  m_opaque_up.reset();
113  }
114  return LLDB_RECORD_RESULT(*this);
115 }
116 
117 ValueListImpl *SBValueList::operator->() { return m_opaque_up.get(); }
118 
119 ValueListImpl &SBValueList::operator*() { return *m_opaque_up; }
120 
121 const ValueListImpl *SBValueList::operator->() const {
122  return m_opaque_up.get();
123 }
124 
125 const ValueListImpl &SBValueList::operator*() const { return *m_opaque_up; }
126 
127 void SBValueList::Append(const SBValue &val_obj) {
129  val_obj);
130 
131  CreateIfNeeded();
132  m_opaque_up->Append(val_obj);
133 }
134 
135 void SBValueList::Append(lldb::ValueObjectSP &val_obj_sp) {
136  if (val_obj_sp) {
137  CreateIfNeeded();
138  m_opaque_up->Append(SBValue(val_obj_sp));
139  }
140 }
141 
142 void SBValueList::Append(const lldb::SBValueList &value_list) {
144  value_list);
145 
146  if (value_list.IsValid()) {
147  CreateIfNeeded();
148  m_opaque_up->Append(*value_list);
149  }
150 }
151 
154  (uint32_t), idx);
155 
156 
157  SBValue sb_value;
158  if (m_opaque_up)
159  sb_value = m_opaque_up->GetValueAtIndex(idx);
160 
161  return LLDB_RECORD_RESULT(sb_value);
162 }
163 
166 
167  uint32_t size = 0;
168  if (m_opaque_up)
169  size = m_opaque_up->GetSize();
170 
171  return size;
172 }
173 
174 void SBValueList::CreateIfNeeded() {
175  if (m_opaque_up == NULL)
176  m_opaque_up.reset(new ValueListImpl());
177 }
178 
181  (lldb::user_id_t), uid);
182 
183  SBValue sb_value;
184  if (m_opaque_up)
185  sb_value = m_opaque_up->FindValueByUID(uid);
186  return LLDB_RECORD_RESULT(sb_value);
187 }
188 
189 SBValue SBValueList::GetFirstValueByName(const char *name) const {
191  (const char *), name);
192 
193  SBValue sb_value;
194  if (m_opaque_up)
195  sb_value = m_opaque_up->GetFirstValueByName(name);
196  return LLDB_RECORD_RESULT(sb_value);
197 }
198 
199 void *SBValueList::opaque_ptr() { return m_opaque_up.get(); }
200 
201 ValueListImpl &SBValueList::ref() {
202  CreateIfNeeded();
203  return *m_opaque_up;
204 }
205 
206 namespace lldb_private {
207 namespace repro {
208 
209 template <>
214  LLDB_REGISTER_METHOD_CONST(bool, SBValueList, operator bool, ());
217  SBValueList, operator=,(const lldb::SBValueList &));
220  (const lldb::SBValueList &));
222  (uint32_t));
225  (lldb::user_id_t));
227  (const char *));
228 }
229 
230 }
231 }
The registry contains a unique mapping between functions and their ID.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
uint32_t GetSize() const
ValueListImpl(const ValueListImpl &rhs)
Definition: SBValueList.cpp:24
lldb::SBValue GetValueAtIndex(uint32_t idx) const
const lldb::SBValueList & operator=(const lldb::SBValueList &rhs)
lldb::SBValue GetFirstValueByName(const char *name) const
Definition: SBValueList.cpp:56
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
uint64_t user_id_t
Definition: lldb-types.h:84
lldb::SBValue GetValueAtIndex(uint32_t index)
Definition: SBValueList.cpp:42
class LLDB_API SBValue
Definition: SBDefines.h:90
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
bool IsValid() const
Definition: SBValueList.cpp:88
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
lldb::SBValue FindValueByUID(lldb::user_id_t uid)
Definition: SBValueList.cpp:48
lldb::SBValue FindValueObjectByUID(lldb::user_id_t uid)
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
lldb::SBValue GetFirstValueByName(const char *name) const
Definition: SBAddress.h:15
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
void Append(const ValueListImpl &list)
Definition: SBValueList.cpp:37
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
ValueListImpl & operator=(const ValueListImpl &rhs)
Definition: SBValueList.cpp:26
void RegisterMethods< SBValueList >(Registry &R)
void Append(const lldb::SBValue &sb_value)
Definition: SBValueList.cpp:35
uint32_t GetSize()
Definition: SBValueList.cpp:33
#define LLDB_RECORD_RESULT(Result)
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
void Append(const lldb::SBValue &val_obj)