[PATCH] D18707: Make DIASession work if msdia*.dll isn't registered.

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 1 12:44:04 PDT 2016


thakis created this revision.
thakis added a reviewer: rnk.
thakis added a subscriber: llvm-commits.

This fixes various symbolization test failures for me when I build with a hermetic VS2015 without having run the 2015 installer.

http://reviews.llvm.org/D18707

Files:
  lib/DebugInfo/PDB/DIA/DIASession.cpp

Index: lib/DebugInfo/PDB/DIA/DIASession.cpp
===================================================================
--- lib/DebugInfo/PDB/DIA/DIASession.cpp
+++ lib/DebugInfo/PDB/DIA/DIASession.cpp
@@ -18,9 +18,36 @@
 #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.
+  // We can try loading the DLL corresponding to the #included DIA SDK, but
+  // the DIA headers don't provide a version. Lets try to figure out which DIA
+  // version we're compiling against by comparing CLSIDs.
+  class DECLSPEC_UUID("3BFCEA48-620F-4B6B-81F7-B9AF75454C7D") DiaSource120;
+  class DECLSPEC_UUID("E6756135-1E65-4D17-8576-610761398C3C") DiaSource140;
+  const wchar_t *msdia_dll = nullptr;
+  if (CLSID_DiaSource == _uuidof(DiaSource120)) // VS2013
+    msdia_dll = L"msdia120.dll";
+  else if (CLSID_DiaSource == _uuidof(DiaSource140)) // VS2015
+    msdia_dll = L"msdia140.dll";
+
+  return msdia_dll &&
+         SUCCEEDED(NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource,
+                                 reinterpret_cast<LPVOID *>(&DiaDataSource)));
+}
+
+}
 
 DIASession::DIASession(CComPtr<IDiaSession> DiaSession) : Session(DiaSession) {}
 
@@ -30,17 +57,15 @@
   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;
   if (!llvm::convertUTF8ToUTF16String(Path, 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;
@@ -71,17 +96,15 @@
   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;
   if (!llvm::convertUTF8ToUTF16String(Path, 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18707.52412.patch
Type: text/x-patch
Size: 3187 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160401/57c25548/attachment.bin>


More information about the llvm-commits mailing list