1d5d37dcfSZachary Turner //===- CodeViewError.cpp - Error extensions for CodeView --------*- C++ -*-===// 2d5d37dcfSZachary Turner // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6d5d37dcfSZachary Turner // 7d5d37dcfSZachary Turner //===----------------------------------------------------------------------===// 8d5d37dcfSZachary Turner 9d5d37dcfSZachary Turner #include "llvm/DebugInfo/CodeView/CodeViewError.h" 10d5d37dcfSZachary Turner #include "llvm/Support/ErrorHandling.h" 11d5d37dcfSZachary Turner #include "llvm/Support/ManagedStatic.h" 12*9277ce79SSimon Pilgrim #include <string> 13d5d37dcfSZachary Turner 14d5d37dcfSZachary Turner using namespace llvm; 15d5d37dcfSZachary Turner using namespace llvm::codeview; 16d5d37dcfSZachary Turner 17711950c1SBenjamin Kramer namespace { 18d5d37dcfSZachary Turner // FIXME: This class is only here to support the transition to llvm::Error. It 19d5d37dcfSZachary Turner // will be removed once this transition is complete. Clients should prefer to 20d5d37dcfSZachary Turner // deal with the Error value directly, rather than converting to error_code. 21d5d37dcfSZachary Turner class CodeViewErrorCategory : public std::error_category { 22d5d37dcfSZachary Turner public: 23990504e6SReid Kleckner const char *name() const noexcept override { return "llvm.codeview"; } 24d5d37dcfSZachary Turner std::string message(int Condition) const override { 25d5d37dcfSZachary Turner switch (static_cast<cv_error_code>(Condition)) { 26d5d37dcfSZachary Turner case cv_error_code::unspecified: 276a7efef4SAlexandre Ganea return "An unknown CodeView error has occurred."; 28d5d37dcfSZachary Turner case cv_error_code::insufficient_buffer: 29d5d37dcfSZachary Turner return "The buffer is not large enough to read the requested number of " 30d5d37dcfSZachary Turner "bytes."; 31d5d37dcfSZachary Turner case cv_error_code::corrupt_record: 32d5d37dcfSZachary Turner return "The CodeView record is corrupted."; 337b327d05SZachary Turner case cv_error_code::no_records: 346a7efef4SAlexandre Ganea return "There are no records."; 355acb4ac6SZachary Turner case cv_error_code::operation_unsupported: 365acb4ac6SZachary Turner return "The requested operation is not supported."; 375e3e4bb2SZachary Turner case cv_error_code::unknown_member_record: 385e3e4bb2SZachary Turner return "The member record is of an unknown type."; 39d5d37dcfSZachary Turner } 40d5d37dcfSZachary Turner llvm_unreachable("Unrecognized cv_error_code"); 41d5d37dcfSZachary Turner } 42d5d37dcfSZachary Turner }; 43711950c1SBenjamin Kramer } // namespace 44d5d37dcfSZachary Turner 456a7efef4SAlexandre Ganea static llvm::ManagedStatic<CodeViewErrorCategory> CodeViewErrCategory; 4671c43ceaSAlexandre Ganea const std::error_category &llvm::codeview::CVErrorCategory() { 4771c43ceaSAlexandre Ganea return *CodeViewErrCategory; 4871c43ceaSAlexandre Ganea } 49d5d37dcfSZachary Turner 506a7efef4SAlexandre Ganea char CodeViewError::ID; 51