LLDB  mainline
SBValueList.cpp
Go to the documentation of this file.
1 //===-- SBValueList.cpp ---------------------------------------------------===//
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 = std::make_unique<ValueListImpl>(*rhs);
79 }
80 
81 SBValueList::SBValueList(const ValueListImpl *lldb_object_ptr) : m_opaque_up() {
82  if (lldb_object_ptr)
83  m_opaque_up = std::make_unique<ValueListImpl>(*lldb_object_ptr);
84 }
85 
86 SBValueList::~SBValueList() = default;
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 != nullptr);
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 = std::make_unique<ValueListImpl>(*rhs);
111  else
112  m_opaque_up.reset();
113  }
114  return LLDB_RECORD_RESULT(*this);
115 }
116 
118 
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 
175  if (m_opaque_up == nullptr)
176  m_opaque_up = std::make_unique<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 
202  CreateIfNeeded();
203  return *m_opaque_up;
204 }
205 
206 namespace lldb_private {
207 namespace repro {
208 
209 template <>
213  LLDB_REGISTER_METHOD_CONST(bool, SBValueList, IsValid, ());
214  LLDB_REGISTER_METHOD_CONST(bool, SBValueList, operator bool, ());
215  LLDB_REGISTER_METHOD(void, SBValueList, Clear, ());
217  SBValueList, operator=,(const lldb::SBValueList &));
218  LLDB_REGISTER_METHOD(void, SBValueList, Append, (const lldb::SBValue &));
219  LLDB_REGISTER_METHOD(void, SBValueList, Append,
220  (const lldb::SBValueList &));
222  (uint32_t));
224  LLDB_REGISTER_METHOD(lldb::SBValue, SBValueList, FindValueObjectByUID,
225  (lldb::user_id_t));
227  (const char *));
228 }
229 
230 }
231 }
lldb::SBValueList
Definition: SBValueList.h:18
lldb::SBValueList::m_opaque_up
std::unique_ptr< ValueListImpl > m_opaque_up
Definition: SBValueList.h:70
lldb_private::repro::RegisterMethods< SBValueList >
void RegisterMethods< SBValueList >(Registry &R)
Definition: SBValueList.cpp:210
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
LLDB_RECORD_METHOD_CONST_NO_ARGS
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:168
lldb::SBValueList::FindValueObjectByUID
lldb::SBValue FindValueObjectByUID(lldb::user_id_t uid)
Definition: SBValueList.cpp:179
LLDB_RECORD_METHOD_NO_ARGS
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:165
lldb::SBValue
Definition: SBValue.h:21
lldb::SBValueList::GetFirstValueByName
lldb::SBValue GetFirstValueByName(const char *name) const
Definition: SBValueList.cpp:189
LLDB_RECORD_CONSTRUCTOR_NO_ARGS
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
Definition: ReproducerInstrumentation.h:136
LLDB_REGISTER_METHOD_CONST
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:98
ValueListImpl::GetFirstValueByName
lldb::SBValue GetFirstValueByName(const char *name) const
Definition: SBValueList.cpp:56
SBReproducerPrivate.h
lldb::SBValueList::ref
ValueListImpl & ref()
Definition: SBValueList.cpp:201
LLDB_REGISTER_CONSTRUCTOR
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
Definition: ReproducerInstrumentation.h:89
lldb::SBValueList::GetValueAtIndex
lldb::SBValue GetValueAtIndex(uint32_t idx) const
Definition: SBValueList.cpp:152
lldb::SBValueList::IsValid
bool IsValid() const
Definition: SBValueList.cpp:88
SBStream.h
ValueListImpl::Append
void Append(const ValueListImpl &list)
Definition: SBValueList.cpp:37
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
ValueListImpl
Definition: SBValueList.cpp:20
ValueListImpl::operator=
ValueListImpl & operator=(const ValueListImpl &rhs)
Definition: SBValueList.cpp:26
SBValueList.h
lldb::SBValueList::Append
void Append(const lldb::SBValue &val_obj)
Definition: SBValueList.cpp:127
ValueListImpl::GetSize
uint32_t GetSize()
Definition: SBValueList.cpp:33
lldb::SBValueList::operator=
const lldb::SBValueList & operator=(const lldb::SBValueList &rhs)
Definition: SBValueList.cpp:104
lldb::SBValueList::opaque_ptr
void * opaque_ptr()
Definition: SBValueList.cpp:199
lldb::SBValueList::~SBValueList
~SBValueList()
ValueListImpl::ValueListImpl
ValueListImpl()
Definition: SBValueList.cpp:22
LLDB_RECORD_CONSTRUCTOR
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
Definition: ReproducerInstrumentation.h:133
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
lldb::SBValueList::operator->
ValueListImpl * operator->()
Definition: SBValueList.cpp:117
ValueListImpl::GetValueAtIndex
lldb::SBValue GetValueAtIndex(uint32_t index)
Definition: SBValueList.cpp:42
ValueListImpl::FindValueByUID
lldb::SBValue FindValueByUID(lldb::user_id_t uid)
Definition: SBValueList.cpp:48
uint32_t
lldb::SBValueList::SBValueList
SBValueList()
Definition: SBValueList.cpp:70
lldb::SBValueList::operator*
ValueListImpl & operator*()
Definition: SBValueList.cpp:119
lldb::SBValue
class LLDB_API SBValue
Definition: SBDefines.h:91
ValueListImpl::Append
void Append(const lldb::SBValue &sb_value)
Definition: SBValueList.cpp:35
SBValue.h
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
LLDB_RECORD_METHOD_CONST
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:161
lldb::SBValueList::GetSize
uint32_t GetSize() const
Definition: SBValueList.cpp:164
lldb
Definition: SBAddress.h:15
ValueListImpl::ValueListImpl
ValueListImpl(const ValueListImpl &rhs)
Definition: SBValueList.cpp:24
ValueObjectList.h
ValueListImpl::m_values
std::vector< lldb::SBValue > m_values
Definition: SBValueList.cpp:67
lldb::SBValueList::CreateIfNeeded
void CreateIfNeeded()
Definition: SBValueList.cpp:174
lldb::SBValueList::Clear
void Clear()
Definition: SBValueList.cpp:98
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93