blob: 2a9753add311e6d43f859a4a2a784b1983d6e5b8 [file] [log] [blame]
Zachary Turnerd5d37dc2016-05-25 20:37:03 +00001//===- CodeViewError.cpp - Error extensions for CodeView --------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/DebugInfo/CodeView/CodeViewError.h"
11#include "llvm/Support/ErrorHandling.h"
12#include "llvm/Support/ManagedStatic.h"
13
14using namespace llvm;
15using namespace llvm::codeview;
16
Zachary Turnerd5d37dc2016-05-25 20:37:03 +000017// FIXME: This class is only here to support the transition to llvm::Error. It
18// will be removed once this transition is complete. Clients should prefer to
19// deal with the Error value directly, rather than converting to error_code.
20class CodeViewErrorCategory : public std::error_category {
21public:
Reid Kleckner990504e2016-10-19 23:52:38 +000022 const char *name() const noexcept override { return "llvm.codeview"; }
Zachary Turnerd5d37dc2016-05-25 20:37:03 +000023 std::string message(int Condition) const override {
24 switch (static_cast<cv_error_code>(Condition)) {
25 case cv_error_code::unspecified:
Alexandre Ganea6a7efef2018-08-31 17:41:58 +000026 return "An unknown CodeView error has occurred.";
Zachary Turnerd5d37dc2016-05-25 20:37:03 +000027 case cv_error_code::insufficient_buffer:
28 return "The buffer is not large enough to read the requested number of "
29 "bytes.";
30 case cv_error_code::corrupt_record:
31 return "The CodeView record is corrupted.";
Zachary Turner7b327d02017-02-16 23:35:45 +000032 case cv_error_code::no_records:
Alexandre Ganea6a7efef2018-08-31 17:41:58 +000033 return "There are no records.";
Zachary Turner5acb4ac2016-06-10 05:09:12 +000034 case cv_error_code::operation_unsupported:
35 return "The requested operation is not supported.";
Zachary Turner5e3e4bb2016-08-05 21:45:34 +000036 case cv_error_code::unknown_member_record:
37 return "The member record is of an unknown type.";
Zachary Turnerd5d37dc2016-05-25 20:37:03 +000038 }
39 llvm_unreachable("Unrecognized cv_error_code");
40 }
41};
Zachary Turnerd5d37dc2016-05-25 20:37:03 +000042
Alexandre Ganea6a7efef2018-08-31 17:41:58 +000043static llvm::ManagedStatic<CodeViewErrorCategory> CodeViewErrCategory;
Alexandre Ganea71c43ce2018-11-05 19:20:47 +000044const std::error_category &llvm::codeview::CVErrorCategory() {
45 return *CodeViewErrCategory;
46}
Zachary Turnerd5d37dc2016-05-25 20:37:03 +000047
Alexandre Ganea6a7efef2018-08-31 17:41:58 +000048char CodeViewError::ID;