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 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. 11 class DIAErrorCategory : public std::error_category { 12 public: name() const13 const char *name() const LLVM_NOEXCEPT override { return "llvm.pdb.dia"; } 14 message(int Condition) const15 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 DIAError(dia_error_code C)39DIAError::DIAError(dia_error_code C) : DIAError(C, "") {} 40 DIAError(const std::string & Context)41DIAError::DIAError(const std::string &Context) 42 : DIAError(dia_error_code::unspecified, Context) {} 43 DIAError(dia_error_code C,const std::string & Context)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 log(raw_ostream & OS) const53void DIAError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; } 54 getErrorMessage() const55const std::string &DIAError::getErrorMessage() const { return ErrMsg; } 56 convertToErrorCode() const57std::error_code DIAError::convertToErrorCode() const { 58 return std::error_code(static_cast<int>(Code), *Category); 59 } 60