2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBError.cpp ---------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBError.h"
|
2019-03-06 08:06:00 +08:00
|
|
|
#include "SBReproducerPrivate.h"
|
2019-03-06 08:05:55 +08:00
|
|
|
#include "Utils.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.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;
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
SBError::SBError() : m_opaque_up() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBError); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
SBError::SBError(const SBError &rhs) : m_opaque_up() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBError, (const lldb::SBError &), rhs);
|
|
|
|
|
2019-03-06 08:05:55 +08:00
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBError::~SBError() {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const SBError &SBError::operator=(const SBError &rhs) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(const lldb::SBError &,
|
|
|
|
SBError, operator=,(const lldb::SBError &), rhs);
|
|
|
|
|
2019-03-06 08:05:55 +08:00
|
|
|
if (this != &rhs)
|
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2016-09-07 04:57:50 +08:00
|
|
|
return *this;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *SBError::GetCString() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBError, GetCString);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up)
|
|
|
|
return m_opaque_up->AsCString();
|
2016-09-07 04:57:50 +08:00
|
|
|
return NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBError::Clear() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(void, SBError, Clear);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up)
|
|
|
|
m_opaque_up->Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBError::Fail() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBError, Fail);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool ret_value = false;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up)
|
|
|
|
ret_value = m_opaque_up->Fail();
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return ret_value;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBError::Success() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBError, Success);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool ret_value = true;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up)
|
|
|
|
ret_value = m_opaque_up->Success();
|
2010-10-30 12:51:46 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return ret_value;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t SBError::GetError() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBError, GetError);
|
|
|
|
|
2010-10-30 12:51:46 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t err = 0;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up)
|
|
|
|
err = m_opaque_up->GetError();
|
2010-10-30 12:51:46 +08:00
|
|
|
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return err;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ErrorType SBError::GetType() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::ErrorType, SBError, GetType);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ErrorType err_type = eErrorTypeInvalid;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up)
|
|
|
|
err_type = m_opaque_up->GetType();
|
2010-10-30 12:51:46 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return err_type;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBError::SetError(uint32_t err, ErrorType type) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBError, SetError, (uint32_t, lldb::ErrorType), err,
|
|
|
|
type);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
CreateIfNeeded();
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up->SetError(err, type);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
void SBError::SetError(const Status &lldb_error) {
|
2016-09-07 04:57:50 +08:00
|
|
|
CreateIfNeeded();
|
2019-02-13 14:25:41 +08:00
|
|
|
*m_opaque_up = lldb_error;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBError::SetErrorToErrno() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(void, SBError, SetErrorToErrno);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
CreateIfNeeded();
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up->SetErrorToErrno();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBError::SetErrorToGenericError() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(void, SBError, SetErrorToGenericError);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
CreateIfNeeded();
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up->SetErrorToErrno();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBError::SetErrorString(const char *err_str) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBError, SetErrorString, (const char *), err_str);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
CreateIfNeeded();
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up->SetErrorString(err_str);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
int SBError::SetErrorStringWithFormat(const char *format, ...) {
|
|
|
|
CreateIfNeeded();
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2019-02-13 14:25:41 +08:00
|
|
|
int num_chars = m_opaque_up->SetErrorStringWithVarArg(format, args);
|
2016-09-07 04:57:50 +08:00
|
|
|
va_end(args);
|
|
|
|
return num_chars;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
bool SBError::IsValid() const {
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBError, IsValid);
|
|
|
|
|
|
|
|
return m_opaque_up != NULL;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBError::CreateIfNeeded() {
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up == NULL)
|
|
|
|
m_opaque_up.reset(new Status());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
lldb_private::Status *SBError::operator->() { return m_opaque_up.get(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
lldb_private::Status *SBError::get() { return m_opaque_up.get(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
lldb_private::Status &SBError::ref() {
|
2016-09-07 04:57:50 +08:00
|
|
|
CreateIfNeeded();
|
2019-02-13 14:25:41 +08:00
|
|
|
return *m_opaque_up;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
const lldb_private::Status &SBError::operator*() const {
|
2016-09-07 04:57:50 +08:00
|
|
|
// Be sure to call "IsValid()" before calling this function or it will crash
|
2019-02-13 14:25:41 +08:00
|
|
|
return *m_opaque_up;
|
2010-11-04 09:54:29 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBError::GetDescription(SBStream &description) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(bool, SBError, GetDescription, (lldb::SBStream &),
|
|
|
|
description);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
if (m_opaque_up->Success())
|
2016-09-07 04:57:50 +08:00
|
|
|
description.Printf("success");
|
|
|
|
else {
|
|
|
|
const char *err_string = GetCString();
|
|
|
|
description.Printf("error: %s", (err_string != NULL ? err_string : ""));
|
2010-09-20 13:20:02 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
|
|
|
description.Printf("error: <NULL>");
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
|
|
|
}
|