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/SBStream.h"
11 #include "lldb/API/SBValue.h"
14 
15 #include <vector>
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
21 public:
22  ValueListImpl() = default;
23 
24  ValueListImpl(const ValueListImpl &rhs) = default;
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 
71 
73  LLDB_INSTRUMENT_VA(this, rhs);
74 
75  if (rhs.IsValid())
76  m_opaque_up = std::make_unique<ValueListImpl>(*rhs);
77 }
78 
79 SBValueList::SBValueList(const ValueListImpl *lldb_object_ptr) {
80  if (lldb_object_ptr)
81  m_opaque_up = std::make_unique<ValueListImpl>(*lldb_object_ptr);
82 }
83 
84 SBValueList::~SBValueList() = default;
85 
86 bool SBValueList::IsValid() const {
87  LLDB_INSTRUMENT_VA(this);
88  return this->operator bool();
89 }
90 SBValueList::operator bool() const {
91  LLDB_INSTRUMENT_VA(this);
92 
93  return (m_opaque_up != nullptr);
94 }
95 
97  LLDB_INSTRUMENT_VA(this);
98 
99  m_opaque_up.reset();
100 }
101 
103  LLDB_INSTRUMENT_VA(this, rhs);
104 
105  if (this != &rhs) {
106  if (rhs.IsValid())
107  m_opaque_up = std::make_unique<ValueListImpl>(*rhs);
108  else
109  m_opaque_up.reset();
110  }
111  return *this;
112 }
113 
114 ValueListImpl *SBValueList::operator->() { return m_opaque_up.get(); }
115 
116 ValueListImpl &SBValueList::operator*() { return *m_opaque_up; }
117 
118 const ValueListImpl *SBValueList::operator->() const {
119  return m_opaque_up.get();
120 }
121 
122 const ValueListImpl &SBValueList::operator*() const { return *m_opaque_up; }
123 
124 void SBValueList::Append(const SBValue &val_obj) {
125  LLDB_INSTRUMENT_VA(this, val_obj);
126 
127  CreateIfNeeded();
128  m_opaque_up->Append(val_obj);
129 }
130 
131 void SBValueList::Append(lldb::ValueObjectSP &val_obj_sp) {
132  if (val_obj_sp) {
133  CreateIfNeeded();
134  m_opaque_up->Append(SBValue(val_obj_sp));
135  }
136 }
137 
138 void SBValueList::Append(const lldb::SBValueList &value_list) {
139  LLDB_INSTRUMENT_VA(this, value_list);
140 
141  if (value_list.IsValid()) {
142  CreateIfNeeded();
143  m_opaque_up->Append(*value_list);
144  }
145 }
146 
148  LLDB_INSTRUMENT_VA(this, idx);
149 
150  SBValue sb_value;
151  if (m_opaque_up)
152  sb_value = m_opaque_up->GetValueAtIndex(idx);
153 
154  return sb_value;
155 }
156 
158  LLDB_INSTRUMENT_VA(this);
159 
160  uint32_t size = 0;
161  if (m_opaque_up)
162  size = m_opaque_up->GetSize();
163 
164  return size;
165 }
166 
168  if (m_opaque_up == nullptr)
169  m_opaque_up = std::make_unique<ValueListImpl>();
170 }
171 
173  LLDB_INSTRUMENT_VA(this, uid);
174 
175  SBValue sb_value;
176  if (m_opaque_up)
177  sb_value = m_opaque_up->FindValueByUID(uid);
178  return sb_value;
179 }
180 
181 SBValue SBValueList::GetFirstValueByName(const char *name) const {
182  LLDB_INSTRUMENT_VA(this, name);
183 
184  SBValue sb_value;
185  if (m_opaque_up)
186  sb_value = m_opaque_up->GetFirstValueByName(name);
187  return sb_value;
188 }
189 
190 void *SBValueList::opaque_ptr() { return m_opaque_up.get(); }
191 
193  CreateIfNeeded();
194  return *m_opaque_up;
195 }
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
lldb::SBValueList::FindValueObjectByUID
lldb::SBValue FindValueObjectByUID(lldb::user_id_t uid)
Definition: SBValueList.cpp:172
lldb::SBValue
Definition: SBValue.h:21
lldb::SBValueList::GetFirstValueByName
lldb::SBValue GetFirstValueByName(const char *name) const
Definition: SBValueList.cpp:181
ValueListImpl::GetFirstValueByName
lldb::SBValue GetFirstValueByName(const char *name) const
Definition: SBValueList.cpp:56
lldb::SBValueList::ref
ValueListImpl & ref()
Definition: SBValueList.cpp:192
lldb::SBValueList::GetValueAtIndex
lldb::SBValue GetValueAtIndex(uint32_t idx) const
Definition: SBValueList.cpp:147
lldb::SBValueList::IsValid
bool IsValid() const
Definition: SBValueList.cpp:86
SBStream.h
ValueListImpl::Append
void Append(const ValueListImpl &list)
Definition: SBValueList.cpp:37
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:124
ValueListImpl::GetSize
uint32_t GetSize()
Definition: SBValueList.cpp:33
lldb::SBValueList::operator=
const lldb::SBValueList & operator=(const lldb::SBValueList &rhs)
Definition: SBValueList.cpp:102
lldb::SBValueList::opaque_ptr
void * opaque_ptr()
Definition: SBValueList.cpp:190
lldb::SBValueList::~SBValueList
~SBValueList()
lldb::SBValueList::operator->
ValueListImpl * operator->()
Definition: SBValueList.cpp:114
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:116
lldb::SBValue
class LLDB_API SBValue
Definition: SBDefines.h:103
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_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb::SBValueList::GetSize
uint32_t GetSize() const
Definition: SBValueList.cpp:157
lldb
Definition: SBAddress.h:15
ValueObjectList.h
ValueListImpl::m_values
std::vector< lldb::SBValue > m_values
Definition: SBValueList.cpp:67
lldb::SBValueList::CreateIfNeeded
void CreateIfNeeded()
Definition: SBValueList.cpp:167
lldb::SBValueList::Clear
void Clear()
Definition: SBValueList.cpp:96