xref: /src/contrib/llvm-project/llvm/lib/DebugInfo/PDB/GenericError.cpp (revision 753f127f3ace09432b2baeffd71a308760641a62)
101095a5dSDimitry Andric //===- Error.cpp - system_error extensions for PDB --------------*- C++ -*-===//
201095a5dSDimitry Andric //
3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
601095a5dSDimitry Andric //
701095a5dSDimitry Andric //===----------------------------------------------------------------------===//
801095a5dSDimitry Andric 
901095a5dSDimitry Andric #include "llvm/DebugInfo/PDB/GenericError.h"
1001095a5dSDimitry Andric #include "llvm/Support/ErrorHandling.h"
1101095a5dSDimitry Andric 
1201095a5dSDimitry Andric using namespace llvm;
1301095a5dSDimitry Andric using namespace llvm::pdb;
1401095a5dSDimitry Andric 
15e6d15924SDimitry Andric namespace {
1601095a5dSDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It
1701095a5dSDimitry Andric // will be removed once this transition is complete. Clients should prefer to
1801095a5dSDimitry Andric // deal with the Error value directly, rather than converting to error_code.
19d8e91e46SDimitry Andric class PDBErrorCategory : public std::error_category {
2001095a5dSDimitry Andric public:
name() const21b915e9e0SDimitry Andric   const char *name() const noexcept override { return "llvm.pdb"; }
message(int Condition) const2201095a5dSDimitry Andric   std::string message(int Condition) const override {
23d8e91e46SDimitry Andric     switch (static_cast<pdb_error_code>(Condition)) {
24d8e91e46SDimitry Andric     case pdb_error_code::unspecified:
2501095a5dSDimitry Andric       return "An unknown error has occurred.";
26d8e91e46SDimitry Andric     case pdb_error_code::dia_sdk_not_present:
2701095a5dSDimitry Andric       return "LLVM was not compiled with support for DIA. This usually means "
28eb11fae6SDimitry Andric              "that you are not using MSVC, or your Visual Studio "
29d8e91e46SDimitry Andric              "installation is corrupt.";
30d8e91e46SDimitry Andric     case pdb_error_code::dia_failed_loading:
31d8e91e46SDimitry Andric       return "DIA is only supported when using MSVC.";
32d8e91e46SDimitry Andric     case pdb_error_code::invalid_utf8_path:
33d8e91e46SDimitry Andric       return "The PDB file path is an invalid UTF8 sequence.";
34d8e91e46SDimitry Andric     case pdb_error_code::signature_out_of_date:
35d8e91e46SDimitry Andric       return "The signature does not match; the file(s) might be out of date.";
361d5ae102SDimitry Andric     case pdb_error_code::no_matching_pch:
371d5ae102SDimitry Andric       return "No matching precompiled header could be located.";
3801095a5dSDimitry Andric     }
3901095a5dSDimitry Andric     llvm_unreachable("Unrecognized generic_error_code");
4001095a5dSDimitry Andric   }
4101095a5dSDimitry Andric };
42e6d15924SDimitry Andric } // namespace
4301095a5dSDimitry Andric 
PDBErrCategory()441f917f69SDimitry Andric const std::error_category &llvm::pdb::PDBErrCategory() {
451f917f69SDimitry Andric   static PDBErrorCategory PDBCategory;
461f917f69SDimitry Andric   return PDBCategory;
471f917f69SDimitry Andric }
4801095a5dSDimitry Andric 
49d8e91e46SDimitry Andric char PDBError::ID;
50