sBool PDBFileReader::ReadDebugInfo(sChar *fileName,DebugInfo &to) { sBool readOk = sFALSE; if(FAILED(CoInitialize(0))) return sFALSE; IDiaDataSource *source = 0; CoCreateInstance(__uuidof(DiaSource),0,CLSCTX_INPROC_SERVER, __uuidof(IDiaDataSource),(void**) &source); if(source) { wchar_t wideFileName[260]; mbstowcs(wideFileName,fileName,260); if(SUCCEEDED(source->loadDataForExe(wideFileName,0,0))) { if(SUCCEEDED(source->openSession(&Session))) { ReadEverything(to); readOk = sTRUE; Session->Release(); } } source->Release(); } CoUninitialize(); return readOk; }
sBool PDBFileReader::ReadDebugInfo(sChar *fileName,DebugInfo &to) { static const struct DLLDesc { const char *Filename; IID UseCLSID; } DLLs[] = { "msdia71.dll", __uuidof(DiaSource71), "msdia80.dll", __uuidof(DiaSource80), "msdia90.dll", __uuidof(DiaSource90), // add more here as new versions appear (as long as they're backwards-compatible) 0 }; sBool readOk = false; if(FAILED(CoInitialize(0))) { fprintf(stderr, " failed to initialize COM\n"); return false; } IDiaDataSource *source = 0; HRESULT hr = E_FAIL; // Try creating things "the official way" for(sInt i=0;DLLs[i].Filename;i++) { hr = CoCreateInstance(DLLs[i].UseCLSID,0,CLSCTX_INPROC_SERVER, __uuidof(IDiaDataSource),(void**) &source); if(SUCCEEDED(hr)) break; } if(FAILED(hr)) { // None of the classes are registered, but most programmers will have the // DLLs on their system anyway and can copy it over; try loading it directly. for(sInt i=0;DLLs[i].Filename;i++) { HMODULE hDIADll = LoadLibrary(DLLs[i].Filename); if(hDIADll) { typedef HRESULT (__stdcall *PDllGetClassObject)(REFCLSID rclsid,REFIID riid,void** ppvObj); PDllGetClassObject DllGetClassObject = (PDllGetClassObject) GetProcAddress(hDIADll,"DllGetClassObject"); if(DllGetClassObject) { // first create a class factory IClassFactory *classFactory; hr = DllGetClassObject(DLLs[i].UseCLSID,IID_IClassFactory,(void**) &classFactory); if(SUCCEEDED(hr)) { hr = classFactory->CreateInstance(0,__uuidof(IDiaDataSource),(void**) &source); classFactory->Release(); } } if(SUCCEEDED(hr)) break; else FreeLibrary(hDIADll); } } } if(source) { wchar_t wideFileName[260]; mbstowcs(wideFileName,fileName,260); if(SUCCEEDED(source->loadDataForExe(wideFileName,0,0))) { if(SUCCEEDED(source->openSession(&Session))) { ReadEverything(to); readOk = true; Session->Release(); } else fprintf(stderr," failed to open DIA session\n"); } else fprintf(stderr," failed to load debug symbols (PDB not found)\n"); source->Release(); } else fprintf(stderr," couldn't find (or properly initialize) any DIA dll, copying msdia*.dll to app dir might help.\n"); CoUninitialize(); return readOk; }