[DebugInfo] Common behavior for error types

Following D50807, and heading towards D50664, this intermediary change does the following:

1. Upgrade all custom Error types in llvm/trunk/lib/DebugInfo/ to use the new StringError behavior (D50807).
2. Implement std::is_error_code_enum and make_error_code() for DebugInfo error enumerations.
3. Rename GenericError -> PDBError (the file will be renamed in a subsequent commit)
4. Update custom error messages to follow the same formatting: (\w\s*)+\.
5. Keep generic "file not found" (ENOENT) errors as they are in PDB code. Previously, there used to be a custom enumeration for that purpose.
6. Remove a few extraneous LF in log() implementations. Printing LF is a responsability at a higher level, not at the error level.

Differential Revision: https://reviews.llvm.org/D51499

llvm-svn: 341228
diff --git a/llvm/lib/DebugInfo/PDB/GenericError.cpp b/llvm/lib/DebugInfo/PDB/GenericError.cpp
index 2a677b9..b6e668a 100644
--- a/llvm/lib/DebugInfo/PDB/GenericError.cpp
+++ b/llvm/lib/DebugInfo/PDB/GenericError.cpp
@@ -14,55 +14,34 @@
 using namespace llvm;
 using namespace llvm::pdb;
 
-namespace {
 // FIXME: This class is only here to support the transition to llvm::Error. It
 // will be removed once this transition is complete. Clients should prefer to
 // deal with the Error value directly, rather than converting to error_code.
-class GenericErrorCategory : public std::error_category {
+class PDBErrorCategory : public std::error_category {
 public:
   const char *name() const noexcept override { return "llvm.pdb"; }
-
   std::string message(int Condition) const override {
-    switch (static_cast<generic_error_code>(Condition)) {
-    case generic_error_code::unspecified:
+    switch (static_cast<pdb_error_code>(Condition)) {
+    case pdb_error_code::unspecified:
       return "An unknown error has occurred.";
-    case generic_error_code::type_server_not_found:
-      return "Type server PDB was not found.";
-    case generic_error_code::dia_sdk_not_present:
-      return "LLVM was not compiled with support for DIA.  This usually means "
+    case pdb_error_code::type_server_not_found:
+        return "Type server PDB was not found.";
+    case pdb_error_code::dia_sdk_not_present:
+      return "LLVM was not compiled with support for DIA. This usually means "
              "that you are not using MSVC, or your Visual Studio "
-             "installation "
-             "is corrupt.";
-    case generic_error_code::invalid_path:
-      return "Unable to load PDB.  Make sure the file exists and is readable.";
+             "installation is corrupt.";
+    case pdb_error_code::dia_failed_loading:
+      return "DIA is only supported when using MSVC.";
+    case pdb_error_code::invalid_utf8_path:
+      return "The PDB file path is an invalid UTF8 sequence.";
+    case pdb_error_code::signature_out_of_date:
+      return "The signature does not match; the file(s) might be out of date";
     }
     llvm_unreachable("Unrecognized generic_error_code");
   }
 };
-} // end anonymous namespace
 
-static ManagedStatic<GenericErrorCategory> Category;
+static llvm::ManagedStatic<PDBErrorCategory> PDBCategory;
+const std::error_category &llvm::pdb::PDBErrCategory() { return *PDBCategory; }
 
-char GenericError::ID = 0;
-
-GenericError::GenericError(generic_error_code C) : GenericError(C, "") {}
-
-GenericError::GenericError(StringRef Context)
-    : GenericError(generic_error_code::unspecified, Context) {}
-
-GenericError::GenericError(generic_error_code C, StringRef Context) : Code(C) {
-  ErrMsg = "PDB Error: ";
-  std::error_code EC = convertToErrorCode();
-  if (Code != generic_error_code::unspecified)
-    ErrMsg += EC.message() + "  ";
-  if (!Context.empty())
-    ErrMsg += Context;
-}
-
-void GenericError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
-
-StringRef GenericError::getErrorMessage() const { return ErrMsg; }
-
-std::error_code GenericError::convertToErrorCode() const {
-  return std::error_code(static_cast<int>(Code), *Category);
-}
+char PDBError::ID;