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"
14#include "lldb/Utility/Status.h"
16#include <vector>
17
18using namespace lldb;
19using namespace lldb_private;
20
22public:
23 ValueListImpl() = default;
24
26 : m_values(rhs.m_values), m_error(rhs.m_error.Clone()) {}
27
29 if (this == &rhs)
30 return *this;
31 m_values = rhs.m_values;
32 m_error = rhs.m_error.Clone();
33 return *this;
34 }
35
36 uint32_t GetSize() { return m_values.size(); }
37
38 void Append(const lldb::SBValue &sb_value) { m_values.push_back(sb_value); }
39
40 void Append(const ValueListImpl &list) {
41 for (auto val : list.m_values)
42 Append(val);
43 }
44
46 if (index >= GetSize())
47 return lldb::SBValue();
48 return m_values[index];
49 }
50
52 for (auto val : m_values) {
53 if (val.IsValid() && val.GetID() == uid)
54 return val;
55 }
56 return lldb::SBValue();
57 }
58
59 lldb::SBValue GetFirstValueByName(const char *name) const {
60 if (name) {
61 for (auto val : m_values) {
62 if (val.IsValid() && val.GetName() && strcmp(name, val.GetName()) == 0)
63 return val;
64 }
65 }
66 return lldb::SBValue();
67 }
68
69 const Status &GetError() const { return m_error; }
70
71 void SetError(Status &&error) { m_error = std::move(error); }
72
73private:
74 std::vector<lldb::SBValue> m_values;
76};
77
79
81 LLDB_INSTRUMENT_VA(this, rhs);
82
83 if (rhs.IsValid())
84 m_opaque_up = std::make_unique<ValueListImpl>(*rhs);
85}
86
87SBValueList::SBValueList(const ValueListImpl *lldb_object_ptr) {
88 if (lldb_object_ptr)
89 m_opaque_up = std::make_unique<ValueListImpl>(*lldb_object_ptr);
90}
91
93
96 return this->operator bool();
97}
98SBValueList::operator bool() const {
100
101 return (m_opaque_up != nullptr);
102}
103
105 LLDB_INSTRUMENT_VA(this);
106
107 m_opaque_up.reset();
108}
109
111 LLDB_INSTRUMENT_VA(this, rhs);
112
113 if (this != &rhs) {
114 if (rhs.IsValid())
115 m_opaque_up = std::make_unique<ValueListImpl>(*rhs);
116 else
117 m_opaque_up.reset();
118 }
119 return *this;
120}
121
123
125
127 return m_opaque_up.get();
128}
129
131
132void SBValueList::Append(const SBValue &val_obj) {
133 LLDB_INSTRUMENT_VA(this, val_obj);
134
136 m_opaque_up->Append(val_obj);
137}
138
140 if (val_obj_sp) {
142 m_opaque_up->Append(SBValue(val_obj_sp));
143 }
144}
145
146void SBValueList::Append(const lldb::SBValueList &value_list) {
147 LLDB_INSTRUMENT_VA(this, value_list);
148
149 if (value_list.IsValid()) {
151 m_opaque_up->Append(*value_list);
152 }
153}
154
156 LLDB_INSTRUMENT_VA(this, idx);
157
158 SBValue sb_value;
159 if (m_opaque_up)
160 sb_value = m_opaque_up->GetValueAtIndex(idx);
161
162 return sb_value;
163}
164
165uint32_t SBValueList::GetSize() const {
166 LLDB_INSTRUMENT_VA(this);
167
168 uint32_t size = 0;
169 if (m_opaque_up)
170 size = m_opaque_up->GetSize();
171
172 return size;
173}
174
176 if (m_opaque_up == nullptr)
177 m_opaque_up = std::make_unique<ValueListImpl>();
178}
179
181 LLDB_INSTRUMENT_VA(this, uid);
182
183 SBValue sb_value;
184 if (m_opaque_up)
185 sb_value = m_opaque_up->FindValueByUID(uid);
186 return sb_value;
187}
188
190 LLDB_INSTRUMENT_VA(this, name);
191
192 SBValue sb_value;
193 if (m_opaque_up)
194 sb_value = m_opaque_up->GetFirstValueByName(name);
195 return sb_value;
196}
197
198void *SBValueList::opaque_ptr() { return m_opaque_up.get(); }
199
202 return *m_opaque_up;
203}
204
206 LLDB_INSTRUMENT_VA(this);
207 SBError sb_error;
208 if (m_opaque_up)
209 sb_error.SetError(m_opaque_up->GetError().Clone());
210 return sb_error;
211}
212
214 ref().SetError(std::move(status));
215}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT_VA(...)
uint32_t GetSize()
Definition: SBValueList.cpp:36
const Status & GetError() const
Definition: SBValueList.cpp:69
void Append(const ValueListImpl &list)
Definition: SBValueList.cpp:40
std::vector< lldb::SBValue > m_values
Definition: SBValueList.cpp:74
ValueListImpl()=default
lldb::SBValue GetFirstValueByName(const char *name) const
Definition: SBValueList.cpp:59
void SetError(Status &&error)
Definition: SBValueList.cpp:71
ValueListImpl & operator=(const ValueListImpl &rhs)
Definition: SBValueList.cpp:28
lldb::SBValue FindValueByUID(lldb::user_id_t uid)
Definition: SBValueList.cpp:51
void Append(const lldb::SBValue &sb_value)
Definition: SBValueList.cpp:38
ValueListImpl(const ValueListImpl &rhs)
Definition: SBValueList.cpp:25
lldb::SBValue GetValueAtIndex(uint32_t index)
Definition: SBValueList.cpp:45
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:124
const lldb::SBValueList & operator=(const lldb::SBValueList &rhs)
ValueListImpl & operator*()
std::unique_ptr< ValueListImpl > m_opaque_up
Definition: SBValueList.h:97
bool IsValid() const
Definition: SBValueList.cpp:94
void Append(const lldb::SBValue &val_obj)
void SetError(lldb_private::Status &&status)
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:118
Status Clone() const
Don't call this function in new code.
Definition: Status.h:174
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:484
uint64_t user_id_t
Definition: lldb-types.h:82