Querying the .Pdb File

A program database file (extension .pdb) is a binary file that contains type and symbolic debugging information gathered over the course of compiling and linking the project. A PDB file is created when you compile a C/C++ program with /ZI or /Zi or a Visual Basic, Visual C#, or JScript program with the /debug option. Object files contain references into the .pdb file for debugging information. For more information on pdb files, see PDB Files. A DIA application can use the following general steps to obtain details about the various symbols, objects, and data elements within an executable image.

To query the .pdb file

  1. Acquire a data source by creating an IDiaDataSource interface.

    CComPtr<IDiaDataSource> pSource;
    hr = CoCreateInstance( CLSID_DiaSource,
                           __uuidof( IDiaDataSource ),
                          (void **) &pSource);
    if (FAILED(hr))
        Fatal("Could not CoCreate CLSID_DiaSource. Register msdia80.dll." );
  2. Call IDiaDataSource::loadDataFromPdb or IDiaDataSource::loadDataForExe to load the debugging information.

    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" );
  3. Call IDiaDataSource::openSession to open an IDiaSession to gain access to the debugging information.

    CComPtr<IDiaSession> psession;
    if ( FAILED( pSource->openSession( &psession ) ) )
        Fatal( "openSession" );
  4. Use the methods in IDiaSession to query for the symbols in the data source.

    CComPtr<IDiaSymbol> pglobal;
    if ( FAILED( psession->get_globalScope( &pglobal) ) )
        Fatal( "get_globalScope" );
  5. Use the IDiaEnum* interfaces to enumerate and scan through the symbols or other elements of debug information.

    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.

See also