LCOV - code coverage report
Current view: top level - lib/DebugInfo/PDB - GenericError.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 17 24 70.8 %
Date: 2017-09-14 15:23:50 Functions: 5 10 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- Error.cpp - system_error extensions for PDB --------------*- 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/PDB/GenericError.h"
      11             : #include "llvm/Support/ErrorHandling.h"
      12             : #include "llvm/Support/ManagedStatic.h"
      13             : 
      14             : using namespace llvm;
      15             : using namespace llvm::pdb;
      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           5 : class GenericErrorCategory : public std::error_category {
      22             : public:
      23           0 :   const char *name() const noexcept override { return "llvm.pdb"; }
      24             : 
      25           1 :   std::string message(int Condition) const override {
      26           1 :     switch (static_cast<generic_error_code>(Condition)) {
      27             :     case generic_error_code::unspecified:
      28           0 :       return "An unknown error has occurred.";
      29             :     case generic_error_code::type_server_not_found:
      30           0 :       return "Type server PDB was not found.";
      31             :     case generic_error_code::dia_sdk_not_present:
      32             :       return "LLVM was not compiled with support for DIA.  This usually means "
      33             :              "that you are are not using MSVC, or your Visual Studio "
      34             :              "installation "
      35           0 :              "is corrupt.";
      36             :     case generic_error_code::invalid_path:
      37           2 :       return "Unable to load PDB.  Make sure the file exists and is readable.";
      38             :     }
      39           0 :     llvm_unreachable("Unrecognized generic_error_code");
      40             :   }
      41             : };
      42             : } // end anonymous namespace
      43             : 
      44             : static ManagedStatic<GenericErrorCategory> Category;
      45             : 
      46             : char GenericError::ID = 0;
      47             : 
      48           2 : GenericError::GenericError(generic_error_code C) : GenericError(C, "") {}
      49             : 
      50          11 : GenericError::GenericError(StringRef Context)
      51          11 :     : GenericError(generic_error_code::unspecified, Context) {}
      52             : 
      53          36 : GenericError::GenericError(generic_error_code C, StringRef Context) : Code(C) {
      54          24 :   ErrMsg = "PDB Error: ";
      55          12 :   std::error_code EC = convertToErrorCode();
      56          12 :   if (Code != generic_error_code::unspecified)
      57           4 :     ErrMsg += EC.message() + "  ";
      58          12 :   if (!Context.empty())
      59          11 :     ErrMsg += Context;
      60          12 : }
      61             : 
      62           0 : void GenericError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
      63             : 
      64           0 : StringRef GenericError::getErrorMessage() const { return ErrMsg; }
      65             : 
      66          12 : std::error_code GenericError::convertToErrorCode() const {
      67          12 :   return std::error_code(static_cast<int>(Code), *Category);
      68             : }

Generated by: LCOV version 1.13