LCOV - code coverage report
Current view: top level - lib/Object - Error.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 16 25 64.0 %
Date: 2018-10-20 13:21:21 Functions: 5 7 71.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- Error.cpp - system_error extensions for Object -----------*- 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             : // This defines a new error_category for the Object library.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/Object/Error.h"
      15             : #include "llvm/Support/ErrorHandling.h"
      16             : #include "llvm/Support/ManagedStatic.h"
      17             : 
      18             : using namespace llvm;
      19             : using namespace object;
      20             : 
      21             : namespace {
      22             : // FIXME: This class is only here to support the transition to llvm::Error. It
      23             : // will be removed once this transition is complete. Clients should prefer to
      24             : // deal with the Error value directly, rather than converting to error_code.
      25        1326 : class _object_error_category : public std::error_category {
      26             : public:
      27             :   const char* name() const noexcept override;
      28             :   std::string message(int ev) const override;
      29             : };
      30             : }
      31             : 
      32           0 : const char *_object_error_category::name() const noexcept {
      33           0 :   return "llvm.object";
      34             : }
      35             : 
      36          37 : std::string _object_error_category::message(int EV) const {
      37             :   object_error E = static_cast<object_error>(EV);
      38          37 :   switch (E) {
      39             :   case object_error::arch_not_found:
      40           2 :     return "No object file for requested architecture";
      41             :   case object_error::invalid_file_type:
      42          10 :     return "The file was not recognized as a valid object file";
      43             :   case object_error::parse_failed:
      44          25 :     return "Invalid data was encountered while parsing the file";
      45             :   case object_error::unexpected_eof:
      46           0 :     return "The end of the file was unexpectedly encountered";
      47             :   case object_error::string_table_non_null_end:
      48           0 :     return "String table must end with a null terminator";
      49             :   case object_error::invalid_section_index:
      50           0 :     return "Invalid section index";
      51             :   case object_error::bitcode_section_not_found:
      52           0 :     return "Bitcode section not found in object file";
      53             :   case object_error::invalid_symbol_index:
      54           0 :     return "Invalid symbol index";
      55             :   }
      56           0 :   llvm_unreachable("An enumerator of object_error does not have a message "
      57             :                    "defined.");
      58             : }
      59             : 
      60             : char BinaryError::ID = 0;
      61             : char GenericBinaryError::ID = 0;
      62             : 
      63           0 : GenericBinaryError::GenericBinaryError(Twine Msg) : Msg(Msg.str()) {}
      64             : 
      65         762 : GenericBinaryError::GenericBinaryError(Twine Msg, object_error ECOverride)
      66         762 :     : Msg(Msg.str()) {
      67             :   setErrorCode(make_error_code(ECOverride));
      68         762 : }
      69             : 
      70         240 : void GenericBinaryError::log(raw_ostream &OS) const {
      71             :   OS << Msg;
      72         240 : }
      73             : 
      74             : static ManagedStatic<_object_error_category> error_category;
      75             : 
      76       12065 : const std::error_category &object::object_category() {
      77       12065 :   return *error_category;
      78             : }
      79             : 
      80         198 : llvm::Error llvm::object::isNotObjectErrorInvalidFileType(llvm::Error Err) {
      81         198 :   if (auto Err2 =
      82             :           handleErrors(std::move(Err), [](std::unique_ptr<ECError> M) -> Error {
      83             :             // Try to handle 'M'. If successful, return a success value from
      84             :             // the handler.
      85             :             if (M->convertToErrorCode() == object_error::invalid_file_type)
      86             :               return Error::success();
      87             : 
      88             :             // We failed to handle 'M' - return it from the handler.
      89             :             // This value will be passed back from catchErrors and
      90             :             // wind up in Err2, where it will be returned from this function.
      91             :             return Error(std::move(M));
      92         396 :           }))
      93             :     return Err2;
      94             :   return Err;
      95             : }

Generated by: LCOV version 1.13