1*0b57cec5SDimitry Andric //===- Error.cpp - system_error extensions for PDB --------------*- C++ -*-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/GenericError.h"
10*0b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h"
11*0b57cec5SDimitry Andric #include "llvm/Support/ManagedStatic.h"
12*0b57cec5SDimitry Andric 
13*0b57cec5SDimitry Andric using namespace llvm;
14*0b57cec5SDimitry Andric using namespace llvm::pdb;
15*0b57cec5SDimitry Andric 
16*0b57cec5SDimitry Andric namespace {
17*0b57cec5SDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It
18*0b57cec5SDimitry Andric // will be removed once this transition is complete. Clients should prefer to
19*0b57cec5SDimitry Andric // deal with the Error value directly, rather than converting to error_code.
20*0b57cec5SDimitry Andric class PDBErrorCategory : public std::error_category {
21*0b57cec5SDimitry Andric public:
name() const22*0b57cec5SDimitry Andric   const char *name() const noexcept override { return "llvm.pdb"; }
message(int Condition) const23*0b57cec5SDimitry Andric   std::string message(int Condition) const override {
24*0b57cec5SDimitry Andric     switch (static_cast<pdb_error_code>(Condition)) {
25*0b57cec5SDimitry Andric     case pdb_error_code::unspecified:
26*0b57cec5SDimitry Andric       return "An unknown error has occurred.";
27*0b57cec5SDimitry Andric     case pdb_error_code::dia_sdk_not_present:
28*0b57cec5SDimitry Andric       return "LLVM was not compiled with support for DIA. This usually means "
29*0b57cec5SDimitry Andric              "that you are not using MSVC, or your Visual Studio "
30*0b57cec5SDimitry Andric              "installation is corrupt.";
31*0b57cec5SDimitry Andric     case pdb_error_code::dia_failed_loading:
32*0b57cec5SDimitry Andric       return "DIA is only supported when using MSVC.";
33*0b57cec5SDimitry Andric     case pdb_error_code::invalid_utf8_path:
34*0b57cec5SDimitry Andric       return "The PDB file path is an invalid UTF8 sequence.";
35*0b57cec5SDimitry Andric     case pdb_error_code::signature_out_of_date:
36*0b57cec5SDimitry Andric       return "The signature does not match; the file(s) might be out of date.";
37*0b57cec5SDimitry Andric     case pdb_error_code::no_matching_pch:
38*0b57cec5SDimitry Andric       return "No matching precompiled header could be located.";
39*0b57cec5SDimitry Andric     }
40*0b57cec5SDimitry Andric     llvm_unreachable("Unrecognized generic_error_code");
41*0b57cec5SDimitry Andric   }
42*0b57cec5SDimitry Andric };
43*0b57cec5SDimitry Andric } // namespace
44*0b57cec5SDimitry Andric 
45*0b57cec5SDimitry Andric static llvm::ManagedStatic<PDBErrorCategory> PDBCategory;
PDBErrCategory()46*0b57cec5SDimitry Andric const std::error_category &llvm::pdb::PDBErrCategory() { return *PDBCategory; }
47*0b57cec5SDimitry Andric 
48*0b57cec5SDimitry Andric char PDBError::ID;
49