9#ifndef LLDB_UTILITY_STATUS_H
10#define LLDB_UTILITY_STATUS_H
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/Error.h"
18#include "llvm/Support/FormatVariadic.h"
22#include <system_error>
36 :
public llvm::ErrorInfo<CloneableError, llvm::ErrorInfoBase> {
38 using llvm::ErrorInfo<
CloneableError, llvm::ErrorInfoBase>::ErrorInfo;
40 virtual std::unique_ptr<CloneableError>
Clone()
const = 0;
48 :
public llvm::ErrorInfo<CloneableECError, CloneableError> {
52 void log(llvm::raw_ostream &
OS)
const override {
OS <<
EC.message(); }
64 :
public llvm::ErrorInfo<MachKernelError, CloneableECError> {
68 std::string
message()
const override;
69 std::unique_ptr<CloneableError>
Clone()
const override;
74class Win32Error :
public llvm::ErrorInfo<Win32Error, CloneableECError> {
77 Win32Error(std::error_code ec,
const llvm::Twine &msg = {}) : ErrorInfo(ec) {}
78 std::string
message()
const override;
79 std::unique_ptr<CloneableError>
Clone()
const override;
134 std::string msg = {});
136 Status(std::error_code EC);
139 explicit Status(std::string err_str);
143 return Status(std::string(str));
144 return Status(std::string(
"null error"));
148 __attribute__((format(printf, 1, 2)));
150 template <typename...
Args>
152 return Status(llvm::formatv(format, std::forward<Args>(args)...));
187 const char *
AsCString(
const char *default_error_str =
"unknown error")
const;
247 llvm::StringRef Options);
251#define LLDB_ERRORF(status, fmt, ...) \
254 (status)->SetErrorStringWithFormat((fmt), __VA_ARGS__); \
static llvm::raw_ostream & error(Stream &strm)
A command line argument class.
Common base class for all error-code errors.
CloneableECError()=delete
void log(llvm::raw_ostream &OS) const override
lldb::ErrorType GetErrorType() const override
std::error_code convertToErrorCode() const override
CloneableECError(std::error_code ec)
virtual StructuredData::ObjectSP GetAsStructuredData() const override
Going a bit against the spirit of llvm::Error, lldb_private::Status need to store errors long-term an...
virtual std::unique_ptr< CloneableError > Clone() const =0
virtual StructuredData::ObjectSP GetAsStructuredData() const =0
virtual lldb::ErrorType GetErrorType() const =0
FIXME: Move these declarations closer to where they're used.
std::string message() const override
std::unique_ptr< CloneableError > Clone() const override
MachKernelError(std::error_code ec)
lldb::ErrorType GetErrorType() const override
uint32_t ValueType
into ValueType.
void Clear()
Clear the object state.
static Status FromErrno()
Set the current error to errno.
Status(Status &&other)=default
lldb::ErrorType GetType() const
Access the error type.
Status Clone() const
Don't call this function in new code.
ValueType GetError() const
Access the error value.
Status(llvm::Error error)
llvm::Error ToError() const
FIXME: Replace all uses with takeError() instead.
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
bool Fail() const
Test for error condition.
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
const Status & operator=(Status &&)
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
bool Success() const
Test for success condition.
std::string m_string
TODO: Replace this with just calling toString(m_error).
StructuredData::ObjectSP GetAsStructuredData() const
Get the error in machine-readable form.
std::shared_ptr< Object > ObjectSP
Win32Error(std::error_code ec, const llvm::Twine &msg={})
std::string message() const override
lldb::ErrorType GetErrorType() const override
std::unique_ptr< CloneableError > Clone() const override
A class that represents a running process on the host machine.
@ eErrorTypeGeneric
Generic errors that can be any value.