1d5d37dcfSZachary Turner //===- CodeViewError.cpp - Error extensions for CodeView --------*- C++ -*-===// 2d5d37dcfSZachary 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 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" 12d5d37dcfSZachary Turner 13d5d37dcfSZachary Turner using namespace llvm; 14d5d37dcfSZachary Turner using namespace llvm::codeview; 15d5d37dcfSZachary Turner 16d5d37dcfSZachary Turner // FIXME: This class is only here to support the transition to llvm::Error. It 17d5d37dcfSZachary Turner // will be removed once this transition is complete. Clients should prefer to 18d5d37dcfSZachary Turner // deal with the Error value directly, rather than converting to error_code. 19d5d37dcfSZachary Turner class CodeViewErrorCategory : public std::error_category { 20d5d37dcfSZachary Turner public: 21990504e6SReid Kleckner const char *name() const noexcept override { return "llvm.codeview"; } 22d5d37dcfSZachary Turner std::string message(int Condition) const override { 23d5d37dcfSZachary Turner switch (static_cast<cv_error_code>(Condition)) { 24d5d37dcfSZachary Turner case cv_error_code::unspecified: 256a7efef4SAlexandre Ganea return "An unknown CodeView error has occurred."; 26d5d37dcfSZachary Turner case cv_error_code::insufficient_buffer: 27d5d37dcfSZachary Turner return "The buffer is not large enough to read the requested number of " 28d5d37dcfSZachary Turner "bytes."; 29d5d37dcfSZachary Turner case cv_error_code::corrupt_record: 30d5d37dcfSZachary Turner return "The CodeView record is corrupted."; 317b327d05SZachary Turner case cv_error_code::no_records: 326a7efef4SAlexandre Ganea return "There are no records."; 335acb4ac6SZachary Turner case cv_error_code::operation_unsupported: 345acb4ac6SZachary Turner return "The requested operation is not supported."; 355e3e4bb2SZachary Turner case cv_error_code::unknown_member_record: 365e3e4bb2SZachary Turner return "The member record is of an unknown type."; 37d5d37dcfSZachary Turner } 38d5d37dcfSZachary Turner llvm_unreachable("Unrecognized cv_error_code"); 39d5d37dcfSZachary Turner } 40d5d37dcfSZachary Turner }; 41d5d37dcfSZachary Turner 426a7efef4SAlexandre Ganea static llvm::ManagedStatic<CodeViewErrorCategory> CodeViewErrCategory; 4371c43ceaSAlexandre Ganea const std::error_category &llvm::codeview::CVErrorCategory() { 4471c43ceaSAlexandre Ganea return *CodeViewErrCategory; 4571c43ceaSAlexandre Ganea } 46d5d37dcfSZachary Turner 476a7efef4SAlexandre Ganea char CodeViewError::ID; 48