Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 1 | #include "llvm/DebugInfo/PDB/DIA/DIAError.h" |
| 2 | #include "llvm/Support/ErrorHandling.h" |
| 3 | #include "llvm/Support/ManagedStatic.h" |
| 4 | |
| 5 | using namespace llvm; |
| 6 | using namespace llvm::pdb; |
| 7 | |
Peter Collingbourne | 4718f8b | 2016-05-24 20:13:46 +0000 | [diff] [blame] | 8 | // 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 Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 11 | class DIAErrorCategory : public std::error_category { |
| 12 | public: |
Reid Kleckner | 990504e | 2016-10-19 23:52:38 +0000 | [diff] [blame] | 13 | const char *name() const noexcept override { return "llvm.pdb.dia"; } |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 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 | |
| 35 | static ManagedStatic<DIAErrorCategory> Category; |
| 36 | |
| 37 | char DIAError::ID = 0; |
| 38 | |
| 39 | DIAError::DIAError(dia_error_code C) : DIAError(C, "") {} |
| 40 | |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 41 | DIAError::DIAError(StringRef Context) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 42 | : DIAError(dia_error_code::unspecified, Context) {} |
| 43 | |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 44 | DIAError::DIAError(dia_error_code C, StringRef Context) : Code(C) { |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 45 | ErrMsg = "DIA Error: "; |
| 46 | std::error_code EC = convertToErrorCode(); |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 47 | ErrMsg += EC.message() + " "; |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 48 | if (!Context.empty()) |
| 49 | ErrMsg += Context; |
| 50 | } |
| 51 | |
| 52 | void DIAError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; } |
| 53 | |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 54 | StringRef DIAError::getErrorMessage() const { return ErrMsg; } |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 55 | |
| 56 | std::error_code DIAError::convertToErrorCode() const { |
| 57 | return std::error_code(static_cast<int>(Code), *Category); |
| 58 | } |