summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-10-19 16:42:20 +0000
committerZachary Turner <zturner@google.com>2016-10-19 16:42:20 +0000
commit383803230bba0c0dea3d93d9eb4f97d6fa8f3718 (patch)
treecee967f69d3e7042182f4deb692427b32a830f6f
parent7bb63ac029bfe00e24ed4628d46252fde200c0e4 (diff)
downloadbcm5719-llvm-383803230bba0c0dea3d93d9eb4f97d6fa8f3718.tar.gz
bcm5719-llvm-383803230bba0c0dea3d93d9eb4f97d6fa8f3718.zip
[pdb] Improve error messages when DIA is not found.
llvm-svn: 284610
-rw-r--r--llvm/include/llvm/DebugInfo/PDB/DIA/DIAError.h9
-rw-r--r--llvm/include/llvm/DebugInfo/PDB/GenericError.h7
-rw-r--r--llvm/lib/DebugInfo/PDB/DIA/DIAError.cpp9
-rw-r--r--llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp33
-rw-r--r--llvm/lib/DebugInfo/PDB/GenericError.cpp7
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 f198d07e99d..35a39a0df5c 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 <string>
-
namespace llvm {
namespace pdb {
enum class dia_error_code {
@@ -30,11 +29,11 @@ class DIAError : public ErrorInfo<DIAError> {
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 959c2616104..466cb455651 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<GenericError> {
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 1d72a92b514..81125d267f4 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<int>(Code), *Category);
diff --git a/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp b/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp
index 861b7bb4c26..6ecf335812b 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<GenericError>(generic_error_code::invalid_path);
+ return make_error<GenericError>(generic_error_code::invalid_path, Context);
case E_PDB_FORMAT:
- return make_error<DIAError>(dia_error_code::invalid_file_format);
+ return make_error<DIAError>(dia_error_code::invalid_file_format, Context);
case E_INVALIDARG:
- return make_error<DIAError>(dia_error_code::invalid_parameter);
+ return make_error<DIAError>(dia_error_code::invalid_parameter, Context);
case E_UNEXPECTED:
- return make_error<DIAError>(dia_error_code::already_loaded);
+ return make_error<DIAError>(dia_error_code::already_loaded, Context);
case E_PDB_INVALID_SIG:
case E_PDB_INVALID_AGE:
- return make_error<DIAError>(dia_error_code::debug_info_mismatch);
- default:
- return make_error<DIAError>(dia_error_code::unspecified);
+ return make_error<DIAError>(dia_error_code::debug_info_mismatch, Context);
+ default: {
+ std::string S;
+ raw_string_ostream OS(S);
+ OS << "HRESULT: " << format_hex(static_cast<DWORD>(Result), 10, true)
+ << ": " << Context;
+ return make_error<DIAError>(dia_error_code::unspecified, OS.str());
+ }
}
}
@@ -66,7 +73,7 @@ static Error LoadDIA(CComPtr<IDiaDataSource> &DiaDataSource) {
HRESULT HR;
if (FAILED(HR = NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource,
reinterpret_cast<LPVOID *>(&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<const wchar_t*>(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<const wchar_t *>(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 34e17999802..43210139bb6 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<int>(Code), *Category);
OpenPOWER on IntegriCloud