LLVM  4.0.0
RawError.cpp
Go to the documentation of this file.
4 
5 using namespace llvm;
6 using namespace llvm::pdb;
7 
8 namespace {
9 // FIXME: This class is only here to support the transition to llvm::Error. It
10 // will be removed once this transition is complete. Clients should prefer to
11 // deal with the Error value directly, rather than converting to error_code.
12 class RawErrorCategory : public std::error_category {
13 public:
14  const char *name() const noexcept override { return "llvm.pdb.raw"; }
15 
16  std::string message(int Condition) const override {
17  switch (static_cast<raw_error_code>(Condition)) {
19  return "An unknown error has occurred.";
21  return "The feature is unsupported by the implementation.";
23  return "The record is in an unexpected format.";
25  return "The PDB file is corrupt.";
27  return "The buffer is not large enough to read the requested number of "
28  "bytes.";
30  return "The specified stream could not be loaded.";
32  return "The specified item does not exist in the array.";
34  return "The specified block address is not valid.";
36  return "The entry already exists.";
38  return "The entry does not exist.";
40  return "The PDB does not support writing.";
42  return "The Type record has an invalid hash value.";
43  }
44  llvm_unreachable("Unrecognized raw_error_code");
45  }
46 };
47 } // end anonymous namespace
48 
50 
51 char RawError::ID = 0;
52 
54 
55 RawError::RawError(const std::string &Context)
56  : RawError(raw_error_code::unspecified, Context) {}
57 
58 RawError::RawError(raw_error_code C, const std::string &Context) : Code(C) {
59  ErrMsg = "Native PDB Error: ";
60  std::error_code EC = convertToErrorCode();
61  if (Code != raw_error_code::unspecified)
62  ErrMsg += EC.message() + " ";
63  if (!Context.empty())
64  ErrMsg += Context;
65 }
66 
67 void RawError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
68 
69 const std::string &RawError::getErrorMessage() const { return ErrMsg; }
70 
71 std::error_code RawError::convertToErrorCode() const {
72  return std::error_code(static_cast<int>(Code), *Category);
73 }
const std::string & getErrorMessage() const
Definition: RawError.cpp:69
LLVMContext & Context
Base class for errors originating when parsing raw PDB files.
Definition: RawError.h:35
raw_error_code
Definition: RawError.h:19
static ManagedStatic< RawErrorCategory > Category
Definition: RawError.cpp:49
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: RawError.cpp:67
static ManagedStatic< _object_error_category > error_category
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: RawError.cpp:71
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
RawError(raw_error_code C)
Definition: RawError.cpp:53
aarch64 promote const
static const char * name
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:63
static char ID
Definition: RawError.h:37