IEnumerable<PdbSourceFile^>^ PdbSession::SourceFiles::get() { IDiaEnumTables* diaEnumTables = nullptr; if (FAILED(diaSession->getEnumTables(&diaEnumTables))) return nullptr; if (diaEnumTables == nullptr) return nullptr; ULONG celt = 0; IDiaTable* diaTable = nullptr; while (SUCCEEDED(diaEnumTables->Next(1, &diaTable, &celt)) && celt == 1) { IDiaEnumSourceFiles* diaEnumSourceFiles; if (SUCCEEDED(diaTable->QueryInterface(_uuidof(IDiaEnumSourceFiles), (void**)&diaEnumSourceFiles))) return diaEnumSourceFiles ? gcnew PdbSourceFileCollection(diaEnumSourceFiles) : nullptr; } return nullptr; }
static void DumpSections(IDiaSession *session) { HRESULT hr; IDiaEnumTables * enumTables = NULL; IDiaTable * secTable = NULL; hr = session->getEnumTables(&enumTables); if (S_OK != hr) return; AddReportSepLine(); g_report.Append("Sections:\n"); VARIANT vIndex; vIndex.vt = VT_BSTR; vIndex.bstrVal = SysAllocString(L"Sections"); hr = enumTables->Item(vIndex, &secTable); if (S_OK != hr) goto Exit; LONG count; secTable->get_Count(&count); IDiaSectionContrib *item; ULONG numFetched; for (;;) { hr = secTable->Next(1,(IUnknown **)&item, &numFetched); if (FAILED(hr) || (numFetched != 1)) break; DumpSection(item); item->Release(); } Exit: UnkReleaseSafe(secTable); SysFreeStringSafe(vIndex.bstrVal); UnkReleaseSafe(enumTables); }
static IDiaEnumSegments* GetEnumSegments(IDiaSession *pSession) { IDiaEnumSegments* pUnknown = NULL; IDiaEnumTables* pEnumTables = NULL; IDiaTable* pTable = NULL; ULONG celt = 0; if ( pSession->getEnumTables(&pEnumTables) != S_OK ) return nullptr; while (pEnumTables->Next(1, &pTable, &celt) == S_OK && celt == 1) { // There is only one table that matches the given iid HRESULT hr = pTable->QueryInterface(__uuidof(IDiaEnumSegments), (void**)&pUnknown); pTable->Release(); if (hr == S_OK) break; } pEnumTables->Release(); return pUnknown; }
I* GetEnumTable(IDiaSession *pSession) { I* pUnknown = NULL; REFIID iid = __uuidof(I); IDiaEnumTables* pEnumTables = NULL; IDiaTable* pTable = NULL; ULONG celt = 0; if (pSession->getEnumTables(&pEnumTables) != S_OK) { // wprintf(L"ERROR - GetTable() getEnumTables\n"); return NULL; } while (pEnumTables->Next(1, &pTable, &celt) == S_OK && celt == 1) { // There is only one table that matches the given iid HRESULT hr = pTable->QueryInterface(iid, (void**)&pUnknown); pTable->Release(); if (hr == S_OK) break; } pEnumTables->Release(); return pUnknown; }
void PDBFileReader::ReadEverything(DebugInfo &to) { ULONG celt; Contribs = 0; nContribs = 0; DanglingLengthStart = 0; // read section table IDiaEnumTables *enumTables; if(Session->getEnumTables(&enumTables) == S_OK) { VARIANT vIndex; vIndex.vt = VT_BSTR; vIndex.bstrVal = SysAllocString(L"Sections"); IDiaTable *secTable; if(enumTables->Item(vIndex,&secTable) == S_OK) { LONG count; secTable->get_Count(&count); Contribs = new SectionContrib[count]; nContribs = 0; IDiaSectionContrib *item; while(SUCCEEDED(secTable->Next(1,(IUnknown **)&item,&celt)) && celt == 1) { SectionContrib &contrib = Contribs[nContribs++]; item->get_addressOffset(&contrib.Offset); item->get_addressSection(&contrib.Section); item->get_length(&contrib.Length); item->get_compilandId(&contrib.Compiland); item->get_execute(&contrib.CodeFlag); item->Release(); } secTable->Release(); } SysFreeString(vIndex.bstrVal); enumTables->Release(); } // enumerate symbols by (virtual) address IDiaEnumSymbolsByAddr *enumByAddr; if(SUCCEEDED(Session->getSymbolsByAddr(&enumByAddr))) { IDiaSymbol *symbol; // get first symbol to get first RVA (argh) if(SUCCEEDED(enumByAddr->symbolByAddr(1,0,&symbol))) { DWORD rva; if(symbol->get_relativeVirtualAddress(&rva) == S_OK) { symbol->Release(); // now, enumerate by rva. if(SUCCEEDED(enumByAddr->symbolByRVA(rva,&symbol))) { do { ProcessSymbol(symbol,to); symbol->Release(); if(FAILED(enumByAddr->Next(1,&symbol,&celt))) break; } while(celt == 1); } } else symbol->Release(); } enumByAddr->Release(); } // clean up delete[] Contribs; }
void PDBFileReader::ReadEverything(DebugInfo &to) { ULONG celt; Contribs = 0; nContribs = 0; // read section table IDiaEnumTables *enumTables; if(Session->getEnumTables(&enumTables) == S_OK) { VARIANT vIndex; vIndex.vt = VT_BSTR; vIndex.bstrVal = SysAllocString(L"Sections"); IDiaTable *secTable; if(enumTables->Item(vIndex,&secTable) == S_OK) { LONG count; secTable->get_Count(&count); Contribs = new SectionContrib[count]; nContribs = 0; IDiaSectionContrib *item; while(SUCCEEDED(secTable->Next(1,(IUnknown **)&item,&celt)) && celt == 1) { SectionContrib &contrib = Contribs[nContribs++]; item->get_addressOffset(&contrib.Offset); item->get_addressSection(&contrib.Section); item->get_length(&contrib.Length); item->get_compilandId(&contrib.Compiland); BOOL code=FALSE,initData=FALSE,uninitData=FALSE; item->get_code(&code); item->get_initializedData(&initData); item->get_uninitializedData(&uninitData); if(code && !initData && !uninitData) contrib.Type = DIC_CODE; else if(!code && initData && !uninitData) contrib.Type = DIC_DATA; else if(!code && !initData && uninitData) contrib.Type = DIC_BSS; else contrib.Type = DIC_UNKNOWN; BSTR objFileName = 0; IDiaSymbol *compiland = 0; item->get_compiland(&compiland); if(compiland) { compiland->get_name(&objFileName); compiland->Release(); } sChar *objFileStr = BStrToString(objFileName,"<noobjfile>"); contrib.ObjFile = to.GetFileByName(objFileStr); delete[] objFileStr; if(objFileName) SysFreeString(objFileName); item->Release(); } secTable->Release(); } SysFreeString(vIndex.bstrVal); enumTables->Release(); } // enumerate symbols by (virtual) address IDiaEnumSymbolsByAddr *enumByAddr; if(SUCCEEDED(Session->getSymbolsByAddr(&enumByAddr))) { IDiaSymbol *symbol; // get first symbol to get first RVA (argh) if(SUCCEEDED(enumByAddr->symbolByAddr(1,0,&symbol))) { DWORD rva; if(symbol->get_relativeVirtualAddress(&rva) == S_OK) { symbol->Release(); // now, enumerate by rva. if(SUCCEEDED(enumByAddr->symbolByRVA(rva,&symbol))) { do { ProcessSymbol(symbol,to); symbol->Release(); if(FAILED(enumByAddr->Next(1,&symbol,&celt))) break; } while(celt == 1); } } else symbol->Release(); } enumByAddr->Release(); } // clean up delete[] Contribs; }