summaryrefslogtreecommitdiff
path: root/lib/DebugInfo/PDB/DIA
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-05-06 20:51:57 +0000
committerZachary Turner <zturner@google.com>2016-05-06 20:51:57 +0000
commitfdb6da30151e3333e9ced7f2b3c6f7bbcf09da38 (patch)
tree0d5158840072e0bf1995a046a546192269cc3be9 /lib/DebugInfo/PDB/DIA
parente8e14421904d72853de582f171361cf25c1bfe5c (diff)
Port DebugInfoPDB over to using llvm::Error.
Differential Revision: http://reviews.llvm.org/D19940 Reviewed By: rnk git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268791 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/DebugInfo/PDB/DIA')
-rw-r--r--lib/DebugInfo/PDB/DIA/DIAError.cpp56
-rw-r--r--lib/DebugInfo/PDB/DIA/DIASession.cpp125
2 files changed, 112 insertions, 69 deletions
diff --git a/lib/DebugInfo/PDB/DIA/DIAError.cpp b/lib/DebugInfo/PDB/DIA/DIAError.cpp
new file mode 100644
index 00000000000..647446be577
--- /dev/null
+++ b/lib/DebugInfo/PDB/DIA/DIAError.cpp
@@ -0,0 +1,56 @@
+#include "llvm/DebugInfo/PDB/DIA/DIAError.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/ManagedStatic.h"
+
+using namespace llvm;
+using namespace llvm::pdb;
+
+class DIAErrorCategory : public std::error_category {
+public:
+ const char *name() const LLVM_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 "
+ "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.";
+ case dia_error_code::invalid_parameter:
+ return "The parameter is incorrect.";
+ case dia_error_code::already_loaded:
+ return "Unable to load the PDB or EXE, because it is already loaded.";
+ case dia_error_code::debug_info_mismatch:
+ return "The PDB file and the EXE file do not match.";
+ case dia_error_code::unspecified:
+ return "An unknown error has occurred.";
+ }
+ llvm_unreachable("Unrecognized DIAErrorCode");
+ }
+};
+
+static ManagedStatic<DIAErrorCategory> Category;
+
+char DIAError::ID = 0;
+
+DIAError::DIAError(dia_error_code C) : DIAError(C, "") {}
+
+DIAError::DIAError(const std::string &Context)
+ : DIAError(dia_error_code::unspecified, Context) {}
+
+DIAError::DIAError(dia_error_code C, const std::string &Context) : Code(C) {
+ ErrMsg = "DIA Error: ";
+ std::error_code EC = convertToErrorCode();
+ if (Code != dia_error_code::unspecified)
+ 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; }
+
+std::error_code DIAError::convertToErrorCode() const {
+ return std::error_code(static_cast<int>(Code), *Category);
+}
diff --git a/lib/DebugInfo/PDB/DIA/DIASession.cpp b/lib/DebugInfo/PDB/DIA/DIASession.cpp
index 83aebfede0b..fa224af8cb8 100644
--- a/lib/DebugInfo/PDB/DIA/DIASession.cpp
+++ b/lib/DebugInfo/PDB/DIA/DIASession.cpp
@@ -6,35 +6,55 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-
+#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/PDB/DIA/DIAEnumDebugStreams.h"
#include "llvm/DebugInfo/PDB/DIA/DIAEnumLineNumbers.h"
#include "llvm/DebugInfo/PDB/DIA/DIAEnumSourceFiles.h"
+#include "llvm/DebugInfo/PDB/DIA/DIAError.h"
#include "llvm/DebugInfo/PDB/DIA/DIARawSymbol.h"
-#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
#include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h"
+#include "llvm/DebugInfo/PDB/DIA/DIASupport.h"
+#include "llvm/DebugInfo/PDB/GenericError.h"
+#include "llvm/DebugInfo/PDB/PDB.h"
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
#include "llvm/Support/ConvertUTF.h"
-#include <diacreate.h>
-
using namespace llvm;
using namespace llvm::pdb;
namespace {
-PDB_ErrorCode LoadDIA(CComPtr<IDiaDataSource> &DiaDataSource) {
+Error ErrorFromHResult(HRESULT Result) {
+ switch (Result) {
+ case E_PDB_NOT_FOUND:
+ return make_error<GenericError>(generic_error_code::invalid_path);
+ case E_PDB_FORMAT:
+ return make_error<DIAError>(dia_error_code::invalid_file_format);
+ case E_INVALIDARG:
+ return make_error<DIAError>(dia_error_code::invalid_parameter);
+ case E_UNEXPECTED:
+ return make_error<DIAError>(dia_error_code::already_loaded);
+ 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);
+ }
+}
+
+Error LoadDIA(CComPtr<IDiaDataSource> &DiaDataSource) {
if (SUCCEEDED(CoCreateInstance(CLSID_DiaSource, nullptr, CLSCTX_INPROC_SERVER,
IID_IDiaDataSource,
reinterpret_cast<LPVOID *>(&DiaDataSource))))
- return PDB_ErrorCode::Success;
+ return Error::success();
- // If the CoCreateInstance call above failed, msdia*.dll is not registered.
- // Try loading the DLL corresponding to the #included DIA SDK.
+// 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 PDB_ErrorCode::NoDiaSupport;
+ return llvm::make_error<GenericError>(
+ "DIA is only supported when using MSVC.");
#endif
const wchar_t *msdia_dll = nullptr;
@@ -46,98 +66,65 @@ PDB_ErrorCode LoadDIA(CComPtr<IDiaDataSource> &DiaDataSource) {
#error "Unknown Visual Studio version."
#endif
- if (SUCCEEDED(NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource,
- reinterpret_cast<LPVOID *>(&DiaDataSource))))
- return PDB_ErrorCode::Success;
- else
- return PDB_ErrorCode::CouldNotCreateImpl;
+ HRESULT HR;
+ if (FAILED(HR = NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource,
+ reinterpret_cast<LPVOID *>(&DiaDataSource))))
+ return ErrorFromHResult(HR);
+ return Error::success();
}
}
DIASession::DIASession(CComPtr<IDiaSession> DiaSession) : Session(DiaSession) {}
-PDB_ErrorCode DIASession::createFromPdb(StringRef Path,
- std::unique_ptr<IPDBSession> &Session) {
+Error DIASession::createFromPdb(StringRef Path,
+ std::unique_ptr<IPDBSession> &Session) {
CComPtr<IDiaDataSource> DiaDataSource;
CComPtr<IDiaSession> DiaSession;
// We assume that CoInitializeEx has already been called by the executable.
- PDB_ErrorCode result = LoadDIA(DiaDataSource);
- if (result != PDB_ErrorCode::Success)
- return result;
+ if (auto E = LoadDIA(DiaDataSource))
+ return E;
llvm::SmallVector<UTF16, 128> Path16;
if (!llvm::convertUTF8ToUTF16String(Path, Path16))
- return PDB_ErrorCode::InvalidPath;
+ return make_error<GenericError>(generic_error_code::invalid_path);
const wchar_t *Path16Str = reinterpret_cast<const wchar_t*>(Path16.data());
- HRESULT Result;
- if (FAILED(Result = DiaDataSource->loadDataFromPdb(Path16Str))) {
- if (Result == E_PDB_NOT_FOUND)
- return PDB_ErrorCode::InvalidPath;
- else if (Result == E_PDB_FORMAT)
- return PDB_ErrorCode::InvalidFileFormat;
- else if (Result == E_INVALIDARG)
- return PDB_ErrorCode::InvalidParameter;
- else if (Result == E_UNEXPECTED)
- return PDB_ErrorCode::AlreadyLoaded;
- else
- return PDB_ErrorCode::UnknownError;
- }
+ HRESULT HR;
+ if (FAILED(HR = DiaDataSource->loadDataFromPdb(Path16Str)))
+ return ErrorFromHResult(HR);
- if (FAILED(Result = DiaDataSource->openSession(&DiaSession))) {
- if (Result == E_OUTOFMEMORY)
- return PDB_ErrorCode::NoMemory;
- else
- return PDB_ErrorCode::UnknownError;
- }
+ if (FAILED(HR = DiaDataSource->openSession(&DiaSession)))
+ return ErrorFromHResult(HR);
Session.reset(new DIASession(DiaSession));
- return PDB_ErrorCode::Success;
+ return Error::success();
}
-PDB_ErrorCode DIASession::createFromExe(StringRef Path,
- std::unique_ptr<IPDBSession> &Session) {
+Error DIASession::createFromExe(StringRef Path,
+ std::unique_ptr<IPDBSession> &Session) {
CComPtr<IDiaDataSource> DiaDataSource;
CComPtr<IDiaSession> DiaSession;
// We assume that CoInitializeEx has already been called by the executable.
- PDB_ErrorCode result = LoadDIA(DiaDataSource);
- if (result != PDB_ErrorCode::Success)
- return result;
+ if (auto EC = LoadDIA(DiaDataSource))
+ return EC;
llvm::SmallVector<UTF16, 128> Path16;
if (!llvm::convertUTF8ToUTF16String(Path, Path16))
- return PDB_ErrorCode::InvalidPath;
+ return make_error<GenericError>(generic_error_code::invalid_path, Path);
const wchar_t *Path16Str = reinterpret_cast<const wchar_t *>(Path16.data());
- HRESULT Result;
- if (FAILED(Result =
- DiaDataSource->loadDataForExe(Path16Str, nullptr, nullptr))) {
- if (Result == E_PDB_NOT_FOUND)
- return PDB_ErrorCode::InvalidPath;
- else if (Result == E_PDB_FORMAT)
- return PDB_ErrorCode::InvalidFileFormat;
- else if (Result == E_PDB_INVALID_SIG || Result == E_PDB_INVALID_AGE)
- return PDB_ErrorCode::DebugInfoMismatch;
- else if (Result == E_INVALIDARG)
- return PDB_ErrorCode::InvalidParameter;
- else if (Result == E_UNEXPECTED)
- return PDB_ErrorCode::AlreadyLoaded;
- else
- return PDB_ErrorCode::UnknownError;
- }
+ HRESULT HR;
+ if (FAILED(HR = DiaDataSource->loadDataForExe(Path16Str, nullptr, nullptr)))
+ return ErrorFromHResult(HR);
- if (FAILED(Result = DiaDataSource->openSession(&DiaSession))) {
- if (Result == E_OUTOFMEMORY)
- return PDB_ErrorCode::NoMemory;
- else
- return PDB_ErrorCode::UnknownError;
- }
+ if (FAILED(HR = DiaDataSource->openSession(&DiaSession)))
+ return ErrorFromHResult(HR);
Session.reset(new DIASession(DiaSession));
- return PDB_ErrorCode::Success;
+ return Error::success();
}
uint64_t DIASession::getLoadAddress() const {