13ca95b02SDimitry Andric //===- Error.cpp - system_error extensions for PDB --------------*- C++ -*-===//
23ca95b02SDimitry Andric //
33ca95b02SDimitry Andric //                     The LLVM Compiler Infrastructure
43ca95b02SDimitry Andric //
53ca95b02SDimitry Andric // This file is distributed under the University of Illinois Open Source
63ca95b02SDimitry Andric // License. See LICENSE.TXT for details.
73ca95b02SDimitry Andric //
83ca95b02SDimitry Andric //===----------------------------------------------------------------------===//
93ca95b02SDimitry Andric 
103ca95b02SDimitry Andric #include "llvm/DebugInfo/PDB/GenericError.h"
113ca95b02SDimitry Andric #include "llvm/Support/ErrorHandling.h"
123ca95b02SDimitry Andric #include "llvm/Support/ManagedStatic.h"
133ca95b02SDimitry Andric 
143ca95b02SDimitry Andric using namespace llvm;
153ca95b02SDimitry Andric using namespace llvm::pdb;
163ca95b02SDimitry Andric 
173ca95b02SDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It
183ca95b02SDimitry Andric // will be removed once this transition is complete. Clients should prefer to
193ca95b02SDimitry Andric // deal with the Error value directly, rather than converting to error_code.
20*b5893f02SDimitry Andric class PDBErrorCategory : public std::error_category {
213ca95b02SDimitry Andric public:
name() const22d88c1a5aSDimitry Andric   const char *name() const noexcept override { return "llvm.pdb"; }
message(int Condition) const233ca95b02SDimitry Andric   std::string message(int Condition) const override {
24*b5893f02SDimitry Andric     switch (static_cast<pdb_error_code>(Condition)) {
25*b5893f02SDimitry Andric     case pdb_error_code::unspecified:
263ca95b02SDimitry Andric       return "An unknown error has occurred.";
27*b5893f02SDimitry Andric     case pdb_error_code::dia_sdk_not_present:
283ca95b02SDimitry Andric       return "LLVM was not compiled with support for DIA. This usually means "
294ba319b5SDimitry Andric              "that you are not using MSVC, or your Visual Studio "
30*b5893f02SDimitry Andric              "installation is corrupt.";
31*b5893f02SDimitry Andric     case pdb_error_code::dia_failed_loading:
32*b5893f02SDimitry Andric       return "DIA is only supported when using MSVC.";
33*b5893f02SDimitry Andric     case pdb_error_code::invalid_utf8_path:
34*b5893f02SDimitry Andric       return "The PDB file path is an invalid UTF8 sequence.";
35*b5893f02SDimitry Andric     case pdb_error_code::signature_out_of_date:
36*b5893f02SDimitry Andric       return "The signature does not match; the file(s) might be out of date.";
37*b5893f02SDimitry Andric     case pdb_error_code::external_cmdline_ref:
38*b5893f02SDimitry Andric       return "The path to this file must be provided on the command-line.";
393ca95b02SDimitry Andric     }
403ca95b02SDimitry Andric     llvm_unreachable("Unrecognized generic_error_code");
413ca95b02SDimitry Andric   }
423ca95b02SDimitry Andric };
433ca95b02SDimitry Andric 
44*b5893f02SDimitry Andric static llvm::ManagedStatic<PDBErrorCategory> PDBCategory;
PDBErrCategory()45*b5893f02SDimitry Andric const std::error_category &llvm::pdb::PDBErrCategory() { return *PDBCategory; }
463ca95b02SDimitry Andric 
47*b5893f02SDimitry Andric char PDBError::ID;
48