2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBError.cpp ---------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBError.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Error.h"
|
2010-10-26 11:11:13 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
|
2010-06-09 16:46:23 +08:00
|
|
|
#include <stdarg.h>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
|
|
SBError::SBError () :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError::SBError (const SBError &rhs) :
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (rhs.IsValid())
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap.reset (new Error(*rhs));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SBError::~SBError()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const SBError &
|
|
|
|
SBError::operator = (const SBError &rhs)
|
|
|
|
{
|
|
|
|
if (rhs.IsValid())
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
*m_opaque_ap = *rhs;
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap.reset (new Error(*rhs));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap.reset();
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBError::GetCString () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
return m_opaque_ap->AsCString();
|
2010-06-09 00:52:24 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBError::Clear ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
|
|
|
m_opaque_ap->Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBError::Fail () const
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
bool ret_value = false;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
2010-10-26 11:11:13 +08:00
|
|
|
ret_value = m_opaque_ap->Fail();
|
|
|
|
|
|
|
|
if (log)
|
2010-10-30 12:51:46 +08:00
|
|
|
log->Printf ("SBError(%p)::Fail () => %i", m_opaque_ap.get(), ret_value);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return ret_value;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBError::Success () const
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2011-08-13 07:34:31 +08:00
|
|
|
bool ret_value = true;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
2010-10-30 12:51:46 +08:00
|
|
|
ret_value = m_opaque_ap->Success();
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf ("SBError(%p)::Success () => %i", m_opaque_ap.get(), ret_value);
|
|
|
|
|
|
|
|
return ret_value;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
SBError::GetError () const
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 12:51:46 +08:00
|
|
|
|
|
|
|
uint32_t err = 0;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
2010-10-30 12:51:46 +08:00
|
|
|
err = m_opaque_ap->GetError();
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf ("SBError(%p)::GetError () => 0x%8.8x", m_opaque_ap.get(), err);
|
|
|
|
|
|
|
|
|
|
|
|
return err;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ErrorType
|
|
|
|
SBError::GetType () const
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-30 12:51:46 +08:00
|
|
|
ErrorType err_type = eErrorTypeInvalid;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get())
|
2010-10-30 12:51:46 +08:00
|
|
|
err_type = m_opaque_ap->GetType();
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf ("SBError(%p)::GetType () => %i", m_opaque_ap.get(), err_type);
|
|
|
|
|
|
|
|
return err_type;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBError::SetError (uint32_t err, ErrorType type)
|
|
|
|
{
|
|
|
|
CreateIfNeeded ();
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap->SetError (err, type);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBError::SetError (const Error &lldb_error)
|
|
|
|
{
|
|
|
|
CreateIfNeeded ();
|
2010-06-23 09:19:29 +08:00
|
|
|
*m_opaque_ap = lldb_error;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
SBError::SetErrorToErrno ()
|
|
|
|
{
|
|
|
|
CreateIfNeeded ();
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap->SetErrorToErrno ();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBError::SetErrorToGenericError ()
|
|
|
|
{
|
|
|
|
CreateIfNeeded ();
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap->SetErrorToErrno ();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBError::SetErrorString (const char *err_str)
|
|
|
|
{
|
|
|
|
CreateIfNeeded ();
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_ap->SetErrorString (err_str);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SBError::SetErrorStringWithFormat (const char *format, ...)
|
|
|
|
{
|
|
|
|
CreateIfNeeded ();
|
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
2010-06-23 09:19:29 +08:00
|
|
|
int num_chars = m_opaque_ap->SetErrorStringWithVarArg (format, args);
|
2010-06-09 00:52:24 +08:00
|
|
|
va_end (args);
|
|
|
|
return num_chars;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBError::IsValid () const
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get() != NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBError::CreateIfNeeded ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ap.get() == NULL)
|
|
|
|
m_opaque_ap.reset(new Error ());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lldb_private::Error *
|
|
|
|
SBError::operator->()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb_private::Error *
|
|
|
|
SBError::get()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-11-04 09:54:29 +08:00
|
|
|
lldb_private::Error &
|
|
|
|
SBError::ref()
|
|
|
|
{
|
|
|
|
CreateIfNeeded();
|
|
|
|
return *m_opaque_ap;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
const lldb_private::Error &
|
|
|
|
SBError::operator*() const
|
|
|
|
{
|
|
|
|
// Be sure to call "IsValid()" before calling this function or it will crash
|
2010-06-23 09:19:29 +08:00
|
|
|
return *m_opaque_ap;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
bool
|
|
|
|
SBError::GetDescription (SBStream &description)
|
|
|
|
{
|
|
|
|
if (m_opaque_ap.get())
|
|
|
|
{
|
2011-07-07 00:49:27 +08:00
|
|
|
if (m_opaque_ap->Success())
|
|
|
|
description.Printf ("success");
|
2010-09-20 13:20:02 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
const char * err_string = GetCString();
|
2011-07-07 00:49:27 +08:00
|
|
|
description.Printf ("error: %s", (err_string != NULL ? err_string : ""));
|
2010-09-20 13:20:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2011-07-07 00:49:27 +08:00
|
|
|
description.Printf ("error: <NULL>");
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|