1819e77d1SZachary Turner //===- Error.cpp - system_error extensions for PDB --------------*- C++ -*-===//
2819e77d1SZachary Turner //
3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6819e77d1SZachary Turner //
7819e77d1SZachary Turner //===----------------------------------------------------------------------===//
8819e77d1SZachary Turner 
9819e77d1SZachary Turner #include "llvm/DebugInfo/PDB/GenericError.h"
10819e77d1SZachary Turner #include "llvm/Support/ErrorHandling.h"
11819e77d1SZachary Turner #include "llvm/Support/ManagedStatic.h"
12819e77d1SZachary Turner 
13819e77d1SZachary Turner using namespace llvm;
14819e77d1SZachary Turner using namespace llvm::pdb;
15819e77d1SZachary Turner 
164718f8b5SPeter Collingbourne // FIXME: This class is only here to support the transition to llvm::Error. It
174718f8b5SPeter Collingbourne // will be removed once this transition is complete. Clients should prefer to
184718f8b5SPeter Collingbourne // deal with the Error value directly, rather than converting to error_code.
196a7efef4SAlexandre Ganea class PDBErrorCategory : public std::error_category {
20819e77d1SZachary Turner public:
21990504e6SReid Kleckner   const char *name() const noexcept override { return "llvm.pdb"; }
22819e77d1SZachary Turner   std::string message(int Condition) const override {
236a7efef4SAlexandre Ganea     switch (static_cast<pdb_error_code>(Condition)) {
246a7efef4SAlexandre Ganea     case pdb_error_code::unspecified:
25819e77d1SZachary Turner       return "An unknown error has occurred.";
266a7efef4SAlexandre Ganea     case pdb_error_code::dia_sdk_not_present:
27819e77d1SZachary Turner       return "LLVM was not compiled with support for DIA. This usually means "
289ff2380eSHiroshi Inoue              "that you are not using MSVC, or your Visual Studio "
296a7efef4SAlexandre Ganea              "installation is corrupt.";
306a7efef4SAlexandre Ganea     case pdb_error_code::dia_failed_loading:
316a7efef4SAlexandre Ganea       return "DIA is only supported when using MSVC.";
326a7efef4SAlexandre Ganea     case pdb_error_code::invalid_utf8_path:
336a7efef4SAlexandre Ganea       return "The PDB file path is an invalid UTF8 sequence.";
346a7efef4SAlexandre Ganea     case pdb_error_code::signature_out_of_date:
35d93b07f0SAlexandre Ganea       return "The signature does not match; the file(s) might be out of date.";
364b295724SAlexandre Ganea     case pdb_error_code::external_cmdline_ref:
374b295724SAlexandre Ganea       return "The path to this file must be provided on the command-line.";
38819e77d1SZachary Turner     }
39819e77d1SZachary Turner     llvm_unreachable("Unrecognized generic_error_code");
40819e77d1SZachary Turner   }
41819e77d1SZachary Turner };
42819e77d1SZachary Turner 
436a7efef4SAlexandre Ganea static llvm::ManagedStatic<PDBErrorCategory> PDBCategory;
446a7efef4SAlexandre Ganea const std::error_category &llvm::pdb::PDBErrCategory() { return *PDBCategory; }
45819e77d1SZachary Turner 
466a7efef4SAlexandre Ganea char PDBError::ID;
47