1*0b57cec5SDimitry Andric //===- CodeViewError.cpp - Error extensions for CodeView --------*- C++ -*-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "llvm/DebugInfo/CodeView/CodeViewError.h"
10*0b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h"
11*0b57cec5SDimitry Andric #include <string>
12*0b57cec5SDimitry Andric 
13*0b57cec5SDimitry Andric using namespace llvm;
14*0b57cec5SDimitry Andric using namespace llvm::codeview;
15*0b57cec5SDimitry Andric 
16*0b57cec5SDimitry Andric namespace {
17*0b57cec5SDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It
18*0b57cec5SDimitry Andric // will be removed once this transition is complete. Clients should prefer to
19*0b57cec5SDimitry Andric // deal with the Error value directly, rather than converting to error_code.
20*0b57cec5SDimitry Andric class CodeViewErrorCategory : public std::error_category {
21*0b57cec5SDimitry Andric public:
name() const22*0b57cec5SDimitry Andric   const char *name() const noexcept override { return "llvm.codeview"; }
message(int Condition) const23*0b57cec5SDimitry Andric   std::string message(int Condition) const override {
24*0b57cec5SDimitry Andric     switch (static_cast<cv_error_code>(Condition)) {
25*0b57cec5SDimitry Andric     case cv_error_code::unspecified:
26*0b57cec5SDimitry Andric       return "An unknown CodeView error has occurred.";
27*0b57cec5SDimitry Andric     case cv_error_code::insufficient_buffer:
28*0b57cec5SDimitry Andric       return "The buffer is not large enough to read the requested number of "
29*0b57cec5SDimitry Andric              "bytes.";
30*0b57cec5SDimitry Andric     case cv_error_code::corrupt_record:
31*0b57cec5SDimitry Andric       return "The CodeView record is corrupted.";
32*0b57cec5SDimitry Andric     case cv_error_code::no_records:
33*0b57cec5SDimitry Andric       return "There are no records.";
34*0b57cec5SDimitry Andric     case cv_error_code::operation_unsupported:
35*0b57cec5SDimitry Andric       return "The requested operation is not supported.";
36*0b57cec5SDimitry Andric     case cv_error_code::unknown_member_record:
37*0b57cec5SDimitry Andric       return "The member record is of an unknown type.";
38*0b57cec5SDimitry Andric     }
39*0b57cec5SDimitry Andric     llvm_unreachable("Unrecognized cv_error_code");
40*0b57cec5SDimitry Andric   }
41*0b57cec5SDimitry Andric };
42*0b57cec5SDimitry Andric } // namespace
43*0b57cec5SDimitry Andric 
CVErrorCategory()44*0b57cec5SDimitry Andric const std::error_category &llvm::codeview::CVErrorCategory() {
45*0b57cec5SDimitry Andric   static CodeViewErrorCategory CodeViewErrCategory;
46*0b57cec5SDimitry Andric   return CodeViewErrCategory;
47*0b57cec5SDimitry Andric }
48*0b57cec5SDimitry Andric 
49*0b57cec5SDimitry Andric char CodeViewError::ID;
50