/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/DebugInfo/CodeView/CodeViewError.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- 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 | | |
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 | 0 | const char *name() const noexcept override { return "llvm.codeview"; } |
24 | | |
25 | 1 | std::string message(int Condition) const override { |
26 | 1 | switch (static_cast<cv_error_code>(Condition)) { |
27 | 0 | case cv_error_code::unspecified: |
28 | 0 | return "An unknown error has occurred."; |
29 | 0 | case cv_error_code::insufficient_buffer: |
30 | 0 | return "The buffer is not large enough to read the requested number of " |
31 | 0 | "bytes."; |
32 | 1 | case cv_error_code::corrupt_record: |
33 | 1 | return "The CodeView record is corrupted."; |
34 | 0 | case cv_error_code::no_records: |
35 | 0 | return "There are no records"; |
36 | 0 | case cv_error_code::operation_unsupported: |
37 | 0 | return "The requested operation is not supported."; |
38 | 0 | case cv_error_code::unknown_member_record: |
39 | 0 | return "The member record is of an unknown type."; |
40 | 0 | } |
41 | 0 | llvm_unreachable0 ("Unrecognized cv_error_code"); |
42 | 0 | } |
43 | | }; |
44 | | } // end anonymous namespace |
45 | | |
46 | | static ManagedStatic<CodeViewErrorCategory> Category; |
47 | | |
48 | | char CodeViewError::ID = 0; |
49 | | |
50 | 0 | CodeViewError::CodeViewError(cv_error_code C) : CodeViewError(C, "") {} Unexecuted instantiation: llvm::codeview::CodeViewError::CodeViewError(llvm::codeview::cv_error_code) Unexecuted instantiation: llvm::codeview::CodeViewError::CodeViewError(llvm::codeview::cv_error_code) |
51 | | |
52 | | CodeViewError::CodeViewError(const std::string &Context) |
53 | 96 | : CodeViewError(cv_error_code::unspecified, Context) {} Unexecuted instantiation: llvm::codeview::CodeViewError::CodeViewError(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) llvm::codeview::CodeViewError::CodeViewError(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 53 | 96 | : CodeViewError(cv_error_code::unspecified, Context) {} |
|
54 | | |
55 | | CodeViewError::CodeViewError(cv_error_code C, const std::string &Context) |
56 | 97 | : Code(C) { |
57 | 97 | ErrMsg = "CodeView Error: "; |
58 | 97 | std::error_code EC = convertToErrorCode(); |
59 | 97 | if (Code != cv_error_code::unspecified) |
60 | 1 | ErrMsg += EC.message() + " "; |
61 | 97 | if (!Context.empty()) |
62 | 97 | ErrMsg += Context; |
63 | 97 | } |
64 | | |
65 | 1 | void CodeViewError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; } |
66 | | |
67 | 0 | const std::string &CodeViewError::getErrorMessage() const { return ErrMsg; } |
68 | | |
69 | 97 | std::error_code CodeViewError::convertToErrorCode() const { |
70 | 97 | return std::error_code(static_cast<int>(Code), *Category); |
71 | 97 | } |