From 819e77d196f208cc8ef15b4186e07ecb14a115c8 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Fri, 6 May 2016 20:51:57 +0000 Subject: Port DebugInfoPDB over to using llvm::Error. Differential Revision: http://reviews.llvm.org/D19940 Reviewed By: rnk llvm-svn: 268791 --- llvm/lib/DebugInfo/PDB/Raw/RawError.cpp | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 llvm/lib/DebugInfo/PDB/Raw/RawError.cpp (limited to 'llvm/lib/DebugInfo/PDB/Raw/RawError.cpp') diff --git a/llvm/lib/DebugInfo/PDB/Raw/RawError.cpp b/llvm/lib/DebugInfo/PDB/Raw/RawError.cpp new file mode 100644 index 00000000000..aa6f15726a6 --- /dev/null +++ b/llvm/lib/DebugInfo/PDB/Raw/RawError.cpp @@ -0,0 +1,52 @@ +#include "llvm/DebugInfo/PDB/Raw/RawError.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/ManagedStatic.h" + +using namespace llvm; +using namespace llvm::pdb; + +class RawErrorCategory : public std::error_category { +public: + const char *name() const LLVM_NOEXCEPT override { return "llvm.pdb.raw"; } + + std::string message(int Condition) const override { + switch (static_cast(Condition)) { + case raw_error_code::unspecified: + return "An unknown error has occurred."; + case raw_error_code::feature_unsupported: + return "The feature is unsupported by the implementation."; + case raw_error_code::corrupt_file: + return "The PDB file is corrupt."; + case raw_error_code::insufficient_buffer: + return "The buffer is not large enough to read the requested number of " + "bytes."; + } + llvm_unreachable("Unrecognized raw_error_code"); + } +}; + +static ManagedStatic Category; + +char RawError::ID = 0; + +RawError::RawError(raw_error_code C) : RawError(C, "") {} + +RawError::RawError(const std::string &Context) + : RawError(raw_error_code::unspecified, Context) {} + +RawError::RawError(raw_error_code C, const std::string &Context) : Code(C) { + ErrMsg = "Native PDB Error: "; + std::error_code EC = convertToErrorCode(); + if (Code != raw_error_code::unspecified) + ErrMsg += EC.message() + " "; + if (!Context.empty()) + ErrMsg += Context; +} + +void RawError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; } + +const std::string &RawError::getErrorMessage() const { return ErrMsg; } + +std::error_code RawError::convertToErrorCode() const { + return std::error_code(static_cast(Code), *Category); +} -- cgit v1.2.3