10b57cec5SDimitry Andric //===- CodeViewError.cpp - Error extensions for CodeView --------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #include "llvm/DebugInfo/CodeView/CodeViewError.h" 100b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h" 11fe6060f1SDimitry Andric #include <string> 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric using namespace llvm; 140b57cec5SDimitry Andric using namespace llvm::codeview; 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric namespace { 170b57cec5SDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It 180b57cec5SDimitry Andric // will be removed once this transition is complete. Clients should prefer to 190b57cec5SDimitry Andric // deal with the Error value directly, rather than converting to error_code. 200b57cec5SDimitry Andric class CodeViewErrorCategory : public std::error_category { 210b57cec5SDimitry Andric public: name() const220b57cec5SDimitry Andric const char *name() const noexcept override { return "llvm.codeview"; } message(int Condition) const230b57cec5SDimitry Andric std::string message(int Condition) const override { 240b57cec5SDimitry Andric switch (static_cast<cv_error_code>(Condition)) { 250b57cec5SDimitry Andric case cv_error_code::unspecified: 260b57cec5SDimitry Andric return "An unknown CodeView error has occurred."; 270b57cec5SDimitry Andric case cv_error_code::insufficient_buffer: 280b57cec5SDimitry Andric return "The buffer is not large enough to read the requested number of " 290b57cec5SDimitry Andric "bytes."; 300b57cec5SDimitry Andric case cv_error_code::corrupt_record: 310b57cec5SDimitry Andric return "The CodeView record is corrupted."; 320b57cec5SDimitry Andric case cv_error_code::no_records: 330b57cec5SDimitry Andric return "There are no records."; 340b57cec5SDimitry Andric case cv_error_code::operation_unsupported: 350b57cec5SDimitry Andric return "The requested operation is not supported."; 360b57cec5SDimitry Andric case cv_error_code::unknown_member_record: 370b57cec5SDimitry Andric return "The member record is of an unknown type."; 380b57cec5SDimitry Andric } 390b57cec5SDimitry Andric llvm_unreachable("Unrecognized cv_error_code"); 400b57cec5SDimitry Andric } 410b57cec5SDimitry Andric }; 420b57cec5SDimitry Andric } // namespace 430b57cec5SDimitry Andric CVErrorCategory()440b57cec5SDimitry Andricconst std::error_category &llvm::codeview::CVErrorCategory() { 45*753f127fSDimitry Andric static CodeViewErrorCategory CodeViewErrCategory; 46*753f127fSDimitry Andric return CodeViewErrCategory; 470b57cec5SDimitry Andric } 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric char CodeViewError::ID; 50