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/Core/Error.h"
13 #include "lldb/Core/Log.h"
18 using namespace lldb_private;
26 SBError::SBError (const SBError &rhs) :
30 m_opaque_ap.reset (new Error(*rhs));
39 SBError::operator = (const SBError &rhs)
43 if (m_opaque_ap.get())
46 m_opaque_ap.reset (new Error(*rhs));
56 SBError::GetCString () const
58 if (m_opaque_ap.get())
59 return m_opaque_ap->AsCString();
66 if (m_opaque_ap.get())
71 SBError::Fail () const
73 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
75 bool ret_value = false;
76 if (m_opaque_ap.get())
77 ret_value = m_opaque_ap->Fail();
80 log->Printf ("SBError(%p)::Fail () => %i", m_opaque_ap.get(), ret_value);
86 SBError::Success () const
88 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
89 bool ret_value = true;
90 if (m_opaque_ap.get())
91 ret_value = m_opaque_ap->Success();
94 log->Printf ("SBError(%p)::Success () => %i", m_opaque_ap.get(), ret_value);
100 SBError::GetError () const
102 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
105 if (m_opaque_ap.get())
106 err = m_opaque_ap->GetError();
109 log->Printf ("SBError(%p)::GetError () => 0x%8.8x", m_opaque_ap.get(), err);
116 SBError::GetType () const
118 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
119 ErrorType err_type = eErrorTypeInvalid;
120 if (m_opaque_ap.get())
121 err_type = m_opaque_ap->GetType();
124 log->Printf ("SBError(%p)::GetType () => %i", m_opaque_ap.get(), err_type);
130 SBError::SetError (uint32_t err, ErrorType type)
133 m_opaque_ap->SetError (err, type);
137 SBError::SetError (const Error &lldb_error)
140 *m_opaque_ap = lldb_error;
145 SBError::SetErrorToErrno ()
148 m_opaque_ap->SetErrorToErrno ();
152 SBError::SetErrorToGenericError ()
155 m_opaque_ap->SetErrorToErrno ();
159 SBError::SetErrorString (const char *err_str)
162 m_opaque_ap->SetErrorString (err_str);
166 SBError::SetErrorStringWithFormat (const char *format, ...)
170 va_start (args, format);
171 int num_chars = m_opaque_ap->SetErrorStringWithVarArg (format, args);
177 SBError::IsValid () const
179 return m_opaque_ap.get() != NULL;
183 SBError::CreateIfNeeded ()
185 if (m_opaque_ap.get() == NULL)
186 m_opaque_ap.reset(new Error ());
190 lldb_private::Error *
191 SBError::operator->()
193 return m_opaque_ap.get();
196 lldb_private::Error *
199 return m_opaque_ap.get();
202 lldb_private::Error &
209 const lldb_private::Error &
210 SBError::operator*() const
212 // Be sure to call "IsValid()" before calling this function or it will crash
217 SBError::GetDescription (SBStream &description)
219 if (m_opaque_ap.get())
221 if (m_opaque_ap->Success())
222 description.Printf ("success");
225 const char * err_string = GetCString();
226 description.Printf ("error: %s", (err_string != NULL ? err_string : ""));
230 description.Printf ("error: <NULL>");