diff options
author | Zachary Turner <zturner@google.com> | 2016-05-06 20:51:57 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-05-06 20:51:57 +0000 |
commit | 819e77d196f208cc8ef15b4186e07ecb14a115c8 (patch) | |
tree | 409e2ff42a99563c75759c4c22116c35eb60569c /llvm/lib/DebugInfo/PDB/GenericError.cpp | |
parent | 091fcfa3a7632b6bbfbefdac84e0425d827d288c (diff) | |
download | llvm-819e77d196f208cc8ef15b4186e07ecb14a115c8.zip llvm-819e77d196f208cc8ef15b4186e07ecb14a115c8.tar.gz llvm-819e77d196f208cc8ef15b4186e07ecb14a115c8.tar.bz2 |
Port DebugInfoPDB over to using llvm::Error.
Differential Revision: http://reviews.llvm.org/D19940
Reviewed By: rnk
llvm-svn: 268791
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/GenericError.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/GenericError.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/PDB/GenericError.cpp b/llvm/lib/DebugInfo/PDB/GenericError.cpp new file mode 100644 index 0000000..ca2d65d --- /dev/null +++ b/llvm/lib/DebugInfo/PDB/GenericError.cpp @@ -0,0 +1,62 @@ +//===- Error.cpp - system_error extensions for PDB --------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/GenericError.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/ManagedStatic.h" + +using namespace llvm; +using namespace llvm::pdb; + +class GenericErrorCategory : public std::error_category { +public: + const char *name() const LLVM_NOEXCEPT override { return "llvm.pdb"; } + + std::string message(int Condition) const override { + switch (static_cast<generic_error_code>(Condition)) { + case generic_error_code::unspecified: + return "An unknown error has occurred."; + case generic_error_code::dia_sdk_not_present: + return "LLVM was not compiled with support for DIA. This usually means " + "that you are are not using MSVC, or your Visual Studio " + "installation " + "is corrupt."; + case generic_error_code::invalid_path: + return "Unable to load PDB. Make sure the file exists and is readable."; + } + llvm_unreachable("Unrecognized generic_error_code"); + } +}; + +static ManagedStatic<GenericErrorCategory> Category; + +char GenericError::ID = 0; + +GenericError::GenericError(generic_error_code C) : GenericError(C, "") {} + +GenericError::GenericError(const std::string &Context) + : GenericError(generic_error_code::unspecified, Context) {} + +GenericError::GenericError(generic_error_code C, const std::string &Context) + : Code(C) { + ErrMsg = "PDB Error: "; + std::error_code EC = convertToErrorCode(); + if (Code != generic_error_code::unspecified) + ErrMsg += EC.message() + " "; + if (!Context.empty()) + ErrMsg += Context; +} + +void GenericError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; } + +const std::string &GenericError::getErrorMessage() const { return ErrMsg; } + +std::error_code GenericError::convertToErrorCode() const { + return std::error_code(static_cast<int>(Code), *Category); +} |