LLVM  6.0.0svn
GenericError.cpp
Go to the documentation of this file.
1 //===- Error.cpp - system_error extensions for PDB --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
13 
14 using namespace llvm;
15 using namespace llvm::pdb;
16 
17 namespace {
18 // FIXME: This class is only here to support the transition to llvm::Error. It
19 // will be removed once this transition is complete. Clients should prefer to
20 // deal with the Error value directly, rather than converting to error_code.
21 class GenericErrorCategory : public std::error_category {
22 public:
23  const char *name() const noexcept override { return "llvm.pdb"; }
24 
25  std::string message(int Condition) const override {
26  switch (static_cast<generic_error_code>(Condition)) {
28  return "An unknown error has occurred.";
30  return "Type server PDB was not found.";
32  return "LLVM was not compiled with support for DIA. This usually means "
33  "that you are are not using MSVC, or your Visual Studio "
34  "installation "
35  "is corrupt.";
37  return "Unable to load PDB. Make sure the file exists and is readable.";
38  }
39  llvm_unreachable("Unrecognized generic_error_code");
40  }
41 };
42 } // end anonymous namespace
43 
45 
46 char GenericError::ID = 0;
47 
49 
52 
54  ErrMsg = "PDB Error: ";
55  std::error_code EC = convertToErrorCode();
57  ErrMsg += EC.message() + " ";
58  if (!Context.empty())
59  ErrMsg += Context;
60 }
61 
62 void GenericError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
63 
64 StringRef GenericError::getErrorMessage() const { return ErrMsg; }
65 
66 std::error_code GenericError::convertToErrorCode() const {
67  return std::error_code(static_cast<int>(Code), *Category);
68 }
uint64_t CallInst * C
LLVMContext & Context
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
GenericError(generic_error_code C)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:74
Base class for errors originating when parsing raw PDB files.
Definition: GenericError.h:27
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static ManagedStatic< GenericErrorCategory > Category
StringRef getErrorMessage() const
aarch64 promote const
void log(raw_ostream &OS) const override
Print an error message to an output stream.
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
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:61