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" 110b57cec5SDimitry Andric #include "llvm/Support/ManagedStatic.h" 12*5f7ddb14SDimitry Andric #include <string> 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric using namespace llvm; 150b57cec5SDimitry Andric using namespace llvm::codeview; 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric namespace { 180b57cec5SDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It 190b57cec5SDimitry Andric // will be removed once this transition is complete. Clients should prefer to 200b57cec5SDimitry Andric // deal with the Error value directly, rather than converting to error_code. 210b57cec5SDimitry Andric class CodeViewErrorCategory : public std::error_category { 220b57cec5SDimitry Andric public: name() const230b57cec5SDimitry Andric const char *name() const noexcept override { return "llvm.codeview"; } message(int Condition) const240b57cec5SDimitry Andric std::string message(int Condition) const override { 250b57cec5SDimitry Andric switch (static_cast<cv_error_code>(Condition)) { 260b57cec5SDimitry Andric case cv_error_code::unspecified: 270b57cec5SDimitry Andric return "An unknown CodeView error has occurred."; 280b57cec5SDimitry Andric case cv_error_code::insufficient_buffer: 290b57cec5SDimitry Andric return "The buffer is not large enough to read the requested number of " 300b57cec5SDimitry Andric "bytes."; 310b57cec5SDimitry Andric case cv_error_code::corrupt_record: 320b57cec5SDimitry Andric return "The CodeView record is corrupted."; 330b57cec5SDimitry Andric case cv_error_code::no_records: 340b57cec5SDimitry Andric return "There are no records."; 350b57cec5SDimitry Andric case cv_error_code::operation_unsupported: 360b57cec5SDimitry Andric return "The requested operation is not supported."; 370b57cec5SDimitry Andric case cv_error_code::unknown_member_record: 380b57cec5SDimitry Andric return "The member record is of an unknown type."; 390b57cec5SDimitry Andric } 400b57cec5SDimitry Andric llvm_unreachable("Unrecognized cv_error_code"); 410b57cec5SDimitry Andric } 420b57cec5SDimitry Andric }; 430b57cec5SDimitry Andric } // namespace 440b57cec5SDimitry Andric 450b57cec5SDimitry Andric static llvm::ManagedStatic<CodeViewErrorCategory> CodeViewErrCategory; CVErrorCategory()460b57cec5SDimitry Andricconst std::error_category &llvm::codeview::CVErrorCategory() { 470b57cec5SDimitry Andric return *CodeViewErrCategory; 480b57cec5SDimitry Andric } 490b57cec5SDimitry Andric 500b57cec5SDimitry Andric char CodeViewError::ID; 51