Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 1 | //===- Error.cpp - system_error extensions for PDB --------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/DebugInfo/PDB/GenericError.h" |
| 11 | #include "llvm/Support/ErrorHandling.h" |
| 12 | #include "llvm/Support/ManagedStatic.h" |
| 13 | |
| 14 | using namespace llvm; |
| 15 | using namespace llvm::pdb; |
| 16 | |
Peter Collingbourne | 4718f8b | 2016-05-24 20:13:46 +0000 | [diff] [blame] | 17 | // FIXME: This class is only here to support the transition to llvm::Error. It |
| 18 | // will be removed once this transition is complete. Clients should prefer to |
| 19 | // deal with the Error value directly, rather than converting to error_code. |
Alexandre Ganea | 6a7efef | 2018-08-31 17:41:58 +0000 | [diff] [blame] | 20 | class PDBErrorCategory : public std::error_category { |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 21 | public: |
Reid Kleckner | 990504e | 2016-10-19 23:52:38 +0000 | [diff] [blame] | 22 | const char *name() const noexcept override { return "llvm.pdb"; } |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 23 | std::string message(int Condition) const override { |
Alexandre Ganea | 6a7efef | 2018-08-31 17:41:58 +0000 | [diff] [blame] | 24 | switch (static_cast<pdb_error_code>(Condition)) { |
| 25 | case pdb_error_code::unspecified: |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 26 | return "An unknown error has occurred."; |
Alexandre Ganea | 6a7efef | 2018-08-31 17:41:58 +0000 | [diff] [blame] | 27 | case pdb_error_code::dia_sdk_not_present: |
| 28 | return "LLVM was not compiled with support for DIA. This usually means " |
Hiroshi Inoue | 9ff2380 | 2018-04-09 04:37:53 +0000 | [diff] [blame] | 29 | "that you are not using MSVC, or your Visual Studio " |
Alexandre Ganea | 6a7efef | 2018-08-31 17:41:58 +0000 | [diff] [blame] | 30 | "installation is corrupt."; |
| 31 | case pdb_error_code::dia_failed_loading: |
| 32 | return "DIA is only supported when using MSVC."; |
| 33 | case pdb_error_code::invalid_utf8_path: |
| 34 | return "The PDB file path is an invalid UTF8 sequence."; |
| 35 | case pdb_error_code::signature_out_of_date: |
Alexandre Ganea | d93b07f | 2018-09-10 13:51:21 +0000 | [diff] [blame] | 36 | return "The signature does not match; the file(s) might be out of date."; |
Alexandre Ganea | 4b29572 | 2018-11-08 14:42:37 +0000 | [diff] [blame] | 37 | case pdb_error_code::external_cmdline_ref: |
| 38 | return "The path to this file must be provided on the command-line."; |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 39 | } |
| 40 | llvm_unreachable("Unrecognized generic_error_code"); |
| 41 | } |
| 42 | }; |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 43 | |
Alexandre Ganea | 6a7efef | 2018-08-31 17:41:58 +0000 | [diff] [blame] | 44 | static llvm::ManagedStatic<PDBErrorCategory> PDBCategory; |
| 45 | const std::error_category &llvm::pdb::PDBErrCategory() { return *PDBCategory; } |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 46 | |
Alexandre Ganea | 6a7efef | 2018-08-31 17:41:58 +0000 | [diff] [blame] | 47 | char PDBError::ID; |