101095a5dSDimitry Andric //===- CodeViewError.cpp - Error extensions for CodeView --------*- C++ -*-===// 201095a5dSDimitry Andric // 3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 601095a5dSDimitry Andric // 701095a5dSDimitry Andric //===----------------------------------------------------------------------===// 801095a5dSDimitry Andric 901095a5dSDimitry Andric #include "llvm/DebugInfo/CodeView/CodeViewError.h" 1001095a5dSDimitry Andric #include "llvm/Support/ErrorHandling.h" 11344a3780SDimitry Andric #include <string> 1201095a5dSDimitry Andric 1301095a5dSDimitry Andric using namespace llvm; 1401095a5dSDimitry Andric using namespace llvm::codeview; 1501095a5dSDimitry Andric 16e6d15924SDimitry Andric namespace { 1701095a5dSDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It 1801095a5dSDimitry Andric // will be removed once this transition is complete. Clients should prefer to 1901095a5dSDimitry Andric // deal with the Error value directly, rather than converting to error_code. 2001095a5dSDimitry Andric class CodeViewErrorCategory : public std::error_category { 2101095a5dSDimitry Andric public: name() const22b915e9e0SDimitry Andric const char *name() const noexcept override { return "llvm.codeview"; } message(int Condition) const2301095a5dSDimitry Andric std::string message(int Condition) const override { 2401095a5dSDimitry Andric switch (static_cast<cv_error_code>(Condition)) { 2501095a5dSDimitry Andric case cv_error_code::unspecified: 26d8e91e46SDimitry Andric return "An unknown CodeView error has occurred."; 2701095a5dSDimitry Andric case cv_error_code::insufficient_buffer: 2801095a5dSDimitry Andric return "The buffer is not large enough to read the requested number of " 2901095a5dSDimitry Andric "bytes."; 3001095a5dSDimitry Andric case cv_error_code::corrupt_record: 3101095a5dSDimitry Andric return "The CodeView record is corrupted."; 3271d5a254SDimitry Andric case cv_error_code::no_records: 33d8e91e46SDimitry Andric return "There are no records."; 3401095a5dSDimitry Andric case cv_error_code::operation_unsupported: 3501095a5dSDimitry Andric return "The requested operation is not supported."; 36b915e9e0SDimitry Andric case cv_error_code::unknown_member_record: 37b915e9e0SDimitry Andric return "The member record is of an unknown type."; 3801095a5dSDimitry Andric } 3901095a5dSDimitry Andric llvm_unreachable("Unrecognized cv_error_code"); 4001095a5dSDimitry Andric } 4101095a5dSDimitry Andric }; 42e6d15924SDimitry Andric } // namespace 4301095a5dSDimitry Andric CVErrorCategory()44d8e91e46SDimitry Andricconst std::error_category &llvm::codeview::CVErrorCategory() { 451f917f69SDimitry Andric static CodeViewErrorCategory CodeViewErrCategory; 461f917f69SDimitry Andric return CodeViewErrCategory; 4701095a5dSDimitry Andric } 4801095a5dSDimitry Andric 49d8e91e46SDimitry Andric char CodeViewError::ID; 50