blob: aa6f15726a6e13ff60c5c1e09b474b8c498d598c [file] [log] [blame]
Zachary Turner819e77d2016-05-06 20:51:57 +00001#include "llvm/DebugInfo/PDB/Raw/RawError.h"
2#include "llvm/Support/ErrorHandling.h"
3#include "llvm/Support/ManagedStatic.h"
4
5using namespace llvm;
6using namespace llvm::pdb;
7
8class RawErrorCategory : public std::error_category {
9public:
10 const char *name() const LLVM_NOEXCEPT override { return "llvm.pdb.raw"; }
11
12 std::string message(int Condition) const override {
13 switch (static_cast<raw_error_code>(Condition)) {
14 case raw_error_code::unspecified:
15 return "An unknown error has occurred.";
16 case raw_error_code::feature_unsupported:
17 return "The feature is unsupported by the implementation.";
18 case raw_error_code::corrupt_file:
19 return "The PDB file is corrupt.";
20 case raw_error_code::insufficient_buffer:
21 return "The buffer is not large enough to read the requested number of "
22 "bytes.";
23 }
24 llvm_unreachable("Unrecognized raw_error_code");
25 }
26};
27
28static ManagedStatic<RawErrorCategory> Category;
29
30char RawError::ID = 0;
31
32RawError::RawError(raw_error_code C) : RawError(C, "") {}
33
34RawError::RawError(const std::string &Context)
35 : RawError(raw_error_code::unspecified, Context) {}
36
37RawError::RawError(raw_error_code C, const std::string &Context) : Code(C) {
38 ErrMsg = "Native PDB Error: ";
39 std::error_code EC = convertToErrorCode();
40 if (Code != raw_error_code::unspecified)
41 ErrMsg += EC.message() + " ";
42 if (!Context.empty())
43 ErrMsg += Context;
44}
45
46void RawError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
47
48const std::string &RawError::getErrorMessage() const { return ErrMsg; }
49
50std::error_code RawError::convertToErrorCode() const {
51 return std::error_code(static_cast<int>(Code), *Category);
52}