DbgHelp examples
Here you can find complete examples of using various DbgHelp functions.
Of course, there are various examples of using DbgHelp available on the Internet, magazines and books. But since most of them were published, DbgHelp continued to evolve and introduce new functions to work with debug information (often replacing old functions with the new ones). These examples show how to use the latest versions of the functions.
Every example can be compiled and used as a simple tool to explore the corresponding contents of debug information.
How to build and run the examples
List of examples
Init.cpp | The simplest possible example. It shows how to initialize and deinitialize DbgHelp, load symbols for all modules in the current process, ask DbgHelp to produce additional troubleshooting messages. |
SymLoad.cpp | This example shows how to load symbols for an executable and analyze what kind of symbols is loaded (private symbols, public symbols, exports, symbol format, etc.) |
SymLoadPdb.cpp | This example extends SymLoad example with the possibility to load symbols from a standalone .PDB file. |
SymFromAddr.cpp | This example shows how to look up a symbol by address. |
SymFromName.cpp | This example shows how to look up a symbol by name. |
EnumSymbols.cpp | This example shows how to load symbols for an executable or from a standalone .PDB file and enumerate all global symbols (functions, global variables, static variables, public symbols). Search mask can be used. |
LocalsByAddr.cpp | This example shows how to enumerate local variables and parameters of a function. |
SymLines.cpp | This example shows how to enumerate all source lines that belong to a particular source file. |
LineFromAddr.cpp | This example shows how to determine the source file and line number that corresponds to the specified address in the executable. |
AddrFromLine.cpp | This example shows how to determine the address in the executable that corresponds to the specified source file and line number. |
LineOffsets.cpp | This example shows how to enumerate all source lines that belong to the specified source file, and how to determine what address in the executable corresponds to every source line. |
How to build and run examples
The following steps are needed to build the examples:
1. Find the latest versions of DbgHelp.dll, DbgHelp.h and DbgHelp.lib files.
The latest versions of these files are always available with Debugging Tools for Windows package. Download and install Debugging Tools for Windows (when installing, choose custom installation and install SDK).
2. Configure Visual Studio to find DbgHelp.h and DbgHelp.lib files.
These files are supplied with Visual Studio and Platform SDK, but it is necessary to use the latest files - the files that come with Debugging Tools for Windows. Thus it is necessary to configure Visual Studio include and library directories so that the latest files will be found first.
Use the following directories:
Include -> %DebuggingTools%\sdk\inc
Library -> %DebuggingTools%\sdk\lib\i386
3. Create a project and add an example file to the project.
4. When the project is built, make sure that the executable can find the latest version of DbgHelp.dll.
Copy DbgHelp.dll from the installation directory of Debugging Tools for Windows to the directory where the example executable resides.
Note: Most of the examples can use symbol server. If you want to let them use symbol server, make sure that SymSrv.dll is also available in the directory where the example executable resides. SymSrv.dll can also be taken from the installation directory of Debugging Tools for Windows.