Skip to content

Commit

Permalink
[llvm-pdbdump] Print a better error message when PDB loading fails.
Browse files Browse the repository at this point in the history
Differential Revision: http://reviews.llvm.org/D19234

llvm-svn: 266772
  • Loading branch information
Zachary Turner committed Apr 19, 2016
1 parent e0e87af commit 23ee87b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
3 changes: 2 additions & 1 deletion llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ enum class PDB_MemberAccess { Private = 1, Protected = 2, Public = 3 };

enum class PDB_ErrorCode {
Success,
NoPdbImpl,
NoDiaSupport,
CouldNotCreateImpl,
InvalidPath,
InvalidFileFormat,
InvalidParameter,
Expand Down
29 changes: 17 additions & 12 deletions llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ using namespace llvm;

namespace {

bool LoadDIA(CComPtr<IDiaDataSource>& DiaDataSource) {
PDB_ErrorCode LoadDIA(CComPtr<IDiaDataSource> &DiaDataSource) {
if (SUCCEEDED(CoCreateInstance(CLSID_DiaSource, nullptr, CLSCTX_INPROC_SERVER,
IID_IDiaDataSource,
reinterpret_cast<LPVOID *>(&DiaDataSource))))
return true;
return PDB_ErrorCode::Success;

// 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
return PDB_ErrorCode::NoDiaSupport;
#endif

const wchar_t *msdia_dll = nullptr;
#if _MSC_VER == 1900
msdia_dll = L"msdia140.dll"; // VS2015
Expand All @@ -43,10 +44,12 @@ bool LoadDIA(CComPtr<IDiaDataSource>& DiaDataSource) {
#else
#error "Unknown Visual Studio version."
#endif
return msdia_dll &&
SUCCEEDED(NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource,
reinterpret_cast<LPVOID *>(&DiaDataSource)));
#endif

if (SUCCEEDED(NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource,
reinterpret_cast<LPVOID *>(&DiaDataSource))))
return PDB_ErrorCode::Success;
else
return PDB_ErrorCode::CouldNotCreateImpl;
}

}
Expand All @@ -59,8 +62,9 @@ PDB_ErrorCode DIASession::createFromPdb(StringRef Path,
CComPtr<IDiaSession> DiaSession;

// We assume that CoInitializeEx has already been called by the executable.
if (!LoadDIA(DiaDataSource))
return PDB_ErrorCode::NoPdbImpl;
PDB_ErrorCode result = LoadDIA(DiaDataSource);
if (result != PDB_ErrorCode::Success)
return result;

llvm::SmallVector<UTF16, 128> Path16;
if (!llvm::convertUTF8ToUTF16String(Path, Path16))
Expand Down Expand Up @@ -98,8 +102,9 @@ PDB_ErrorCode DIASession::createFromExe(StringRef Path,
CComPtr<IDiaSession> DiaSession;

// We assume that CoInitializeEx has already been called by the executable.
if (!LoadDIA(DiaDataSource))
return PDB_ErrorCode::NoPdbImpl;
PDB_ErrorCode result = LoadDIA(DiaDataSource);
if (result != PDB_ErrorCode::Success)
return result;

llvm::SmallVector<UTF16, 128> Path16;
if (!llvm::convertUTF8ToUTF16String(Path, Path16))
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/DebugInfo/PDB/PDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ PDB_ErrorCode llvm::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
#if HAVE_DIA_SDK
return DIASession::createFromPdb(Path, Session);
#endif
return PDB_ErrorCode::NoPdbImpl;
return PDB_ErrorCode::NoDiaSupport;
}

PDB_ErrorCode llvm::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
Expand All @@ -35,5 +35,5 @@ PDB_ErrorCode llvm::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
#if HAVE_DIA_SDK
return DIASession::createFromExe(Path, Session);
#endif
return PDB_ErrorCode::NoPdbImpl;
return PDB_ErrorCode::NoDiaSupport;
}
10 changes: 8 additions & 2 deletions llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,14 @@ static void dumpInput(StringRef Path) {
switch (Error) {
case PDB_ErrorCode::Success:
break;
case PDB_ErrorCode::NoPdbImpl:
outs() << "Reading PDBs is not supported on this platform.\n";
case PDB_ErrorCode::NoDiaSupport:
outs() << "LLVM was not compiled with support for DIA. This usually means "
"that either LLVM was not compiled with MSVC, or your MSVC "
"installation is corrupt.\n";
return;
case PDB_ErrorCode::CouldNotCreateImpl:
outs() << "Failed to connect to DIA at runtime. Verify that Visual Studio "
"is properly installed, or that msdiaXX.dll is in your PATH.\n";
return;
case PDB_ErrorCode::InvalidPath:
outs() << "Unable to load PDB at '" << Path
Expand Down

0 comments on commit 23ee87b

Please sign in to comment.