aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Object/Error.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Object/Error.h')
-rw-r--r--include/llvm/Object/Error.h47
1 files changed, 43 insertions, 4 deletions
diff --git a/include/llvm/Object/Error.h b/include/llvm/Object/Error.h
index 0f79a6ed0dd8..cd55e5dc26d7 100644
--- a/include/llvm/Object/Error.h
+++ b/include/llvm/Object/Error.h
@@ -14,11 +14,15 @@
#ifndef LLVM_OBJECT_ERROR_H
#define LLVM_OBJECT_ERROR_H
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Error.h"
#include <system_error>
namespace llvm {
namespace object {
+class Binary;
+
const std::error_category &object_category();
enum class object_error {
@@ -30,16 +34,51 @@ enum class object_error {
string_table_non_null_end,
invalid_section_index,
bitcode_section_not_found,
- elf_invalid_dynamic_table_size,
- macho_small_load_command,
- macho_load_segment_too_many_sections,
- macho_load_segment_too_small,
};
inline std::error_code make_error_code(object_error e) {
return std::error_code(static_cast<int>(e), object_category());
}
+/// Base class for all errors indicating malformed binary files.
+///
+/// Having a subclass for all malformed binary files allows archive-walking
+/// code to skip malformed files without having to understand every possible
+/// way that a binary file might be malformed.
+///
+/// Currently inherits from ECError for easy interoperability with
+/// std::error_code, but this will be removed in the future.
+class BinaryError : public ErrorInfo<BinaryError, ECError> {
+public:
+ static char ID;
+ BinaryError() {
+ // Default to parse_failed, can be overridden with setErrorCode.
+ setErrorCode(make_error_code(object_error::parse_failed));
+ }
+};
+
+/// Generic binary error.
+///
+/// For errors that don't require their own specific sub-error (most errors)
+/// this class can be used to describe the error via a string message.
+class GenericBinaryError : public ErrorInfo<GenericBinaryError, BinaryError> {
+public:
+ static char ID;
+ GenericBinaryError(Twine Msg);
+ GenericBinaryError(Twine Msg, object_error ECOverride);
+ const std::string &getMessage() const { return Msg; }
+ void log(raw_ostream &OS) const override;
+private:
+ std::string Msg;
+};
+
+/// isNotObjectErrorInvalidFileType() is used when looping through the children
+/// of an archive after calling getAsBinary() on the child and it returns an
+/// llvm::Error. In the cases we want to loop through the children and ignore the
+/// non-objects in the archive this is used to test the error to see if an
+/// error() function needs to called on the llvm::Error.
+Error isNotObjectErrorInvalidFileType(llvm::Error Err);
+
} // end namespace object.
} // end namespace llvm.