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