Today we will discuss how to use the DIA interfaces for reading the PDB when compared to our previous post here
MSDN says the following steps:
//initialize
MSDN says the following steps:
//initialize
CComPtr<IDiaDataSource> pSource;
hr = CoCreateInstance( CLSID_DiaSource,
NULL,
CLSCTX_INPROC_SERVER,
__uuidof( IDiaDataSource ),
(void **) &pSource);
if (FAILED(hr))
{
Fatal("Could not CoCreate CLSID_DiaSource. Register msdia80.dll." );
}
//load
wchar_t wszFilename[ _MAX_PATH ]; mbstowcs( wszFilename, szFilename, sizeof( wszFilename )/sizeof( wszFilename[0] ) ); if ( FAILED( pSource->loadDataFromPdb( wszFilename ) ) ) { if ( FAILED( pSource->loadDataForExe( wszFilename, NULL, NULL ) ) ) { Fatal( "loadDataFromPdb/Exe" ); } }
CComPtr<IDiaSession> psession; if ( FAILED( pSource->openSession( &psession ) ) ) { Fatal( "openSession" ); }
CComPtr<IDiaSymbol> pglobal; if ( FAILED( psession->get_globalScope( &pglobal) ) ) { Fatal( "get_globalScope" ); }
CComPtr<IDiaEnumTables> pTables; if ( FAILED( psession->getEnumTables( &pTables ) ) ) { Fatal( "getEnumTables" ); }
CComPtr< IDiaTable > pTable; while ( SUCCEEDED( hr = pTables->Next( 1, &pTable, &celt ) ) && celt == 1 ) { // Do something with each IDiaTable. }
And the following lines indicate how to translate addr to function lines:
void dumpFunctionLines( IDiaSymbol* pSymbol, IDiaSession* pSession )
{
ULONGLONG length = 0;
DWORD isect = 0;
DWORD offset = 0;
pSymbol->get_addressSection( &isect );
pSymbol->get_addressOffset( &offset );
pSymbol->get_length( &length );
if ( isect != 0 && length > 0 ) {
CComPtr< IDiaEnumLineNumbers > pLines;
if ( SUCCEEDED( pSession->findLinesByAddr( isect, offset, static_cast<DWORD>( length ), &pLines ) ) ) {
CComPtr< IDiaLineNumber > pLine;
:
: