1 //===-- SBError.cpp ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBError.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Utility/Log.h"
13 #include "lldb/Utility/Status.h"
18 using namespace lldb_private;
20 SBError::SBError() : m_opaque_ap() {}
22 SBError::SBError(const SBError &rhs) : m_opaque_ap() {
24 m_opaque_ap.reset(new Status(*rhs));
27 SBError::~SBError() {}
29 const SBError &SBError::operator=(const SBError &rhs) {
34 m_opaque_ap.reset(new Status(*rhs));
41 const char *SBError::GetCString() const {
43 return m_opaque_ap->AsCString();
47 void SBError::Clear() {
52 bool SBError::Fail() const {
53 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
55 bool ret_value = false;
57 ret_value = m_opaque_ap->Fail();
60 log->Printf("SBError(%p)::Fail () => %i",
61 static_cast<void *>(m_opaque_ap.get()), ret_value);
66 bool SBError::Success() const {
67 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
68 bool ret_value = true;
70 ret_value = m_opaque_ap->Success();
73 log->Printf("SBError(%p)::Success () => %i",
74 static_cast<void *>(m_opaque_ap.get()), ret_value);
79 uint32_t SBError::GetError() const {
80 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
84 err = m_opaque_ap->GetError();
87 log->Printf("SBError(%p)::GetError () => 0x%8.8x",
88 static_cast<void *>(m_opaque_ap.get()), err);
93 ErrorType SBError::GetType() const {
94 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
95 ErrorType err_type = eErrorTypeInvalid;
97 err_type = m_opaque_ap->GetType();
100 log->Printf("SBError(%p)::GetType () => %i",
101 static_cast<void *>(m_opaque_ap.get()), err_type);
106 void SBError::SetError(uint32_t err, ErrorType type) {
108 m_opaque_ap->SetError(err, type);
111 void SBError::SetError(const Status &lldb_error) {
113 *m_opaque_ap = lldb_error;
116 void SBError::SetErrorToErrno() {
118 m_opaque_ap->SetErrorToErrno();
121 void SBError::SetErrorToGenericError() {
123 m_opaque_ap->SetErrorToErrno();
126 void SBError::SetErrorString(const char *err_str) {
128 m_opaque_ap->SetErrorString(err_str);
131 int SBError::SetErrorStringWithFormat(const char *format, ...) {
134 va_start(args, format);
135 int num_chars = m_opaque_ap->SetErrorStringWithVarArg(format, args);
140 bool SBError::IsValid() const { return m_opaque_ap != NULL; }
142 void SBError::CreateIfNeeded() {
143 if (m_opaque_ap == NULL)
144 m_opaque_ap.reset(new Status());
147 lldb_private::Status *SBError::operator->() { return m_opaque_ap.get(); }
149 lldb_private::Status *SBError::get() { return m_opaque_ap.get(); }
151 lldb_private::Status &SBError::ref() {
156 const lldb_private::Status &SBError::operator*() const {
157 // Be sure to call "IsValid()" before calling this function or it will crash
161 bool SBError::GetDescription(SBStream &description) {
163 if (m_opaque_ap->Success())
164 description.Printf("success");
166 const char *err_string = GetCString();
167 description.Printf("error: %s", (err_string != NULL ? err_string : ""));
170 description.Printf("error: <NULL>");