#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
#include "llvm/Support/ConvertUTF.h"
+#include <diacreate.h>
+
using namespace llvm;
-namespace {}
+namespace {
+
+bool LoadDIA(CComPtr<IDiaDataSource>& DiaDataSource) {
+ if (SUCCEEDED(CoCreateInstance(CLSID_DiaSource, nullptr, CLSCTX_INPROC_SERVER,
+ IID_IDiaDataSource,
+ reinterpret_cast<LPVOID *>(&DiaDataSource))))
+ return true;
+
+ // 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 false;
+#else
+ const wchar_t *msdia_dll = nullptr;
+#if _MSC_VER == 1900
+ msdia_dll = L"msdia140.dll"; // VS2015
+#elif _MSC_VER == 1800
+ msdia_dll = L"msdia120.dll"; // VS2013
+#else
+#error "Unknown Visual Studio version."
+#endif
+ return msdia_dll &&
+ SUCCEEDED(NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource,
+ reinterpret_cast<LPVOID *>(&DiaDataSource)));
+#endif
+}
+
+}
DIASession::DIASession(CComPtr<IDiaSession> DiaSession) : Session(DiaSession) {}
CComPtr<IDiaSession> DiaSession;
// We assume that CoInitializeEx has already been called by the executable.
- HRESULT Result = ::CoCreateInstance(
- CLSID_DiaSource, nullptr, CLSCTX_INPROC_SERVER, IID_IDiaDataSource,
- reinterpret_cast<LPVOID *>(&DiaDataSource));
- if (FAILED(Result))
+ if (!LoadDIA(DiaDataSource))
return PDB_ErrorCode::NoPdbImpl;
llvm::SmallVector<UTF16, 128> Path16;
return PDB_ErrorCode::InvalidPath;
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;
CComPtr<IDiaSession> DiaSession;
// We assume that CoInitializeEx has already been called by the executable.
- HRESULT Result = ::CoCreateInstance(
- CLSID_DiaSource, nullptr, CLSCTX_INPROC_SERVER, IID_IDiaDataSource,
- reinterpret_cast<LPVOID *>(&DiaDataSource));
- if (FAILED(Result))
+ if (!LoadDIA(DiaDataSource))
return PDB_ErrorCode::NoPdbImpl;
llvm::SmallVector<UTF16, 128> Path16;
return PDB_ErrorCode::InvalidPath;
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)