xref: /llvm-project/llvm/lib/DebugInfo/CodeView/CodeViewError.cpp (revision ede600377cb6df1bef71f070130d8cfe734cc5b7)
1d5d37dcfSZachary Turner //===- CodeViewError.cpp - Error extensions for CodeView --------*- C++ -*-===//
2d5d37dcfSZachary Turner //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6d5d37dcfSZachary Turner //
7d5d37dcfSZachary Turner //===----------------------------------------------------------------------===//
8d5d37dcfSZachary Turner 
9d5d37dcfSZachary Turner #include "llvm/DebugInfo/CodeView/CodeViewError.h"
10d5d37dcfSZachary Turner #include "llvm/Support/ErrorHandling.h"
119277ce79SSimon Pilgrim #include <string>
12d5d37dcfSZachary Turner 
13d5d37dcfSZachary Turner using namespace llvm;
14d5d37dcfSZachary Turner using namespace llvm::codeview;
15d5d37dcfSZachary Turner 
16711950c1SBenjamin Kramer namespace {
17d5d37dcfSZachary Turner // FIXME: This class is only here to support the transition to llvm::Error. It
18d5d37dcfSZachary Turner // will be removed once this transition is complete. Clients should prefer to
19d5d37dcfSZachary Turner // deal with the Error value directly, rather than converting to error_code.
20d5d37dcfSZachary Turner class CodeViewErrorCategory : public std::error_category {
21d5d37dcfSZachary Turner public:
name() const22990504e6SReid Kleckner   const char *name() const noexcept override { return "llvm.codeview"; }
message(int Condition) const23d5d37dcfSZachary Turner   std::string message(int Condition) const override {
24d5d37dcfSZachary Turner     switch (static_cast<cv_error_code>(Condition)) {
25d5d37dcfSZachary Turner     case cv_error_code::unspecified:
266a7efef4SAlexandre Ganea       return "An unknown CodeView error has occurred.";
27d5d37dcfSZachary Turner     case cv_error_code::insufficient_buffer:
28d5d37dcfSZachary Turner       return "The buffer is not large enough to read the requested number of "
29d5d37dcfSZachary Turner              "bytes.";
30d5d37dcfSZachary Turner     case cv_error_code::corrupt_record:
31d5d37dcfSZachary Turner       return "The CodeView record is corrupted.";
327b327d05SZachary Turner     case cv_error_code::no_records:
336a7efef4SAlexandre Ganea       return "There are no records.";
345acb4ac6SZachary Turner     case cv_error_code::operation_unsupported:
355acb4ac6SZachary Turner       return "The requested operation is not supported.";
365e3e4bb2SZachary Turner     case cv_error_code::unknown_member_record:
375e3e4bb2SZachary Turner       return "The member record is of an unknown type.";
38d5d37dcfSZachary Turner     }
39d5d37dcfSZachary Turner     llvm_unreachable("Unrecognized cv_error_code");
40d5d37dcfSZachary Turner   }
41d5d37dcfSZachary Turner };
42711950c1SBenjamin Kramer } // namespace
43d5d37dcfSZachary Turner 
CVErrorCategory()4471c43ceaSAlexandre Ganea const std::error_category &llvm::codeview::CVErrorCategory() {
45*ede60037SNicolai Hähnle   static CodeViewErrorCategory CodeViewErrCategory;
46*ede60037SNicolai Hähnle   return CodeViewErrCategory;
4771c43ceaSAlexandre Ganea }
48d5d37dcfSZachary Turner 
496a7efef4SAlexandre Ganea char CodeViewError::ID;
50