LCOV - code coverage report
Current view: top level - lib/DebugInfo/PDB/Native - RawError.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 15 33 45.5 %
Date: 2017-09-14 15:23:50 Functions: 4 10 40.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include "llvm/DebugInfo/PDB/Native/RawError.h"
       2             : #include "llvm/Support/ErrorHandling.h"
       3             : #include "llvm/Support/ManagedStatic.h"
       4             : 
       5             : using namespace llvm;
       6             : using namespace llvm::pdb;
       7             : 
       8             : namespace {
       9             : // FIXME: This class is only here to support the transition to llvm::Error. It
      10             : // will be removed once this transition is complete. Clients should prefer to
      11             : // deal with the Error value directly, rather than converting to error_code.
      12           1 : class RawErrorCategory : public std::error_category {
      13             : public:
      14           0 :   const char *name() const noexcept override { return "llvm.pdb.raw"; }
      15             : 
      16           1 :   std::string message(int Condition) const override {
      17           1 :     switch (static_cast<raw_error_code>(Condition)) {
      18             :     case raw_error_code::unspecified:
      19           0 :       return "An unknown error has occurred.";
      20             :     case raw_error_code::feature_unsupported:
      21           0 :       return "The feature is unsupported by the implementation.";
      22             :     case raw_error_code::invalid_format:
      23           0 :       return "The record is in an unexpected format.";
      24             :     case raw_error_code::corrupt_file:
      25           2 :       return "The PDB file is corrupt.";
      26             :     case raw_error_code::insufficient_buffer:
      27             :       return "The buffer is not large enough to read the requested number of "
      28           0 :              "bytes.";
      29             :     case raw_error_code::no_stream:
      30           0 :       return "The specified stream could not be loaded.";
      31             :     case raw_error_code::index_out_of_bounds:
      32           0 :       return "The specified item does not exist in the array.";
      33             :     case raw_error_code::invalid_block_address:
      34           0 :       return "The specified block address is not valid.";
      35             :     case raw_error_code::duplicate_entry:
      36           0 :       return "The entry already exists.";
      37             :     case raw_error_code::no_entry:
      38           0 :       return "The entry does not exist.";
      39             :     case raw_error_code::not_writable:
      40           0 :       return "The PDB does not support writing.";
      41             :     case raw_error_code::stream_too_long:
      42           0 :       return "The stream was longer than expected.";
      43             :     case raw_error_code::invalid_tpi_hash:
      44           0 :       return "The Type record has an invalid hash value.";
      45             :     }
      46           0 :     llvm_unreachable("Unrecognized raw_error_code");
      47             :   }
      48             : };
      49             : } // end anonymous namespace
      50             : 
      51             : static ManagedStatic<RawErrorCategory> Category;
      52             : 
      53             : char RawError::ID = 0;
      54             : 
      55           0 : RawError::RawError(raw_error_code C) : RawError(C, "") {}
      56             : 
      57           0 : RawError::RawError(const std::string &Context)
      58           0 :     : RawError(raw_error_code::unspecified, Context) {}
      59             : 
      60           3 : RawError::RawError(raw_error_code C, const std::string &Context) : Code(C) {
      61           2 :   ErrMsg = "Native PDB Error: ";
      62           1 :   std::error_code EC = convertToErrorCode();
      63           1 :   if (Code != raw_error_code::unspecified)
      64           4 :     ErrMsg += EC.message() + "  ";
      65           1 :   if (!Context.empty())
      66           1 :     ErrMsg += Context;
      67           1 : }
      68             : 
      69           2 : void RawError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
      70             : 
      71           0 : const std::string &RawError::getErrorMessage() const { return ErrMsg; }
      72             : 
      73           1 : std::error_code RawError::convertToErrorCode() const {
      74           1 :   return std::error_code(static_cast<int>(Code), *Category);
      75             : }

Generated by: LCOV version 1.13