|
2 | 2 | title: "Querying the .Pdb File | Microsoft Docs"
|
3 | 3 | ms.date: "11/04/2016"
|
4 | 4 | ms.topic: "conceptual"
|
5 |
| -dev_langs: |
| 5 | +dev_langs: |
6 | 6 | - "C++"
|
7 |
| -helpviewer_keywords: |
| 7 | +helpviewer_keywords: |
8 | 8 | - "PDB files"
|
9 | 9 | - ".pdb files, querying"
|
10 | 10 | ms.assetid: 8da07d1c-2712-45f9-8fbf-f34040408a8a
|
11 | 11 | author: "mikejo5000"
|
12 | 12 | ms.author: "mikejo"
|
13 | 13 | manager: jillfra
|
14 |
| -ms.workload: |
| 14 | +ms.workload: |
15 | 15 | - "multiple"
|
16 | 16 | ---
|
17 | 17 | # Querying the .Pdb File
|
18 |
| -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 [!INCLUDE[vbprvb](../../code-quality/includes/vbprvb_md.md)], [!INCLUDE[csprcs](../../data-tools/includes/csprcs_md.md)], or [!INCLUDE[jsprjscript](../../debugger/debug-interface-access/includes/jsprjscript_md.md)] 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](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/yd4f8bd1(v=vs.100)). A DIA application can use the following general steps to obtain details about the various symbols, objects, and data elements within an executable image. |
19 |
| - |
20 |
| -### To query the .pdb file |
21 |
| - |
22 |
| -1. Acquire a data source by creating an [IDiaDataSource](../../debugger/debug-interface-access/idiadatasource.md) interface. |
23 |
| - |
24 |
| - ```C++ |
25 |
| - CComPtr<IDiaDataSource> pSource; |
26 |
| - hr = CoCreateInstance( CLSID_DiaSource, |
27 |
| - NULL, |
28 |
| - CLSCTX_INPROC_SERVER, |
29 |
| - __uuidof( IDiaDataSource ), |
30 |
| - (void **) &pSource); |
31 |
| - |
32 |
| - if (FAILED(hr)) |
33 |
| - { |
34 |
| - Fatal("Could not CoCreate CLSID_DiaSource. Register msdia80.dll." ); |
35 |
| - } |
36 |
| - ``` |
37 |
| - |
38 |
| -2. Call [IDiaDataSource::loadDataFromPdb](../../debugger/debug-interface-access/idiadatasource-loaddatafrompdb.md) or [IDiaDataSource::loadDataForExe](../../debugger/debug-interface-access/idiadatasource-loaddataforexe.md) to load the debugging information. |
39 |
| - |
40 |
| - ```C++ |
41 |
| - wchar_t wszFilename[ _MAX_PATH ]; |
42 |
| - mbstowcs( wszFilename, szFilename, sizeof( wszFilename )/sizeof( wszFilename[0] ) ); |
43 |
| - if ( FAILED( pSource->loadDataFromPdb( wszFilename ) ) ) |
44 |
| - { |
45 |
| - if ( FAILED( pSource->loadDataForExe( wszFilename, NULL, NULL ) ) ) |
46 |
| - { |
47 |
| - Fatal( "loadDataFromPdb/Exe" ); |
48 |
| - } |
49 |
| - } |
50 |
| - ``` |
51 |
| - |
52 |
| -3. Call [IDiaDataSource::openSession](../../debugger/debug-interface-access/idiadatasource-opensession.md) to open an [IDiaSession](../../debugger/debug-interface-access/idiasession.md) to gain access to the debugging information. |
53 |
| - |
54 |
| - ```C++ |
55 |
| - CComPtr<IDiaSession> psession; |
56 |
| - if ( FAILED( pSource->openSession( &psession ) ) ) |
57 |
| - { |
58 |
| - Fatal( "openSession" ); |
59 |
| - } |
60 |
| - ``` |
61 |
| - |
62 |
| -4. Use the methods in `IDiaSession` to query for the symbols in the data source. |
63 |
| - |
64 |
| - ```C++ |
65 |
| - CComPtr<IDiaSymbol> pglobal; |
66 |
| - if ( FAILED( psession->get_globalScope( &pglobal) ) ) |
67 |
| - { |
68 |
| - Fatal( "get_globalScope" ); |
69 |
| - } |
70 |
| - ``` |
71 |
| - |
72 |
| -5. Use the `IDiaEnum*` interfaces to enumerate and scan through the symbols or other elements of debug information. |
73 |
| - |
74 |
| - ```C++ |
75 |
| - CComPtr<IDiaEnumTables> pTables; |
76 |
| - if ( FAILED( psession->getEnumTables( &pTables ) ) ) |
77 |
| - { |
78 |
| - Fatal( "getEnumTables" ); |
79 |
| - } |
80 |
| - CComPtr< IDiaTable > pTable; |
81 |
| - while ( SUCCEEDED( hr = pTables->Next( 1, &pTable, &celt ) ) && celt == 1 ) |
82 |
| - { |
83 |
| - // Do something with each IDiaTable. |
84 |
| - } |
85 |
| - ``` |
86 |
| - |
87 |
| -## See Also |
88 |
| - [IDiaDataSource](../../debugger/debug-interface-access/idiadatasource.md) |
| 18 | +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 [!INCLUDE[vbprvb](../../code-quality/includes/vbprvb_md.md)], [!INCLUDE[csprcs](../../data-tools/includes/csprcs_md.md)], or [!INCLUDE[jsprjscript](../../debugger/debug-interface-access/includes/jsprjscript_md.md)] 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](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/yd4f8bd1(v=vs.100)). A DIA application can use the following general steps to obtain details about the various symbols, objects, and data elements within an executable image. |
| 19 | + |
| 20 | +### To query the .pdb file |
| 21 | + |
| 22 | +1. Acquire a data source by creating an [IDiaDataSource](../../debugger/debug-interface-access/idiadatasource.md) interface. |
| 23 | + |
| 24 | + ```C++ |
| 25 | + CComPtr<IDiaDataSource> pSource; |
| 26 | + hr = CoCreateInstance( CLSID_DiaSource, |
| 27 | + NULL, |
| 28 | + CLSCTX_INPROC_SERVER, |
| 29 | + __uuidof( IDiaDataSource ), |
| 30 | + (void **) &pSource); |
| 31 | + |
| 32 | + if (FAILED(hr)) |
| 33 | + { |
| 34 | + Fatal("Could not CoCreate CLSID_DiaSource. Register msdia80.dll." ); |
| 35 | + } |
| 36 | + ``` |
| 37 | + |
| 38 | +2. Call [IDiaDataSource::loadDataFromPdb](../../debugger/debug-interface-access/idiadatasource-loaddatafrompdb.md) or [IDiaDataSource::loadDataForExe](../../debugger/debug-interface-access/idiadatasource-loaddataforexe.md) to load the debugging information. |
| 39 | + |
| 40 | + ```C++ |
| 41 | + wchar_t wszFilename[ _MAX_PATH ]; |
| 42 | + mbstowcs( wszFilename, szFilename, sizeof( wszFilename )/sizeof( wszFilename[0] ) ); |
| 43 | + if ( FAILED( pSource->loadDataFromPdb( wszFilename ) ) ) |
| 44 | + { |
| 45 | + if ( FAILED( pSource->loadDataForExe( wszFilename, NULL, NULL ) ) ) |
| 46 | + { |
| 47 | + Fatal( "loadDataFromPdb/Exe" ); |
| 48 | + } |
| 49 | + } |
| 50 | + ``` |
| 51 | + |
| 52 | +3. Call [IDiaDataSource::openSession](../../debugger/debug-interface-access/idiadatasource-opensession.md) to open an [IDiaSession](../../debugger/debug-interface-access/idiasession.md) to gain access to the debugging information. |
| 53 | + |
| 54 | + ```C++ |
| 55 | + CComPtr<IDiaSession> psession; |
| 56 | + if ( FAILED( pSource->openSession( &psession ) ) ) |
| 57 | + { |
| 58 | + Fatal( "openSession" ); |
| 59 | + } |
| 60 | + ``` |
| 61 | + |
| 62 | +4. Use the methods in `IDiaSession` to query for the symbols in the data source. |
| 63 | + |
| 64 | + ```C++ |
| 65 | + CComPtr<IDiaSymbol> pglobal; |
| 66 | + if ( FAILED( psession->get_globalScope( &pglobal) ) ) |
| 67 | + { |
| 68 | + Fatal( "get_globalScope" ); |
| 69 | + } |
| 70 | + ``` |
| 71 | + |
| 72 | +5. Use the `IDiaEnum*` interfaces to enumerate and scan through the symbols or other elements of debug information. |
| 73 | + |
| 74 | + ```C++ |
| 75 | + CComPtr<IDiaEnumTables> pTables; |
| 76 | + if ( FAILED( psession->getEnumTables( &pTables ) ) ) |
| 77 | + { |
| 78 | + Fatal( "getEnumTables" ); |
| 79 | + } |
| 80 | + CComPtr< IDiaTable > pTable; |
| 81 | + while ( SUCCEEDED( hr = pTables->Next( 1, &pTable, &celt ) ) && celt == 1 ) |
| 82 | + { |
| 83 | + // Do something with each IDiaTable. |
| 84 | + } |
| 85 | + ``` |
| 86 | + |
| 87 | +## See Also |
| 88 | +[IDiaDataSource](../../debugger/debug-interface-access/idiadatasource.md) |
0 commit comments