blob: ca2d65d0b59df848b49572024bb5513462e8ff14 [file] [log] [blame]
Zachary Turner819e77d2016-05-06 20:51:57 +00001//===- 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
10#include "llvm/DebugInfo/PDB/GenericError.h"
11#include "llvm/Support/ErrorHandling.h"
12#include "llvm/Support/ManagedStatic.h"
13
14using namespace llvm;
15using namespace llvm::pdb;
16
17class GenericErrorCategory : public std::error_category {
18public:
19 const char *name() const LLVM_NOEXCEPT override { return "llvm.pdb"; }
20
21 std::string message(int Condition) const override {
22 switch (static_cast<generic_error_code>(Condition)) {
23 case generic_error_code::unspecified:
24 return "An unknown error has occurred.";
25 case generic_error_code::dia_sdk_not_present:
26 return "LLVM was not compiled with support for DIA. This usually means "
27 "that you are are not using MSVC, or your Visual Studio "
28 "installation "
29 "is corrupt.";
30 case generic_error_code::invalid_path:
31 return "Unable to load PDB. Make sure the file exists and is readable.";
32 }
33 llvm_unreachable("Unrecognized generic_error_code");
34 }
35};
36
37static ManagedStatic<GenericErrorCategory> Category;
38
39char GenericError::ID = 0;
40
41GenericError::GenericError(generic_error_code C) : GenericError(C, "") {}
42
43GenericError::GenericError(const std::string &Context)
44 : GenericError(generic_error_code::unspecified, Context) {}
45
46GenericError::GenericError(generic_error_code C, const std::string &Context)
47 : Code(C) {
48 ErrMsg = "PDB Error: ";
49 std::error_code EC = convertToErrorCode();
50 if (Code != generic_error_code::unspecified)
51 ErrMsg += EC.message() + " ";
52 if (!Context.empty())
53 ErrMsg += Context;
54}
55
56void GenericError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
57
58const std::string &GenericError::getErrorMessage() const { return ErrMsg; }
59
60std::error_code GenericError::convertToErrorCode() const {
61 return std::error_code(static_cast<int>(Code), *Category);
62}