LLDB mainline
SBError.cpp
Go to the documentation of this file.
1//===-- SBError.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/SBError.h"
10#include "Utils.h"
11#include "lldb/API/SBStream.h"
13#include "lldb/Utility/Status.h"
14
15#include <cstdarg>
16
17using namespace lldb;
18using namespace lldb_private;
19
21
23 LLDB_INSTRUMENT_VA(this, rhs);
24
26}
27
28SBError::SBError(const char *message) {
29 LLDB_INSTRUMENT_VA(this, message);
30
31 SetErrorString(message);
32}
33
35 : m_opaque_up(new Status(status)) {
36 LLDB_INSTRUMENT_VA(this, status);
37}
38
39SBError::~SBError() = default;
40
42 LLDB_INSTRUMENT_VA(this, rhs);
43
44 if (this != &rhs)
46 return *this;
47}
48
49const char *SBError::GetCString() const {
51
52 if (m_opaque_up)
53 return m_opaque_up->AsCString();
54 return nullptr;
55}
56
59
60 if (m_opaque_up)
61 m_opaque_up->Clear();
62}
63
64bool SBError::Fail() const {
66
67 bool ret_value = false;
68 if (m_opaque_up)
69 ret_value = m_opaque_up->Fail();
70
71
72 return ret_value;
73}
74
75bool SBError::Success() const {
77
78 bool ret_value = true;
79 if (m_opaque_up)
80 ret_value = m_opaque_up->Success();
81
82 return ret_value;
83}
84
85uint32_t SBError::GetError() const {
87
88 uint32_t err = 0;
89 if (m_opaque_up)
90 err = m_opaque_up->GetError();
91
92
93 return err;
94}
95
98
100 if (m_opaque_up)
101 err_type = m_opaque_up->GetType();
102
103 return err_type;
104}
105
106void SBError::SetError(uint32_t err, ErrorType type) {
107 LLDB_INSTRUMENT_VA(this, err, type);
108
110 m_opaque_up->SetError(err, type);
111}
112
113void SBError::SetError(const Status &lldb_error) {
115 *m_opaque_up = lldb_error;
116}
117
119 LLDB_INSTRUMENT_VA(this);
120
122 m_opaque_up->SetErrorToErrno();
123}
124
126 LLDB_INSTRUMENT_VA(this);
127
129 m_opaque_up->SetErrorToGenericError();
130}
131
132void SBError::SetErrorString(const char *err_str) {
133 LLDB_INSTRUMENT_VA(this, err_str);
134
136 m_opaque_up->SetErrorString(err_str);
137}
138
139int SBError::SetErrorStringWithFormat(const char *format, ...) {
141 va_list args;
142 va_start(args, format);
143 int num_chars = m_opaque_up->SetErrorStringWithVarArg(format, args);
144 va_end(args);
145 return num_chars;
146}
147
148bool SBError::IsValid() const {
149 LLDB_INSTRUMENT_VA(this);
150 return this->operator bool();
151}
152SBError::operator bool() const {
153 LLDB_INSTRUMENT_VA(this);
154
155 return m_opaque_up != nullptr;
156}
157
159 if (m_opaque_up == nullptr)
160 m_opaque_up = std::make_unique<Status>();
161}
162
164
166
169 return *m_opaque_up;
170}
171
173 // Be sure to call "IsValid()" before calling this function or it will crash
174 return *m_opaque_up;
175}
176
178 LLDB_INSTRUMENT_VA(this, description);
179
180 if (m_opaque_up) {
181 if (m_opaque_up->Success())
182 description.Printf("success");
183 else {
184 const char *err_string = GetCString();
185 description.Printf("error: %s",
186 (err_string != nullptr ? err_string : ""));
187 }
188 } else
189 description.Printf("error: <NULL>");
190
191 return true;
192}
#define LLDB_INSTRUMENT_VA(...)
uint32_t GetError() const
Definition: SBError.cpp:85
bool GetDescription(lldb::SBStream &description)
Definition: SBError.cpp:177
bool Success() const
Definition: SBError.cpp:75
std::unique_ptr< lldb_private::Status > m_opaque_up
Definition: SBError.h:113
void SetErrorString(const char *err_str)
Definition: SBError.cpp:132
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:106
bool Fail() const
Definition: SBError.cpp:64
const SBError & operator=(const lldb::SBError &rhs)
Definition: SBError.cpp:41
lldb_private::Status & ref()
Definition: SBError.cpp:167
lldb::ErrorType GetType() const
Definition: SBError.cpp:96
const lldb_private::Status & operator*() const
Definition: SBError.cpp:172
void SetErrorToGenericError()
Definition: SBError.cpp:125
const char * GetCString() const
Get the error string as a NULL terminated UTF8 c-string.
Definition: SBError.cpp:49
lldb_private::Status * operator->()
Definition: SBError.cpp:163
bool IsValid() const
Definition: SBError.cpp:148
void SetErrorToErrno()
Definition: SBError.cpp:118
void CreateIfNeeded()
Definition: SBError.cpp:158
lldb_private::Status * get()
Definition: SBError.cpp:165
void Clear()
Definition: SBError.cpp:57
An error handling class.
Definition: Status.h:44
A class that represents a running process on the host machine.
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
Definition: SBAddress.h:15
@ eErrorTypeInvalid