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 "lldb/API/SBError.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/API/SBValue.h"
15 #include "lldb/Utility/Status.h"
16 #include <vector>
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
22 public:
23  ValueListImpl() = default;
24 
25  ValueListImpl(const ValueListImpl &rhs) = default;
26 
28  if (this == &rhs)
29  return *this;
30  m_values = rhs.m_values;
31  m_error = rhs.m_error;
32  return *this;
33  }
34 
35  uint32_t GetSize() { return m_values.size(); }
36 
37  void Append(const lldb::SBValue &sb_value) { m_values.push_back(sb_value); }
38 
39  void Append(const ValueListImpl &list) {
40  for (auto val : list.m_values)
41  Append(val);
42  }
43 
45  if (index >= GetSize())
46  return lldb::SBValue();
47  return m_values[index];
48  }
49 
51  for (auto val : m_values) {
52  if (val.IsValid() && val.GetID() == uid)
53  return val;
54  }
55  return lldb::SBValue();
56  }
57 
58  lldb::SBValue GetFirstValueByName(const char *name) const {
59  if (name) {
60  for (auto val : m_values) {
61  if (val.IsValid() && val.GetName() && strcmp(name, val.GetName()) == 0)
62  return val;
63  }
64  }
65  return lldb::SBValue();
66  }
67 
68  const Status &GetError() const { return m_error; }
69 
70  void SetError(const Status &error) { m_error = error; }
71 
72 private:
73  std::vector<lldb::SBValue> m_values;
75 };
76 
78 
80  LLDB_INSTRUMENT_VA(this, rhs);
81 
82  if (rhs.IsValid())
83  m_opaque_up = std::make_unique<ValueListImpl>(*rhs);
84 }
85 
86 SBValueList::SBValueList(const ValueListImpl *lldb_object_ptr) {
87  if (lldb_object_ptr)
88  m_opaque_up = std::make_unique<ValueListImpl>(*lldb_object_ptr);
89 }
90 
91 SBValueList::~SBValueList() = default;
92 
93 bool SBValueList::IsValid() const {
94  LLDB_INSTRUMENT_VA(this);
95  return this->operator bool();
96 }
97 SBValueList::operator bool() const {
98  LLDB_INSTRUMENT_VA(this);
99 
100  return (m_opaque_up != nullptr);
101 }
102 
104  LLDB_INSTRUMENT_VA(this);
105 
106  m_opaque_up.reset();
107 }
108 
110  LLDB_INSTRUMENT_VA(this, rhs);
111 
112  if (this != &rhs) {
113  if (rhs.IsValid())
114  m_opaque_up = std::make_unique<ValueListImpl>(*rhs);
115  else
116  m_opaque_up.reset();
117  }
118  return *this;
119 }
120 
121 ValueListImpl *SBValueList::operator->() { return m_opaque_up.get(); }
122 
123 ValueListImpl &SBValueList::operator*() { return *m_opaque_up; }
124 
125 const ValueListImpl *SBValueList::operator->() const {
126  return m_opaque_up.get();
127 }
128 
129 const ValueListImpl &SBValueList::operator*() const { return *m_opaque_up; }
130 
131 void SBValueList::Append(const SBValue &val_obj) {
132  LLDB_INSTRUMENT_VA(this, val_obj);
133 
134  CreateIfNeeded();
135  m_opaque_up->Append(val_obj);
136 }
137 
138 void SBValueList::Append(lldb::ValueObjectSP &val_obj_sp) {
139  if (val_obj_sp) {
140  CreateIfNeeded();
141  m_opaque_up->Append(SBValue(val_obj_sp));
142  }
143 }
144 
145 void SBValueList::Append(const lldb::SBValueList &value_list) {
146  LLDB_INSTRUMENT_VA(this, value_list);
147 
148  if (value_list.IsValid()) {
149  CreateIfNeeded();
150  m_opaque_up->Append(*value_list);
151  }
152 }
153 
155  LLDB_INSTRUMENT_VA(this, idx);
156 
157  SBValue sb_value;
158  if (m_opaque_up)
159  sb_value = m_opaque_up->GetValueAtIndex(idx);
160 
161  return sb_value;
162 }
163 
165  LLDB_INSTRUMENT_VA(this);
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 
180  LLDB_INSTRUMENT_VA(this, uid);
181 
182  SBValue sb_value;
183  if (m_opaque_up)
184  sb_value = m_opaque_up->FindValueByUID(uid);
185  return sb_value;
186 }
187 
188 SBValue SBValueList::GetFirstValueByName(const char *name) const {
189  LLDB_INSTRUMENT_VA(this, name);
190 
191  SBValue sb_value;
192  if (m_opaque_up)
193  sb_value = m_opaque_up->GetFirstValueByName(name);
194  return sb_value;
195 }
196 
197 void *SBValueList::opaque_ptr() { return m_opaque_up.get(); }
198 
200  CreateIfNeeded();
201  return *m_opaque_up;
202 }
203 
205  LLDB_INSTRUMENT_VA(this);
206  SBError sb_error;
207  if (m_opaque_up)
208  sb_error.SetError(m_opaque_up->GetError());
209  return sb_error;
210 }
211 
213  ref().SetError(status);
214 }
lldb::SBValueList
Definition: SBValueList.h:18
Instrumentation.h
list
MATCHES FreeBSD list(APPEND FBSDKERNEL_LIBS kvm) endif() if(NOT FBSDKERNEL_LIBS) message(STATUS "Skipping FreeBSDKernel plugin due to missing libfbsdvmcore") return() endif() add_lldb_library(lldbPluginProcessFreeBSDKernel PLUGIN ProcessFreeBSDKernel.cpp RegisterContextFreeBSDKernel_arm64.cpp RegisterContextFreeBSDKernel_i386.cpp RegisterContextFreeBSDKernel_x86_64.cpp ThreadFreeBSDKernel.cpp LINK_LIBS lldbCore lldbTarget $
Definition: Plugins/Process/FreeBSDKernel/CMakeLists.txt:6
ValueListImpl::m_error
Status m_error
Definition: SBValueList.cpp:74
lldb::SBError
Definition: SBError.h:20
lldb::SBValueList::FindValueObjectByUID
lldb::SBValue FindValueObjectByUID(lldb::user_id_t uid)
Definition: SBValueList.cpp:179
lldb::SBValue
Definition: SBValue.h:21
lldb::SBValueList::GetFirstValueByName
lldb::SBValue GetFirstValueByName(const char *name) const
Definition: SBValueList.cpp:188
ValueListImpl::SetError
void SetError(const Status &error)
Definition: SBValueList.cpp:70
ValueListImpl::GetFirstValueByName
lldb::SBValue GetFirstValueByName(const char *name) const
Definition: SBValueList.cpp:58
lldb::SBValueList::ref
ValueListImpl & ref()
Definition: SBValueList.cpp:199
lldb::SBValueList::GetValueAtIndex
lldb::SBValue GetValueAtIndex(uint32_t idx) const
Definition: SBValueList.cpp:154
lldb::SBValueList::IsValid
bool IsValid() const
Definition: SBValueList.cpp:93
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
SBStream.h
ValueListImpl::Append
void Append(const ValueListImpl &list)
Definition: SBValueList.cpp:39
bool
lldb::SBValueList::GetError
lldb::SBError GetError()
Definition: SBValueList.cpp:204
ValueListImpl
Definition: SBValueList.cpp:21
ValueListImpl::operator=
ValueListImpl & operator=(const ValueListImpl &rhs)
Definition: SBValueList.cpp:27
SBValueList.h
lldb::SBValueList::Append
void Append(const lldb::SBValue &val_obj)
Definition: SBValueList.cpp:131
ValueListImpl::GetSize
uint32_t GetSize()
Definition: SBValueList.cpp:35
lldb::SBValueList::operator=
const lldb::SBValueList & operator=(const lldb::SBValueList &rhs)
Definition: SBValueList.cpp:109
ValueListImpl::GetError
const Status & GetError() const
Definition: SBValueList.cpp:68
lldb::SBValueList::SetError
void SetError(const lldb_private::Status &status)
Definition: SBValueList.cpp:212
lldb::SBValueList::opaque_ptr
void * opaque_ptr()
Definition: SBValueList.cpp:197
lldb::SBError::SetError
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:95
lldb::SBValueList::~SBValueList
~SBValueList()
lldb::SBValueList::operator->
ValueListImpl * operator->()
Definition: SBValueList.cpp:121
ValueListImpl::GetValueAtIndex
lldb::SBValue GetValueAtIndex(uint32_t index)
Definition: SBValueList.cpp:44
lldb_private::Status
Definition: Status.h:44
ValueListImpl::FindValueByUID
lldb::SBValue FindValueByUID(lldb::user_id_t uid)
Definition: SBValueList.cpp:50
uint32_t
lldb::SBValueList::SBValueList
SBValueList()
Definition: SBValueList.cpp:77
lldb::SBValueList::operator*
ValueListImpl & operator*()
Definition: SBValueList.cpp:123
lldb::SBValue
class LLDB_API SBValue
Definition: SBDefines.h:104
ValueListImpl::Append
void Append(const lldb::SBValue &sb_value)
Definition: SBValueList.cpp:37
SBValue.h
Status.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_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb::SBValueList::GetSize
uint32_t GetSize() const
Definition: SBValueList.cpp:164
lldb
Definition: SBAddress.h:15
ValueObjectList.h
ValueListImpl::m_values
std::vector< lldb::SBValue > m_values
Definition: SBValueList.cpp:73
SBError.h
lldb::SBValueList::CreateIfNeeded
void CreateIfNeeded()
Definition: SBValueList.cpp:174
lldb::SBValueList::Clear
void Clear()
Definition: SBValueList.cpp:103