From 383803230bba0c0dea3d93d9eb4f97d6fa8f3718 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Wed, 19 Oct 2016 16:42:20 +0000 Subject: [PATCH] [pdb] Improve error messages when DIA is not found. llvm-svn: 284610 --- llvm/include/llvm/DebugInfo/PDB/DIA/DIAError.h | 9 ++++--- llvm/include/llvm/DebugInfo/PDB/GenericError.h | 7 +++--- llvm/lib/DebugInfo/PDB/DIA/DIAError.cpp | 9 ++++--- llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp | 33 ++++++++++++++++---------- llvm/lib/DebugInfo/PDB/GenericError.cpp | 7 +++--- 5 files changed, 35 insertions(+), 30 deletions(-) diff --git a/llvm/include/llvm/DebugInfo/PDB/DIA/DIAError.h b/llvm/include/llvm/DebugInfo/PDB/DIA/DIAError.h index f198d07..35a39a0 100644 --- a/llvm/include/llvm/DebugInfo/PDB/DIA/DIAError.h +++ b/llvm/include/llvm/DebugInfo/PDB/DIA/DIAError.h @@ -10,10 +10,9 @@ #ifndef LLVM_DEBUGINFO_PDB_DIA_DIAERROR_H #define LLVM_DEBUGINFO_PDB_DIA_DIAERROR_H +#include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" -#include - namespace llvm { namespace pdb { enum class dia_error_code { @@ -30,11 +29,11 @@ class DIAError : public ErrorInfo { public: static char ID; DIAError(dia_error_code C); - DIAError(const std::string &Context); - DIAError(dia_error_code C, const std::string &Context); + DIAError(StringRef Context); + DIAError(dia_error_code C, StringRef Context); void log(raw_ostream &OS) const override; - const std::string &getErrorMessage() const; + StringRef getErrorMessage() const; std::error_code convertToErrorCode() const override; private: diff --git a/llvm/include/llvm/DebugInfo/PDB/GenericError.h b/llvm/include/llvm/DebugInfo/PDB/GenericError.h index 959c261..466cb45 100644 --- a/llvm/include/llvm/DebugInfo/PDB/GenericError.h +++ b/llvm/include/llvm/DebugInfo/PDB/GenericError.h @@ -10,6 +10,7 @@ #ifndef LLVM_DEBUGINFO_PDB_ERROR_H #define LLVM_DEBUGINFO_PDB_ERROR_H +#include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" namespace llvm { @@ -26,11 +27,11 @@ class GenericError : public ErrorInfo { public: static char ID; GenericError(generic_error_code C); - GenericError(const std::string &Context); - GenericError(generic_error_code C, const std::string &Context); + GenericError(StringRef Context); + GenericError(generic_error_code C, StringRef Context); void log(raw_ostream &OS) const override; - const std::string &getErrorMessage() const; + StringRef getErrorMessage() const; std::error_code convertToErrorCode() const override; private: diff --git a/llvm/lib/DebugInfo/PDB/DIA/DIAError.cpp b/llvm/lib/DebugInfo/PDB/DIA/DIAError.cpp index 1d72a92..81125d2 100644 --- a/llvm/lib/DebugInfo/PDB/DIA/DIAError.cpp +++ b/llvm/lib/DebugInfo/PDB/DIA/DIAError.cpp @@ -38,21 +38,20 @@ char DIAError::ID = 0; DIAError::DIAError(dia_error_code C) : DIAError(C, "") {} -DIAError::DIAError(const std::string &Context) +DIAError::DIAError(StringRef Context) : DIAError(dia_error_code::unspecified, Context) {} -DIAError::DIAError(dia_error_code C, const std::string &Context) : Code(C) { +DIAError::DIAError(dia_error_code C, StringRef Context) : Code(C) { ErrMsg = "DIA Error: "; std::error_code EC = convertToErrorCode(); - if (Code != dia_error_code::unspecified) - ErrMsg += EC.message() + " "; + ErrMsg += EC.message() + " "; if (!Context.empty()) ErrMsg += Context; } void DIAError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; } -const std::string &DIAError::getErrorMessage() const { return ErrMsg; } +StringRef DIAError::getErrorMessage() const { return ErrMsg; } std::error_code DIAError::convertToErrorCode() const { return std::error_code(static_cast(Code), *Category); diff --git a/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp b/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp index 861b7bb..6ecf335 100644 --- a/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp +++ b/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp @@ -20,25 +20,32 @@ #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace llvm::pdb; -static Error ErrorFromHResult(HRESULT Result) { +static Error ErrorFromHResult(HRESULT Result, StringRef Context) { switch (Result) { case E_PDB_NOT_FOUND: - return make_error(generic_error_code::invalid_path); + return make_error(generic_error_code::invalid_path, Context); case E_PDB_FORMAT: - return make_error(dia_error_code::invalid_file_format); + return make_error(dia_error_code::invalid_file_format, Context); case E_INVALIDARG: - return make_error(dia_error_code::invalid_parameter); + return make_error(dia_error_code::invalid_parameter, Context); case E_UNEXPECTED: - return make_error(dia_error_code::already_loaded); + return make_error(dia_error_code::already_loaded, Context); case E_PDB_INVALID_SIG: case E_PDB_INVALID_AGE: - return make_error(dia_error_code::debug_info_mismatch); - default: - return make_error(dia_error_code::unspecified); + return make_error(dia_error_code::debug_info_mismatch, Context); + default: { + std::string S; + raw_string_ostream OS(S); + OS << "HRESULT: " << format_hex(static_cast(Result), 10, true) + << ": " << Context; + return make_error(dia_error_code::unspecified, OS.str()); + } } } @@ -66,7 +73,7 @@ static Error LoadDIA(CComPtr &DiaDataSource) { HRESULT HR; if (FAILED(HR = NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource, reinterpret_cast(&DiaDataSource)))) - return ErrorFromHResult(HR); + return ErrorFromHResult(HR, "Calling NoRegCoCreate"); return Error::success(); #endif } @@ -89,10 +96,10 @@ Error DIASession::createFromPdb(StringRef Path, const wchar_t *Path16Str = reinterpret_cast(Path16.data()); HRESULT HR; if (FAILED(HR = DiaDataSource->loadDataFromPdb(Path16Str))) - return ErrorFromHResult(HR); + return ErrorFromHResult(HR, "Calling loadDataFromPdb"); if (FAILED(HR = DiaDataSource->openSession(&DiaSession))) - return ErrorFromHResult(HR); + return ErrorFromHResult(HR, "Calling openSession"); Session.reset(new DIASession(DiaSession)); return Error::success(); @@ -114,10 +121,10 @@ Error DIASession::createFromExe(StringRef Path, const wchar_t *Path16Str = reinterpret_cast(Path16.data()); HRESULT HR; if (FAILED(HR = DiaDataSource->loadDataForExe(Path16Str, nullptr, nullptr))) - return ErrorFromHResult(HR); + return ErrorFromHResult(HR, "Calling loadDataForExe"); if (FAILED(HR = DiaDataSource->openSession(&DiaSession))) - return ErrorFromHResult(HR); + return ErrorFromHResult(HR, "Calling openSession"); Session.reset(new DIASession(DiaSession)); return Error::success(); diff --git a/llvm/lib/DebugInfo/PDB/GenericError.cpp b/llvm/lib/DebugInfo/PDB/GenericError.cpp index 34e1799..4321013 100644 --- a/llvm/lib/DebugInfo/PDB/GenericError.cpp +++ b/llvm/lib/DebugInfo/PDB/GenericError.cpp @@ -45,11 +45,10 @@ char GenericError::ID = 0; GenericError::GenericError(generic_error_code C) : GenericError(C, "") {} -GenericError::GenericError(const std::string &Context) +GenericError::GenericError(StringRef Context) : GenericError(generic_error_code::unspecified, Context) {} -GenericError::GenericError(generic_error_code C, const std::string &Context) - : Code(C) { +GenericError::GenericError(generic_error_code C, StringRef Context) : Code(C) { ErrMsg = "PDB Error: "; std::error_code EC = convertToErrorCode(); if (Code != generic_error_code::unspecified) @@ -60,7 +59,7 @@ GenericError::GenericError(generic_error_code C, const std::string &Context) void GenericError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; } -const std::string &GenericError::getErrorMessage() const { return ErrMsg; } +StringRef GenericError::getErrorMessage() const { return ErrMsg; } std::error_code GenericError::convertToErrorCode() const { return std::error_code(static_cast(Code), *Category); -- 2.7.4