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 #include <string>
13 
14 using namespace llvm;
15 using namespace llvm::codeview;
16 
17 namespace {
18 // FIXME: This class is only here to support the transition to llvm::Error. It
19 // will be removed once this transition is complete. Clients should prefer to
20 // deal with the Error value directly, rather than converting to error_code.
21 class CodeViewErrorCategory : public std::error_category {
22 public:
23   const char *name() const noexcept override { return "llvm.codeview"; }
24   std::string message(int Condition) const override {
25     switch (static_cast<cv_error_code>(Condition)) {
26     case cv_error_code::unspecified:
27       return "An unknown CodeView error has occurred.";
28     case cv_error_code::insufficient_buffer:
29       return "The buffer is not large enough to read the requested number of "
30              "bytes.";
31     case cv_error_code::corrupt_record:
32       return "The CodeView record is corrupted.";
33     case cv_error_code::no_records:
34       return "There are no records.";
35     case cv_error_code::operation_unsupported:
36       return "The requested operation is not supported.";
37     case cv_error_code::unknown_member_record:
38       return "The member record is of an unknown type.";
39     }
40     llvm_unreachable("Unrecognized cv_error_code");
41   }
42 };
43 } // namespace
44 
45 static llvm::ManagedStatic<CodeViewErrorCategory> CodeViewErrCategory;
46 const std::error_category &llvm::codeview::CVErrorCategory() {
47   return *CodeViewErrCategory;
48 }
49 
50 char CodeViewError::ID;
51