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
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
18using namespace lldb;
19using namespace lldb_private;
20
22public:
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
72private:
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
86SBValueList::SBValueList(const ValueListImpl *lldb_object_ptr) {
87 if (lldb_object_ptr)
88 m_opaque_up = std::make_unique<ValueListImpl>(*lldb_object_ptr);
89}
90
92
95 return this->operator bool();
96}
97SBValueList::operator bool() const {
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
122
124
126 return m_opaque_up.get();
127}
128
130
131void SBValueList::Append(const SBValue &val_obj) {
132 LLDB_INSTRUMENT_VA(this, val_obj);
133
135 m_opaque_up->Append(val_obj);
136}
137
138void SBValueList::Append(lldb::ValueObjectSP &val_obj_sp) {
139 if (val_obj_sp) {
141 m_opaque_up->Append(SBValue(val_obj_sp));
142 }
143}
144
145void SBValueList::Append(const lldb::SBValueList &value_list) {
146 LLDB_INSTRUMENT_VA(this, value_list);
147
148 if (value_list.IsValid()) {
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
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
197void *SBValueList::opaque_ptr() { return m_opaque_up.get(); }
198
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}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT_VA(...)
ValueListImpl(const ValueListImpl &rhs)=default
uint32_t GetSize()
Definition: SBValueList.cpp:35
const Status & GetError() const
Definition: SBValueList.cpp:68
void Append(const ValueListImpl &list)
Definition: SBValueList.cpp:39
std::vector< lldb::SBValue > m_values
Definition: SBValueList.cpp:73
ValueListImpl()=default
void SetError(const Status &error)
Definition: SBValueList.cpp:70
lldb::SBValue GetFirstValueByName(const char *name) const
Definition: SBValueList.cpp:58
ValueListImpl & operator=(const ValueListImpl &rhs)
Definition: SBValueList.cpp:27
lldb::SBValue FindValueByUID(lldb::user_id_t uid)
Definition: SBValueList.cpp:50
void Append(const lldb::SBValue &sb_value)
Definition: SBValueList.cpp:37
lldb::SBValue GetValueAtIndex(uint32_t index)
Definition: SBValueList.cpp:44
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:100
const lldb::SBValueList & operator=(const lldb::SBValueList &rhs)
void SetError(const lldb_private::Status &status)
ValueListImpl & operator*()
std::unique_ptr< ValueListImpl > m_opaque_up
Definition: SBValueList.h:97
bool IsValid() const
Definition: SBValueList.cpp:93
void Append(const lldb::SBValue &val_obj)
lldb::SBError GetError()
lldb::SBValue GetValueAtIndex(uint32_t idx) const
lldb::SBValue GetFirstValueByName(const char *name) const
ValueListImpl * operator->()
uint32_t GetSize() const
lldb::SBValue FindValueObjectByUID(lldb::user_id_t uid)
ValueListImpl & ref()
An error handling class.
Definition: Status.h:44
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
uint64_t user_id_t
Definition: lldb-types.h:84