blob: 1d72a92b514525432d721b296cd96f1a3de82ebc [file] [log] [blame]
Zachary Turner819e77d2016-05-06 20:51:57 +00001#include "llvm/DebugInfo/PDB/DIA/DIAError.h"
2#include "llvm/Support/ErrorHandling.h"
3#include "llvm/Support/ManagedStatic.h"
4
5using namespace llvm;
6using namespace llvm::pdb;
7
Peter Collingbourne4718f8b2016-05-24 20:13:46 +00008// FIXME: This class is only here to support the transition to llvm::Error. It
9// will be removed once this transition is complete. Clients should prefer to
10// deal with the Error value directly, rather than converting to error_code.
Zachary Turner819e77d2016-05-06 20:51:57 +000011class DIAErrorCategory : public std::error_category {
12public:
13 const char *name() const LLVM_NOEXCEPT override { return "llvm.pdb.dia"; }
14
15 std::string message(int Condition) const override {
16 switch (static_cast<dia_error_code>(Condition)) {
17 case dia_error_code::could_not_create_impl:
18 return "Failed to connect to DIA at runtime. Verify that Visual Studio "
19 "is properly installed, or that msdiaXX.dll is in your PATH.";
20 case dia_error_code::invalid_file_format:
21 return "Unable to load PDB. The file has an unrecognized format.";
22 case dia_error_code::invalid_parameter:
23 return "The parameter is incorrect.";
24 case dia_error_code::already_loaded:
25 return "Unable to load the PDB or EXE, because it is already loaded.";
26 case dia_error_code::debug_info_mismatch:
27 return "The PDB file and the EXE file do not match.";
28 case dia_error_code::unspecified:
29 return "An unknown error has occurred.";
30 }
31 llvm_unreachable("Unrecognized DIAErrorCode");
32 }
33};
34
35static ManagedStatic<DIAErrorCategory> Category;
36
37char DIAError::ID = 0;
38
39DIAError::DIAError(dia_error_code C) : DIAError(C, "") {}
40
41DIAError::DIAError(const std::string &Context)
42 : DIAError(dia_error_code::unspecified, Context) {}
43
44DIAError::DIAError(dia_error_code C, const std::string &Context) : Code(C) {
45 ErrMsg = "DIA Error: ";
46 std::error_code EC = convertToErrorCode();
47 if (Code != dia_error_code::unspecified)
48 ErrMsg += EC.message() + " ";
49 if (!Context.empty())
50 ErrMsg += Context;
51}
52
53void DIAError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
54
55const std::string &DIAError::getErrorMessage() const { return ErrMsg; }
56
57std::error_code DIAError::convertToErrorCode() const {
58 return std::error_code(static_cast<int>(Code), *Category);
59}