xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/PDB/GenericError.cpp (revision 753f127f3ace09432b2baeffd71a308760641a62)
10b57cec5SDimitry Andric //===- Error.cpp - system_error extensions for PDB --------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/GenericError.h"
100b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h"
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric using namespace llvm;
130b57cec5SDimitry Andric using namespace llvm::pdb;
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric namespace {
160b57cec5SDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It
170b57cec5SDimitry Andric // will be removed once this transition is complete. Clients should prefer to
180b57cec5SDimitry Andric // deal with the Error value directly, rather than converting to error_code.
190b57cec5SDimitry Andric class PDBErrorCategory : public std::error_category {
200b57cec5SDimitry Andric public:
name() const210b57cec5SDimitry Andric   const char *name() const noexcept override { return "llvm.pdb"; }
message(int Condition) const220b57cec5SDimitry Andric   std::string message(int Condition) const override {
230b57cec5SDimitry Andric     switch (static_cast<pdb_error_code>(Condition)) {
240b57cec5SDimitry Andric     case pdb_error_code::unspecified:
250b57cec5SDimitry Andric       return "An unknown error has occurred.";
260b57cec5SDimitry Andric     case pdb_error_code::dia_sdk_not_present:
270b57cec5SDimitry Andric       return "LLVM was not compiled with support for DIA. This usually means "
280b57cec5SDimitry Andric              "that you are not using MSVC, or your Visual Studio "
290b57cec5SDimitry Andric              "installation is corrupt.";
300b57cec5SDimitry Andric     case pdb_error_code::dia_failed_loading:
310b57cec5SDimitry Andric       return "DIA is only supported when using MSVC.";
320b57cec5SDimitry Andric     case pdb_error_code::invalid_utf8_path:
330b57cec5SDimitry Andric       return "The PDB file path is an invalid UTF8 sequence.";
340b57cec5SDimitry Andric     case pdb_error_code::signature_out_of_date:
350b57cec5SDimitry Andric       return "The signature does not match; the file(s) might be out of date.";
368bcb0991SDimitry Andric     case pdb_error_code::no_matching_pch:
378bcb0991SDimitry Andric       return "No matching precompiled header could be located.";
380b57cec5SDimitry Andric     }
390b57cec5SDimitry Andric     llvm_unreachable("Unrecognized generic_error_code");
400b57cec5SDimitry Andric   }
410b57cec5SDimitry Andric };
420b57cec5SDimitry Andric } // namespace
430b57cec5SDimitry Andric 
PDBErrCategory()44*753f127fSDimitry Andric const std::error_category &llvm::pdb::PDBErrCategory() {
45*753f127fSDimitry Andric   static PDBErrorCategory PDBCategory;
46*753f127fSDimitry Andric   return PDBCategory;
47*753f127fSDimitry Andric }
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric char PDBError::ID;
50