xref: /llvm-project/llvm/lib/DebugInfo/PDB/GenericError.cpp (revision d93b07f0b09c55bb7e01b463a822b214d141d6a8)
1819e77d1SZachary Turner //===- Error.cpp - system_error extensions for PDB --------------*- C++ -*-===//
2819e77d1SZachary Turner //
3819e77d1SZachary Turner //                     The LLVM Compiler Infrastructure
4819e77d1SZachary Turner //
5819e77d1SZachary Turner // This file is distributed under the University of Illinois Open Source
6819e77d1SZachary Turner // License. See LICENSE.TXT for details.
7819e77d1SZachary Turner //
8819e77d1SZachary Turner //===----------------------------------------------------------------------===//
9819e77d1SZachary Turner 
10819e77d1SZachary Turner #include "llvm/DebugInfo/PDB/GenericError.h"
11819e77d1SZachary Turner #include "llvm/Support/ErrorHandling.h"
12819e77d1SZachary Turner #include "llvm/Support/ManagedStatic.h"
13819e77d1SZachary Turner 
14819e77d1SZachary Turner using namespace llvm;
15819e77d1SZachary Turner using namespace llvm::pdb;
16819e77d1SZachary Turner 
174718f8b5SPeter Collingbourne // FIXME: This class is only here to support the transition to llvm::Error. It
184718f8b5SPeter Collingbourne // will be removed once this transition is complete. Clients should prefer to
194718f8b5SPeter Collingbourne // deal with the Error value directly, rather than converting to error_code.
206a7efef4SAlexandre Ganea class PDBErrorCategory : public std::error_category {
21819e77d1SZachary Turner public:
22990504e6SReid Kleckner   const char *name() const noexcept override { return "llvm.pdb"; }
23819e77d1SZachary Turner   std::string message(int Condition) const override {
246a7efef4SAlexandre Ganea     switch (static_cast<pdb_error_code>(Condition)) {
256a7efef4SAlexandre Ganea     case pdb_error_code::unspecified:
26819e77d1SZachary Turner       return "An unknown error has occurred.";
276a7efef4SAlexandre Ganea     case pdb_error_code::type_server_not_found:
286597c28dSReid Kleckner         return "Type server PDB was not found.";
296a7efef4SAlexandre Ganea     case pdb_error_code::dia_sdk_not_present:
30819e77d1SZachary Turner       return "LLVM was not compiled with support for DIA. This usually means "
319ff2380eSHiroshi Inoue              "that you are not using MSVC, or your Visual Studio "
326a7efef4SAlexandre Ganea              "installation is corrupt.";
336a7efef4SAlexandre Ganea     case pdb_error_code::dia_failed_loading:
346a7efef4SAlexandre Ganea       return "DIA is only supported when using MSVC.";
356a7efef4SAlexandre Ganea     case pdb_error_code::invalid_utf8_path:
366a7efef4SAlexandre Ganea       return "The PDB file path is an invalid UTF8 sequence.";
376a7efef4SAlexandre Ganea     case pdb_error_code::signature_out_of_date:
38*d93b07f0SAlexandre Ganea       return "The signature does not match; the file(s) might be out of date.";
39819e77d1SZachary Turner     }
40819e77d1SZachary Turner     llvm_unreachable("Unrecognized generic_error_code");
41819e77d1SZachary Turner   }
42819e77d1SZachary Turner };
43819e77d1SZachary Turner 
446a7efef4SAlexandre Ganea static llvm::ManagedStatic<PDBErrorCategory> PDBCategory;
456a7efef4SAlexandre Ganea const std::error_category &llvm::pdb::PDBErrCategory() { return *PDBCategory; }
46819e77d1SZachary Turner 
476a7efef4SAlexandre Ganea char PDBError::ID;
48