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