LLVM  13.0.0git
Error.h
Go to the documentation of this file.
1 //===- Error.h - system_error extensions for Object -------------*- 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 // This declares a new error_category for the Object library.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_OBJECT_ERROR_H
14 #define LLVM_OBJECT_ERROR_H
15 
16 #include "llvm/Support/Error.h"
17 #include <system_error>
18 
19 namespace llvm {
20 
21 class Twine;
22 
23 namespace object {
24 
25 class Binary;
26 
28 
29 enum class object_error {
30  // Error code 0 is absent. Use std::error_code() instead.
31  arch_not_found = 1,
39 };
40 
41 inline std::error_code make_error_code(object_error e) {
42  return std::error_code(static_cast<int>(e), object_category());
43 }
44 
45 /// Base class for all errors indicating malformed binary files.
46 ///
47 /// Having a subclass for all malformed binary files allows archive-walking
48 /// code to skip malformed files without having to understand every possible
49 /// way that a binary file might be malformed.
50 ///
51 /// Currently inherits from ECError for easy interoperability with
52 /// std::error_code, but this will be removed in the future.
53 class BinaryError : public ErrorInfo<BinaryError, ECError> {
54  void anchor() override;
55 public:
56  static char ID;
58  // Default to parse_failed, can be overridden with setErrorCode.
60  }
61 };
62 
63 /// Generic binary error.
64 ///
65 /// For errors that don't require their own specific sub-error (most errors)
66 /// this class can be used to describe the error via a string message.
67 class GenericBinaryError : public ErrorInfo<GenericBinaryError, BinaryError> {
68 public:
69  static char ID;
70  GenericBinaryError(const Twine &Msg);
71  GenericBinaryError(const Twine &Msg, object_error ECOverride);
72  const std::string &getMessage() const { return Msg; }
73  void log(raw_ostream &OS) const override;
74 private:
75  std::string Msg;
76 };
77 
78 /// isNotObjectErrorInvalidFileType() is used when looping through the children
79 /// of an archive after calling getAsBinary() on the child and it returns an
80 /// llvm::Error. In the cases we want to loop through the children and ignore the
81 /// non-objects in the archive this is used to test the error to see if an
82 /// error() function needs to called on the llvm::Error.
84 
85 } // end namespace object.
86 
87 } // end namespace llvm.
88 
89 namespace std {
90 template <>
91 struct is_error_code_enum<llvm::object::object_error> : std::true_type {};
92 }
93 
94 #endif
llvm::object::object_error::unexpected_eof
@ unexpected_eof
llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:23
llvm::object::object_error::bitcode_section_not_found
@ bitcode_section_not_found
llvm::object::GenericBinaryError::ID
static char ID
Definition: Error.h:69
Error.h
llvm::object::object_error::invalid_symbol_index
@ invalid_symbol_index
llvm::object::make_error_code
std::error_code make_error_code(object_error e)
Definition: Error.h:41
llvm::msgpack::Type::Binary
@ Binary
llvm::object::GenericBinaryError::log
void log(raw_ostream &OS) const override
Definition: Error.cpp:72
llvm::object::object_error
object_error
Definition: Error.h:29
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::object::BinaryError::ID
static char ID
Definition: Error.h:56
llvm::object::object_error::parse_failed
@ parse_failed
llvm::object::object_error::invalid_file_type
@ invalid_file_type
llvm::object::GenericBinaryError
Generic binary error.
Definition: Error.h:67
llvm::ECError::setErrorCode
void setErrorCode(std::error_code EC)
Definition: Error.h:1110
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::object::object_error::string_table_non_null_end
@ string_table_non_null_end
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:58
llvm::object::BinaryError::BinaryError
BinaryError()
Definition: Error.h:57
llvm::ErrorInfo
Base class for user error types.
Definition: Error.h:350
llvm::object::object_category
const std::error_category & object_category()
Definition: Error.cpp:78
llvm::object::object_error::invalid_section_index
@ invalid_section_index
llvm::object::BinaryError
Base class for all errors indicating malformed binary files.
Definition: Error.h:53
llvm::object::isNotObjectErrorInvalidFileType
Error isNotObjectErrorInvalidFileType(llvm::Error Err)
isNotObjectErrorInvalidFileType() is used when looping through the children of an archive after calli...
Definition: Error.cpp:82
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
std
Definition: BitVector.h:941
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::object::GenericBinaryError::getMessage
const std::string & getMessage() const
Definition: Error.h:72
llvm::object::object_error::arch_not_found
@ arch_not_found
error_category
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:76
llvm::object::GenericBinaryError::GenericBinaryError
GenericBinaryError(const Twine &Msg)
Definition: Error.cpp:64