1 //===-- SBValueList.cpp ---------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBValueList.h"
10 #include "lldb/API/SBError.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/API/SBValue.h"
13 #include "lldb/Utility/Instrumentation.h"
14 #include "lldb/Utility/Status.h"
15 #include "lldb/ValueObject/ValueObjectList.h"
19 using namespace lldb_private
;
23 ValueListImpl() = default;
25 ValueListImpl(const ValueListImpl
&rhs
)
26 : m_values(rhs
.m_values
), m_error(rhs
.m_error
.Clone()) {}
28 ValueListImpl
&operator=(const ValueListImpl
&rhs
) {
31 m_values
= rhs
.m_values
;
32 m_error
= rhs
.m_error
.Clone();
36 uint32_t GetSize() { return m_values
.size(); }
38 void Append(const lldb::SBValue
&sb_value
) { m_values
.push_back(sb_value
); }
40 void Append(const ValueListImpl
&list
) {
41 for (auto val
: list
.m_values
)
45 lldb::SBValue
GetValueAtIndex(uint32_t index
) {
46 if (index
>= GetSize())
47 return lldb::SBValue();
48 return m_values
[index
];
51 lldb::SBValue
FindValueByUID(lldb::user_id_t uid
) {
52 for (auto val
: m_values
) {
53 if (val
.IsValid() && val
.GetID() == uid
)
56 return lldb::SBValue();
59 lldb::SBValue
GetFirstValueByName(const char *name
) const {
61 for (auto val
: m_values
) {
62 if (val
.IsValid() && val
.GetName() && strcmp(name
, val
.GetName()) == 0)
66 return lldb::SBValue();
69 const Status
&GetError() const { return m_error
; }
71 void SetError(Status
&&error
) { m_error
= std::move(error
); }
74 std::vector
<lldb::SBValue
> m_values
;
78 SBValueList::SBValueList() { LLDB_INSTRUMENT_VA(this); }
80 SBValueList::SBValueList(const SBValueList
&rhs
) {
81 LLDB_INSTRUMENT_VA(this, rhs
);
84 m_opaque_up
= std::make_unique
<ValueListImpl
>(*rhs
);
87 SBValueList::SBValueList(const ValueListImpl
*lldb_object_ptr
) {
89 m_opaque_up
= std::make_unique
<ValueListImpl
>(*lldb_object_ptr
);
92 SBValueList::~SBValueList() = default;
94 bool SBValueList::IsValid() const {
95 LLDB_INSTRUMENT_VA(this);
96 return this->operator bool();
98 SBValueList::operator bool() const {
99 LLDB_INSTRUMENT_VA(this);
101 return (m_opaque_up
!= nullptr);
104 void SBValueList::Clear() {
105 LLDB_INSTRUMENT_VA(this);
110 const SBValueList
&SBValueList::operator=(const SBValueList
&rhs
) {
111 LLDB_INSTRUMENT_VA(this, rhs
);
115 m_opaque_up
= std::make_unique
<ValueListImpl
>(*rhs
);
122 ValueListImpl
*SBValueList::operator->() { return m_opaque_up
.get(); }
124 ValueListImpl
&SBValueList::operator*() { return *m_opaque_up
; }
126 const ValueListImpl
*SBValueList::operator->() const {
127 return m_opaque_up
.get();
130 const ValueListImpl
&SBValueList::operator*() const { return *m_opaque_up
; }
132 void SBValueList::Append(const SBValue
&val_obj
) {
133 LLDB_INSTRUMENT_VA(this, val_obj
);
136 m_opaque_up
->Append(val_obj
);
139 void SBValueList::Append(lldb::ValueObjectSP
&val_obj_sp
) {
142 m_opaque_up
->Append(SBValue(val_obj_sp
));
146 void SBValueList::Append(const lldb::SBValueList
&value_list
) {
147 LLDB_INSTRUMENT_VA(this, value_list
);
149 if (value_list
.IsValid()) {
151 m_opaque_up
->Append(*value_list
);
155 SBValue
SBValueList::GetValueAtIndex(uint32_t idx
) const {
156 LLDB_INSTRUMENT_VA(this, idx
);
160 sb_value
= m_opaque_up
->GetValueAtIndex(idx
);
165 uint32_t SBValueList::GetSize() const {
166 LLDB_INSTRUMENT_VA(this);
170 size
= m_opaque_up
->GetSize();
175 void SBValueList::CreateIfNeeded() {
176 if (m_opaque_up
== nullptr)
177 m_opaque_up
= std::make_unique
<ValueListImpl
>();
180 SBValue
SBValueList::FindValueObjectByUID(lldb::user_id_t uid
) {
181 LLDB_INSTRUMENT_VA(this, uid
);
185 sb_value
= m_opaque_up
->FindValueByUID(uid
);
189 SBValue
SBValueList::GetFirstValueByName(const char *name
) const {
190 LLDB_INSTRUMENT_VA(this, name
);
194 sb_value
= m_opaque_up
->GetFirstValueByName(name
);
198 void *SBValueList::opaque_ptr() { return m_opaque_up
.get(); }
200 ValueListImpl
&SBValueList::ref() {
205 lldb::SBError
SBValueList::GetError() {
206 LLDB_INSTRUMENT_VA(this);
209 sb_error
.SetError(m_opaque_up
->GetError().Clone());
213 void SBValueList::SetError(lldb_private::Status
&&status
) {
214 ref().SetError(std::move(status
));