[llvm] r341228 - [DebugInfo] Common behavior for error types
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 31 10:41:58 PDT 2018
Author: aganea
Date: Fri Aug 31 10:41:58 2018
New Revision: 341228
URL: http://llvm.org/viewvc/llvm-project?rev=341228&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewError.h
llvm/trunk/include/llvm/DebugInfo/MSF/MSFError.h
llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIAError.h
llvm/trunk/include/llvm/DebugInfo/PDB/GenericError.h
llvm/trunk/include/llvm/DebugInfo/PDB/Native/RawError.h
llvm/trunk/lib/DebugInfo/CodeView/CodeViewError.cpp
llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
llvm/trunk/lib/DebugInfo/MSF/MSFError.cpp
llvm/trunk/lib/DebugInfo/PDB/DIA/DIAError.cpp
llvm/trunk/lib/DebugInfo/PDB/DIA/DIASession.cpp
llvm/trunk/lib/DebugInfo/PDB/GenericError.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/NativeSession.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/RawError.cpp
llvm/trunk/lib/DebugInfo/PDB/PDB.cpp
llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp
llvm/trunk/lib/Support/BinaryStreamError.cpp
llvm/trunk/test/DebugInfo/PDB/pdb-invalid-type.test
llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test
llvm/trunk/test/tools/llvm-readobj/codeview-merging-cycle.test
llvm/trunk/test/tools/llvm-symbolizer/pdb/missing_pdb.test
llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp
llvm/trunk/tools/obj2yaml/Error.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewError.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewError.h?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewError.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewError.h Fri Aug 31 10:41:58 2018
@@ -24,23 +24,32 @@ enum class cv_error_code {
no_records,
unknown_member_record,
};
+} // namespace codeview
+} // namespace llvm
+
+namespace std {
+template <>
+struct is_error_code_enum<llvm::codeview::cv_error_code> : std::true_type {};
+} // namespace std
+
+namespace llvm {
+namespace codeview {
+const std::error_category &CVErrorCategory();
+
+inline std::error_code make_error_code(cv_error_code E) {
+ return std::error_code(static_cast<int>(E), CVErrorCategory());
+}
/// Base class for errors originating when parsing raw PDB files
-class CodeViewError : public ErrorInfo<CodeViewError> {
+class CodeViewError : public ErrorInfo<CodeViewError, StringError> {
public:
+ using ErrorInfo<CodeViewError,
+ StringError>::ErrorInfo; // inherit constructors
+ CodeViewError(const Twine &S) : ErrorInfo(S, cv_error_code::unspecified) {}
static char ID;
- CodeViewError(cv_error_code C);
- CodeViewError(const std::string &Context);
- CodeViewError(cv_error_code C, const std::string &Context);
-
- void log(raw_ostream &OS) const override;
- const std::string &getErrorMessage() const;
- std::error_code convertToErrorCode() const override;
-
-private:
- std::string ErrMsg;
- cv_error_code Code;
};
-}
-}
+
+} // namespace codeview
+} // namespace llvm
+
#endif
Modified: llvm/trunk/include/llvm/DebugInfo/MSF/MSFError.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/MSF/MSFError.h?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/MSF/MSFError.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/MSF/MSFError.h Fri Aug 31 10:41:58 2018
@@ -24,22 +24,28 @@ enum class msf_error_code {
invalid_format,
block_in_use
};
+} // namespace msf
+} // namespace llvm
+
+namespace std {
+template <>
+struct is_error_code_enum<llvm::msf::msf_error_code> : std::true_type {};
+} // namespace std
+
+namespace llvm {
+namespace msf {
+const std::error_category &MSFErrCategory();
+
+inline std::error_code make_error_code(msf_error_code E) {
+ return std::error_code(static_cast<int>(E), MSFErrCategory());
+}
/// Base class for errors originating when parsing raw PDB files
-class MSFError : public ErrorInfo<MSFError> {
+class MSFError : public ErrorInfo<MSFError, StringError> {
public:
+ using ErrorInfo<MSFError, StringError>::ErrorInfo; // inherit constructors
+ MSFError(const Twine &S) : ErrorInfo(S, msf_error_code::unspecified) {}
static char ID;
- MSFError(msf_error_code C);
- MSFError(const std::string &Context);
- MSFError(msf_error_code C, const std::string &Context);
-
- void log(raw_ostream &OS) const override;
- const std::string &getErrorMessage() const;
- std::error_code convertToErrorCode() const override;
-
-private:
- std::string ErrMsg;
- msf_error_code Code;
};
} // namespace msf
} // namespace llvm
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIAError.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIAError.h?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIAError.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIAError.h Fri Aug 31 10:41:58 2018
@@ -23,23 +23,29 @@ enum class dia_error_code {
already_loaded,
debug_info_mismatch,
};
+} // namespace pdb
+} // namespace llvm
+
+namespace std {
+template <>
+struct is_error_code_enum<llvm::pdb::dia_error_code> : std::true_type {};
+} // namespace std
+
+namespace llvm {
+namespace pdb {
+const std::error_category &DIAErrCategory();
+
+inline std::error_code make_error_code(dia_error_code E) {
+ return std::error_code(static_cast<int>(E), DIAErrCategory());
+}
/// Base class for errors originating in DIA SDK, e.g. COM calls
-class DIAError : public ErrorInfo<DIAError> {
+class DIAError : public ErrorInfo<DIAError, StringError> {
public:
+ using ErrorInfo<DIAError, StringError>::ErrorInfo;
+ DIAError(const Twine &S) : ErrorInfo(S, dia_error_code::unspecified) {}
static char ID;
- DIAError(dia_error_code C);
- DIAError(StringRef Context);
- DIAError(dia_error_code C, StringRef Context);
-
- void log(raw_ostream &OS) const override;
- StringRef getErrorMessage() const;
- std::error_code convertToErrorCode() const override;
-
-private:
- std::string ErrMsg;
- dia_error_code Code;
};
-}
-}
+} // namespace pdb
+} // namespace llvm
#endif
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/GenericError.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/GenericError.h?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/GenericError.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/GenericError.h Fri Aug 31 10:41:58 2018
@@ -16,29 +16,37 @@
namespace llvm {
namespace pdb {
-enum class generic_error_code {
- invalid_path = 1,
+enum class pdb_error_code {
+ invalid_utf8_path = 1,
dia_sdk_not_present,
+ dia_failed_loading,
+ signature_out_of_date,
type_server_not_found,
unspecified,
};
+} // namespace codeview
+} // namespace llvm
+
+namespace std {
+ template <>
+ struct is_error_code_enum<llvm::pdb::pdb_error_code> : std::true_type {};
+} // namespace std
+
+namespace llvm {
+namespace pdb {
+ const std::error_category &PDBErrCategory();
+
+ inline std::error_code make_error_code(pdb_error_code E) {
+ return std::error_code(static_cast<int>(E), PDBErrCategory());
+ }
/// Base class for errors originating when parsing raw PDB files
-class GenericError : public ErrorInfo<GenericError> {
+class PDBError : public ErrorInfo<PDBError, StringError> {
public:
+ using ErrorInfo<PDBError, StringError>::ErrorInfo; // inherit constructors
+ PDBError(const Twine &S) : ErrorInfo(S, pdb_error_code::unspecified) {}
static char ID;
- GenericError(generic_error_code C);
- GenericError(StringRef Context);
- GenericError(generic_error_code C, StringRef Context);
-
- void log(raw_ostream &OS) const override;
- StringRef getErrorMessage() const;
- std::error_code convertToErrorCode() const override;
-
-private:
- std::string ErrMsg;
- generic_error_code Code;
};
-}
-}
+} // namespace pdb
+} // namespace llvm
#endif
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Native/RawError.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Native/RawError.h?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Native/RawError.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/RawError.h Fri Aug 31 10:41:58 2018
@@ -31,23 +31,29 @@ enum class raw_error_code {
stream_too_long,
invalid_tpi_hash,
};
+} // namespace pdb
+} // namespace llvm
+
+namespace std {
+template <>
+struct is_error_code_enum<llvm::pdb::raw_error_code> : std::true_type {};
+} // namespace std
+
+namespace llvm {
+namespace pdb {
+const std::error_category &RawErrCategory();
+
+inline std::error_code make_error_code(raw_error_code E) {
+ return std::error_code(static_cast<int>(E), RawErrCategory());
+}
/// Base class for errors originating when parsing raw PDB files
-class RawError : public ErrorInfo<RawError> {
+class RawError : public ErrorInfo<RawError, StringError> {
public:
+ using ErrorInfo<RawError, StringError>::ErrorInfo; // inherit constructors
+ RawError(const Twine &S) : ErrorInfo(S, raw_error_code::unspecified) {}
static char ID;
- RawError(raw_error_code C);
- RawError(const std::string &Context);
- RawError(raw_error_code C, const std::string &Context);
-
- void log(raw_ostream &OS) const override;
- const std::string &getErrorMessage() const;
- std::error_code convertToErrorCode() const override;
-
-private:
- std::string ErrMsg;
- raw_error_code Code;
};
-}
-}
+} // namespace pdb
+} // namespace llvm
#endif
Modified: llvm/trunk/lib/DebugInfo/CodeView/CodeViewError.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/CodeViewError.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/CodeViewError.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/CodeViewError.cpp Fri Aug 31 10:41:58 2018
@@ -14,25 +14,23 @@
using namespace llvm;
using namespace llvm::codeview;
-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 CodeViewErrorCategory : public std::error_category {
public:
const char *name() const noexcept override { return "llvm.codeview"; }
-
std::string message(int Condition) const override {
switch (static_cast<cv_error_code>(Condition)) {
case cv_error_code::unspecified:
- return "An unknown error has occurred.";
+ return "An unknown CodeView error has occurred.";
case cv_error_code::insufficient_buffer:
return "The buffer is not large enough to read the requested number of "
"bytes.";
case cv_error_code::corrupt_record:
return "The CodeView record is corrupted.";
case cv_error_code::no_records:
- return "There are no records";
+ return "There are no records.";
case cv_error_code::operation_unsupported:
return "The requested operation is not supported.";
case cv_error_code::unknown_member_record:
@@ -41,31 +39,8 @@ public:
llvm_unreachable("Unrecognized cv_error_code");
}
};
-} // end anonymous namespace
-
-static ManagedStatic<CodeViewErrorCategory> Category;
-
-char CodeViewError::ID = 0;
-
-CodeViewError::CodeViewError(cv_error_code C) : CodeViewError(C, "") {}
-
-CodeViewError::CodeViewError(const std::string &Context)
- : CodeViewError(cv_error_code::unspecified, Context) {}
-
-CodeViewError::CodeViewError(cv_error_code C, const std::string &Context)
- : Code(C) {
- ErrMsg = "CodeView Error: ";
- std::error_code EC = convertToErrorCode();
- if (Code != cv_error_code::unspecified)
- ErrMsg += EC.message() + " ";
- if (!Context.empty())
- ErrMsg += Context;
-}
-
-void CodeViewError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
-const std::string &CodeViewError::getErrorMessage() const { return ErrMsg; }
+static llvm::ManagedStatic<CodeViewErrorCategory> CodeViewErrCategory;
+const std::error_category &llvm::codeview::CVErrorCategory() { return *CodeViewErrCategory; }
-std::error_code CodeViewError::convertToErrorCode() const {
- return std::error_code(static_cast<int>(Code), *Category);
-}
+char CodeViewError::ID;
Modified: llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp Fri Aug 31 10:41:58 2018
@@ -326,7 +326,7 @@ Error TypeStreamMerger::doit(const CVTyp
"second pass found more bad indices");
if (!LastError && NumBadIndices == BadIndicesRemaining) {
return llvm::make_error<CodeViewError>(
- cv_error_code::corrupt_record, "input type graph contains cycles");
+ cv_error_code::corrupt_record, "Input type graph contains cycles");
}
}
Modified: llvm/trunk/lib/DebugInfo/MSF/MSFError.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/MSF/MSFError.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/MSF/MSFError.cpp (original)
+++ llvm/trunk/lib/DebugInfo/MSF/MSFError.cpp Fri Aug 31 10:41:58 2018
@@ -14,14 +14,12 @@
using namespace llvm;
using namespace llvm::msf;
-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 MSFErrorCategory : public std::error_category {
public:
const char *name() const noexcept override { return "llvm.msf"; }
-
std::string message(int Condition) const override {
switch (static_cast<msf_error_code>(Condition)) {
case msf_error_code::unspecified:
@@ -41,30 +39,8 @@ public:
llvm_unreachable("Unrecognized msf_error_code");
}
};
-} // end anonymous namespace
-
-static ManagedStatic<MSFErrorCategory> Category;
-
-char MSFError::ID = 0;
-
-MSFError::MSFError(msf_error_code C) : MSFError(C, "") {}
-
-MSFError::MSFError(const std::string &Context)
- : MSFError(msf_error_code::unspecified, Context) {}
-
-MSFError::MSFError(msf_error_code C, const std::string &Context) : Code(C) {
- ErrMsg = "MSF Error: ";
- std::error_code EC = convertToErrorCode();
- if (Code != msf_error_code::unspecified)
- ErrMsg += EC.message() + " ";
- if (!Context.empty())
- ErrMsg += Context;
-}
-
-void MSFError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
-const std::string &MSFError::getErrorMessage() const { return ErrMsg; }
+static llvm::ManagedStatic<MSFErrorCategory> MSFCategory;
+const std::error_category &llvm::msf::MSFErrCategory() { return *MSFCategory; }
-std::error_code MSFError::convertToErrorCode() const {
- return std::error_code(static_cast<int>(Code), *Category);
-}
+char MSFError::ID;
Modified: llvm/trunk/lib/DebugInfo/PDB/DIA/DIAError.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/DIA/DIAError.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/DIA/DIAError.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/DIA/DIAError.cpp Fri Aug 31 10:41:58 2018
@@ -11,14 +11,13 @@ using namespace llvm::pdb;
class DIAErrorCategory : public std::error_category {
public:
const char *name() const noexcept override { return "llvm.pdb.dia"; }
-
std::string message(int Condition) const override {
switch (static_cast<dia_error_code>(Condition)) {
case dia_error_code::could_not_create_impl:
- return "Failed to connect to DIA at runtime. Verify that Visual Studio "
+ return "Failed to connect to DIA at runtime. Verify that Visual Studio "
"is properly installed, or that msdiaXX.dll is in your PATH.";
case dia_error_code::invalid_file_format:
- return "Unable to load PDB. The file has an unrecognized format.";
+ return "Unable to load PDB. The file has an unrecognized format.";
case dia_error_code::invalid_parameter:
return "The parameter is incorrect.";
case dia_error_code::already_loaded:
@@ -32,27 +31,7 @@ public:
}
};
-static ManagedStatic<DIAErrorCategory> Category;
-
-char DIAError::ID = 0;
-
-DIAError::DIAError(dia_error_code C) : DIAError(C, "") {}
-
-DIAError::DIAError(StringRef Context)
- : DIAError(dia_error_code::unspecified, Context) {}
-
-DIAError::DIAError(dia_error_code C, StringRef Context) : Code(C) {
- ErrMsg = "DIA Error: ";
- std::error_code EC = convertToErrorCode();
- ErrMsg += EC.message() + " ";
- if (!Context.empty())
- ErrMsg += Context;
-}
-
-void DIAError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
-
-StringRef DIAError::getErrorMessage() const { return ErrMsg; }
+static llvm::ManagedStatic<DIAErrorCategory> DIACategory;
+const std::error_category &llvm::pdb::DIAErrCategory() { return *DIACategory; }
-std::error_code DIAError::convertToErrorCode() const {
- return std::error_code(static_cast<int>(Code), *Category);
-}
+char DIAError::ID;
Modified: llvm/trunk/lib/DebugInfo/PDB/DIA/DIASession.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/DIA/DIASession.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/DIA/DIASession.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/DIA/DIASession.cpp Fri Aug 31 10:41:58 2018
@@ -42,7 +42,7 @@ static Error ErrorFromHResult(HRESULT Re
switch (Result) {
case E_PDB_NOT_FOUND:
- return make_error<GenericError>(generic_error_code::invalid_path, Context);
+ return errorCodeToError(std::error_code(ENOENT, std::generic_category()));
case E_PDB_FORMAT:
return make_error<DIAError>(dia_error_code::invalid_file_format, Context);
case E_INVALIDARG:
@@ -71,8 +71,7 @@ static Error LoadDIA(CComPtr<IDiaDataSou
// If the CoCreateInstance call above failed, msdia*.dll is not registered.
// Try loading the DLL corresponding to the #included DIA SDK.
#if !defined(_MSC_VER)
- return llvm::make_error<GenericError>(
- "DIA is only supported when using MSVC.");
+ return llvm::make_error<PDBError>(pdb_error_code::dia_failed_loading);
#else
const wchar_t *msdia_dll = nullptr;
#if _MSC_VER >= 1900 && _MSC_VER < 2000
@@ -104,7 +103,7 @@ Error DIASession::createFromPdb(StringRe
llvm::SmallVector<UTF16, 128> Path16;
if (!llvm::convertUTF8ToUTF16String(Path, Path16))
- return make_error<GenericError>(generic_error_code::invalid_path);
+ return make_error<PDBError>(pdb_error_code::invalid_utf8_path, Path);
const wchar_t *Path16Str = reinterpret_cast<const wchar_t *>(Path16.data());
HRESULT HR;
@@ -130,7 +129,7 @@ Error DIASession::createFromExe(StringRe
llvm::SmallVector<UTF16, 128> Path16;
if (!llvm::convertUTF8ToUTF16String(Path, Path16))
- return make_error<GenericError>(generic_error_code::invalid_path, Path);
+ return make_error<PDBError>(pdb_error_code::invalid_utf8_path, Path);
const wchar_t *Path16Str = reinterpret_cast<const wchar_t *>(Path16.data());
HRESULT HR;
Modified: llvm/trunk/lib/DebugInfo/PDB/GenericError.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/GenericError.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/GenericError.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/GenericError.cpp Fri Aug 31 10:41:58 2018
@@ -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;
-
-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; }
+static llvm::ManagedStatic<PDBErrorCategory> PDBCategory;
+const std::error_category &llvm::pdb::PDBErrCategory() { return *PDBCategory; }
-std::error_code GenericError::convertToErrorCode() const {
- return std::error_code(static_cast<int>(Code), *Category);
-}
+char PDBError::ID;
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/NativeSession.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/NativeSession.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/NativeSession.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/NativeSession.cpp Fri Aug 31 10:41:58 2018
@@ -11,7 +11,6 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
-#include "llvm/DebugInfo/PDB/GenericError.h"
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
#include "llvm/DebugInfo/PDB/Native/NativeBuiltinSymbol.h"
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp Fri Aug 31 10:41:58 2018
@@ -125,7 +125,7 @@ Error PDBFile::parseFileHeaders() {
if (auto EC = Reader.readObject(SB)) {
consumeError(std::move(EC));
return make_error<RawError>(raw_error_code::corrupt_file,
- "Does not contain superblock");
+ "MSF superblock is missing");
}
if (auto EC = msf::validateSuperBlock(*SB))
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp Fri Aug 31 10:41:58 2018
@@ -12,7 +12,6 @@
#include "llvm/ADT/BitVector.h"
#include "llvm/DebugInfo/MSF/MSFBuilder.h"
-#include "llvm/DebugInfo/PDB/GenericError.h"
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
#include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h"
#include "llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h"
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/RawError.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/RawError.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/RawError.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/RawError.cpp Fri Aug 31 10:41:58 2018
@@ -5,14 +5,12 @@
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 RawErrorCategory : public std::error_category {
public:
const char *name() const noexcept override { return "llvm.pdb.raw"; }
-
std::string message(int Condition) const override {
switch (static_cast<raw_error_code>(Condition)) {
case raw_error_code::unspecified:
@@ -46,30 +44,8 @@ public:
llvm_unreachable("Unrecognized raw_error_code");
}
};
-} // end anonymous namespace
-
-static ManagedStatic<RawErrorCategory> Category;
-
-char RawError::ID = 0;
-
-RawError::RawError(raw_error_code C) : RawError(C, "") {}
-
-RawError::RawError(const std::string &Context)
- : RawError(raw_error_code::unspecified, Context) {}
-
-RawError::RawError(raw_error_code C, const std::string &Context) : Code(C) {
- ErrMsg = "Native PDB Error: ";
- std::error_code EC = convertToErrorCode();
- if (Code != raw_error_code::unspecified)
- ErrMsg += EC.message() + " ";
- if (!Context.empty())
- ErrMsg += Context;
-}
-
-void RawError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
-const std::string &RawError::getErrorMessage() const { return ErrMsg; }
+static llvm::ManagedStatic<RawErrorCategory> RawCategory;
+const std::error_category &llvm::pdb::RawErrCategory() { return *RawCategory; }
-std::error_code RawError::convertToErrorCode() const {
- return std::error_code(static_cast<int>(Code), *Category);
-}
+char RawError::ID;
Modified: llvm/trunk/lib/DebugInfo/PDB/PDB.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/PDB.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/PDB.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/PDB.cpp Fri Aug 31 10:41:58 2018
@@ -29,7 +29,7 @@ Error llvm::pdb::loadDataForPDB(PDB_Read
MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
/*RequiresNullTerminator=*/false);
if (!ErrorOrBuffer)
- return make_error<GenericError>(generic_error_code::invalid_path, Path);
+ return errorCodeToError(ErrorOrBuffer.getError());
return NativeSession::createFromPdb(std::move(*ErrorOrBuffer), Session);
}
@@ -37,7 +37,7 @@ Error llvm::pdb::loadDataForPDB(PDB_Read
#if LLVM_ENABLE_DIA_SDK
return DIASession::createFromPdb(Path, Session);
#else
- return make_error<GenericError>("DIA is not installed on the system");
+ return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
#endif
}
@@ -50,6 +50,6 @@ Error llvm::pdb::loadDataForEXE(PDB_Read
#if LLVM_ENABLE_DIA_SDK
return DIASession::createFromExe(Path, Session);
#else
- return make_error<GenericError>("DIA is not installed on the system");
+ return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
#endif
}
Modified: llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp (original)
+++ llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp Fri Aug 31 10:41:58 2018
@@ -410,7 +410,8 @@ LLVMSymbolizer::getOrCreateModuleInfo(co
Objects.first->getFileName(), Session)) {
Modules.insert(
std::make_pair(ModuleName, std::unique_ptr<SymbolizableModule>()));
- return std::move(Err);
+ // Return along the PDB filename to provide more context
+ return createFileError(PDBFileName, std::move(Err));
}
Context.reset(new PDBContext(*CoffObject, std::move(Session)));
}
Modified: llvm/trunk/lib/Support/BinaryStreamError.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/BinaryStreamError.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/lib/Support/BinaryStreamError.cpp (original)
+++ llvm/trunk/lib/Support/BinaryStreamError.cpp Fri Aug 31 10:41:58 2018
@@ -47,7 +47,7 @@ BinaryStreamError::BinaryStreamError(str
}
}
-void BinaryStreamError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
+void BinaryStreamError::log(raw_ostream &OS) const { OS << ErrMsg; }
StringRef BinaryStreamError::getErrorMessage() const { return ErrMsg; }
Modified: llvm/trunk/test/DebugInfo/PDB/pdb-invalid-type.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/pdb-invalid-type.test?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/pdb-invalid-type.test (original)
+++ llvm/trunk/test/DebugInfo/PDB/pdb-invalid-type.test Fri Aug 31 10:41:58 2018
@@ -2,7 +2,7 @@
# RUN: llvm-pdbutil yaml2pdb -pdb=%t2.pdb %s
# RUN: not llvm-pdbutil merge -pdb=%t.pdb %t1.pdb %t2.pdb 2>&1 | FileCheck %s
-# CHECK: CodeView Error: The CodeView record is corrupted.
+# CHECK: The CodeView record is corrupted
---
TpiStream:
Modified: llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test (original)
+++ llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test Fri Aug 31 10:41:58 2018
@@ -1167,4 +1167,4 @@ BIG-NEXT: Mod 0045 | `Import:api-ms-wi
BIG-NEXT: Mod 0046 | `api-ms-win-crt-heap-l1-1-0.dll`:
BIG-NEXT: Mod 0047 | `* Linker *`:
-BAD-BLOCK-SIZE: Native PDB Error: The PDB file is corrupt. Does not contain superblock
+BAD-BLOCK-SIZE: The PDB file is corrupt. MSF superblock is missing
Modified: llvm/trunk/test/tools/llvm-readobj/codeview-merging-cycle.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/codeview-merging-cycle.test?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/codeview-merging-cycle.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/codeview-merging-cycle.test Fri Aug 31 10:41:58 2018
@@ -1,6 +1,6 @@
; RUN: not llvm-readobj -codeview-merged-types %S/Inputs/codeview-cycle.obj 2>&1 | FileCheck %s
-; CHECK: Error{{.*}} input type graph contains cycles
+; CHECK: Error{{.*}} Input type graph contains cycles
; To reproduce codeview-cycle.obj:
; $ cat codeview-cycle.asm
Modified: llvm/trunk/test/tools/llvm-symbolizer/pdb/missing_pdb.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/pdb/missing_pdb.test?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-symbolizer/pdb/missing_pdb.test (original)
+++ llvm/trunk/test/tools/llvm-symbolizer/pdb/missing_pdb.test Fri Aug 31 10:41:58 2018
@@ -8,7 +8,7 @@ ADDR: 0x401001
llvm-symbolizer should print one error and two unknown line info records.
-ERROR: LLVMSymbolizer: error reading file: PDB Error: Unable to load PDB. Make sure the file exists and is readable.
+ERROR: LLVMSymbolizer: error reading file: {{.*}}: {{N|n}}o such file or directory
ERROR-NOT: error reading file
CHECK: ??
Modified: llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp Fri Aug 31 10:41:58 2018
@@ -46,7 +46,6 @@
#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
#include "llvm/DebugInfo/CodeView/TypeStreamMerger.h"
#include "llvm/DebugInfo/MSF/MSFBuilder.h"
-#include "llvm/DebugInfo/PDB/GenericError.h"
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
#include "llvm/DebugInfo/PDB/IPDBInjectedSource.h"
#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
@@ -681,7 +680,7 @@ static void yamlToPdb(StringRef Path) {
/*RequiresNullTerminator=*/false);
if (ErrorOrBuffer.getError()) {
- ExitOnErr(make_error<GenericError>(generic_error_code::invalid_path, Path));
+ ExitOnErr(createFileError(Path, errorCodeToError(ErrorOrBuffer.getError())));
}
std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();
Modified: llvm/trunk/tools/obj2yaml/Error.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/Error.cpp?rev=341228&r1=341227&r2=341228&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/Error.cpp (original)
+++ llvm/trunk/tools/obj2yaml/Error.cpp Fri Aug 31 10:41:58 2018
@@ -53,7 +53,7 @@ const std::error_category &obj2yaml_cate
char Obj2YamlError::ID = 0;
-void Obj2YamlError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
+void Obj2YamlError::log(raw_ostream &OS) const { OS << ErrMsg; }
std::error_code Obj2YamlError::convertToErrorCode() const {
return std::error_code(static_cast<int>(Code), obj2yaml_category());
More information about the llvm-commits
mailing list