14#include "llvm/ADT/SmallString.h"
15#include "llvm/ADT/StringRef.h"
16#include "llvm/Support/Errno.h"
17#include "llvm/Support/FormatProviders.h"
22#include <system_error>
43 : m_code(err), m_type(type), m_string() {}
52 m_string(EC.message()) {}
56 va_start(args, format);
69 error = llvm::handleErrors(
70 std::move(
error), [&](std::unique_ptr<llvm::ECError> e) -> llvm::Error {
71 std::error_code ec = e->convertToErrorCode();
72 if (ec.category() == std::generic_category()) {
74 m_type = ErrorType::eErrorTypePOSIX;
75 return llvm::Error::success();
77 return llvm::Error(std::move(e));
91 return llvm::Error::success();
92 if (
m_type == ErrorType::eErrorTypePOSIX)
93 return llvm::errorCodeToError(
94 std::error_code(
m_code, std::generic_category()));
95 return llvm::createStringError(
AsCString());
101static std::string RetrieveWin32ErrorString(uint32_t error_code) {
102 char *buffer =
nullptr;
106 if (::FormatMessageA(
107 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
108 FORMAT_MESSAGE_MAX_WIDTH_MASK,
109 NULL, error_code, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
110 (LPSTR)&buffer, 0, NULL)) {
111 message.assign(buffer);
115 else if (::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
116 FORMAT_MESSAGE_FROM_SYSTEM |
117 FORMAT_MESSAGE_MAX_WIDTH_MASK,
118 NULL, error_code, 0, (LPSTR)&buffer, 0, NULL)) {
119 message.assign(buffer);
136#if defined(__APPLE__)
137 if (
const char *s = ::mach_error_string(
m_code))
157 if (default_error_str)
190 const char *format, ...) {
193 if (format !=
nullptr && format[0]) {
195 va_start(args, format);
233 if (!err_str.empty()) {
247 if (format !=
nullptr && format[0]) {
249 va_start(args, format);
260 if (format !=
nullptr && format[0]) {
266 llvm::SmallString<1024> buf;
280void llvm::format_provider<lldb_private::Status>::format(
283 llvm::format_provider<llvm::StringRef>::format(
error.AsCString(),
OS,
static llvm::raw_ostream & error(Stream &strm)
A command line option parsing protocol class.
uint32_t ValueType
Every error value that this object can contain needs to be able to fit into ValueType.
lldb::ErrorType m_type
The type of the above error code.
void Clear()
Clear the object state.
void SetErrorToErrno()
Set the current error to errno.
const Status & operator=(llvm::Error error)
int int SetErrorStringWithVarArg(const char *format, va_list args)
ValueType m_code
Member variables.
lldb::ErrorType GetType() const
Access the error type.
void SetErrorToGenericError()
Set the current error to a generic error.
ValueType GetError() const
Access the error value.
llvm::Error ToError() const
void SetExpressionError(lldb::ExpressionResults, const char *mssg)
int SetExpressionErrorWithFormat(lldb::ExpressionResults, const char *format,...) __attribute__((format(printf
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
bool Fail() const
Test for error condition.
int void SetError(ValueType err, lldb::ErrorType type)
Set accessor with an error value and type.
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
bool Success() const
Test for success condition.
std::string m_string
A string representation of the error code.
#define LLDB_GENERIC_ERROR
A class that represents a running process on the host machine.
bool VASprintf(llvm::SmallVectorImpl< char > &buf, const char *fmt, va_list args)
@ eErrorTypeGeneric
Generic errors that can be any value.
@ eErrorTypeWin32
Standard Win32 error codes.
@ eErrorTypeExpression
These are from the ExpressionResults enum.
@ eErrorTypeMachKernel
Mach kernel error codes.
@ eErrorTypePOSIX
POSIX error codes.
ExpressionResults
The results of expression evaluation.