blob: 0da877b0fbadc0b4493696ff3f963b30a3652f4a [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:
Reid Kleckner990504e2016-10-19 23:52:38 +000013 const char *name() const noexcept override { return "llvm.pdb.dia"; }
Zachary Turner819e77d2016-05-06 20:51:57 +000014
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
Zachary Turner38380322016-10-19 16:42:20 +000041DIAError::DIAError(StringRef Context)
Zachary Turner819e77d2016-05-06 20:51:57 +000042 : DIAError(dia_error_code::unspecified, Context) {}
43
Zachary Turner38380322016-10-19 16:42:20 +000044DIAError::DIAError(dia_error_code C, StringRef Context) : Code(C) {
Zachary Turner819e77d2016-05-06 20:51:57 +000045 ErrMsg = "DIA Error: ";
46 std::error_code EC = convertToErrorCode();
Zachary Turner38380322016-10-19 16:42:20 +000047 ErrMsg += EC.message() + " ";
Zachary Turner819e77d2016-05-06 20:51:57 +000048 if (!Context.empty())
49 ErrMsg += Context;
50}
51
52void DIAError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
53
Zachary Turner38380322016-10-19 16:42:20 +000054StringRef DIAError::getErrorMessage() const { return ErrMsg; }
Zachary Turner819e77d2016-05-06 20:51:57 +000055
56std::error_code DIAError::convertToErrorCode() const {
57 return std::error_code(static_cast<int>(Code), *Category);
58}