Zachary Turner | d5d37dc | 2016-05-25 20:37:03 +0000 | [diff] [blame] | 1 | //===- CodeViewError.cpp - Error extensions for CodeView --------*- 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/CodeView/CodeViewError.h" |
| 11 | #include "llvm/Support/ErrorHandling.h" |
| 12 | #include "llvm/Support/ManagedStatic.h" |
| 13 | |
| 14 | using namespace llvm; |
| 15 | using namespace llvm::codeview; |
| 16 | |
Zachary Turner | d5d37dc | 2016-05-25 20:37:03 +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. |
| 20 | class CodeViewErrorCategory : public std::error_category { |
| 21 | public: |
Reid Kleckner | 990504e | 2016-10-19 23:52:38 +0000 | [diff] [blame] | 22 | const char *name() const noexcept override { return "llvm.codeview"; } |
Zachary Turner | d5d37dc | 2016-05-25 20:37:03 +0000 | [diff] [blame] | 23 | std::string message(int Condition) const override { |
| 24 | switch (static_cast<cv_error_code>(Condition)) { |
| 25 | case cv_error_code::unspecified: |
Alexandre Ganea | 6a7efef | 2018-08-31 17:41:58 +0000 | [diff] [blame] | 26 | return "An unknown CodeView error has occurred."; |
Zachary Turner | d5d37dc | 2016-05-25 20:37:03 +0000 | [diff] [blame] | 27 | case cv_error_code::insufficient_buffer: |
| 28 | return "The buffer is not large enough to read the requested number of " |
| 29 | "bytes."; |
| 30 | case cv_error_code::corrupt_record: |
| 31 | return "The CodeView record is corrupted."; |
Zachary Turner | 7b327d0 | 2017-02-16 23:35:45 +0000 | [diff] [blame] | 32 | case cv_error_code::no_records: |
Alexandre Ganea | 6a7efef | 2018-08-31 17:41:58 +0000 | [diff] [blame] | 33 | return "There are no records."; |
Zachary Turner | 5acb4ac | 2016-06-10 05:09:12 +0000 | [diff] [blame] | 34 | case cv_error_code::operation_unsupported: |
| 35 | return "The requested operation is not supported."; |
Zachary Turner | 5e3e4bb | 2016-08-05 21:45:34 +0000 | [diff] [blame] | 36 | case cv_error_code::unknown_member_record: |
| 37 | return "The member record is of an unknown type."; |
Zachary Turner | d5d37dc | 2016-05-25 20:37:03 +0000 | [diff] [blame] | 38 | } |
| 39 | llvm_unreachable("Unrecognized cv_error_code"); |
| 40 | } |
| 41 | }; |
Zachary Turner | d5d37dc | 2016-05-25 20:37:03 +0000 | [diff] [blame] | 42 | |
Alexandre Ganea | 6a7efef | 2018-08-31 17:41:58 +0000 | [diff] [blame] | 43 | static llvm::ManagedStatic<CodeViewErrorCategory> CodeViewErrCategory; |
Alexandre Ganea | 71c43ce | 2018-11-05 19:20:47 +0000 | [diff] [blame] | 44 | const std::error_category &llvm::codeview::CVErrorCategory() { |
| 45 | return *CodeViewErrCategory; |
| 46 | } |
Zachary Turner | d5d37dc | 2016-05-25 20:37:03 +0000 | [diff] [blame] | 47 | |
Alexandre Ganea | 6a7efef | 2018-08-31 17:41:58 +0000 | [diff] [blame] | 48 | char CodeViewError::ID; |