What settings do I need to set in Windbg to be able to step into/through MFC source code like I can with Visual Studio?
The Microsoft Foundation Class (MFC) Library supplies full source code. Header files (.h) are in the \atlmfc\include directory. Implementation files (.cpp) are in the \atlmfc\src\mfc directory.
To control the source path in WinDbg, do one of the following: Choose Source File Pathfrom the Filemenu or press CTRL+P. Use the .srcpath (Set Source Path)command. If you are using a source server, .srcfix (Use Source Server)is slightly easier.
If have Visual Studio 2015 with at least Update 1 , still may not step into the MFC code, even the symbols has been successfully loaded. For this issue see the next topic. The Update 1 for Visual Studio 2015 comes with /DEBUG:FASTLINK liker option.
In WinDbg, the Source window displays source files that have been loaded into the debugger. Opening the Source Window The debugger opens a source window when it loads a new source file.
Stepping into MFC source code requires two things: loading the correct MFC symbols, and setting up the correct source paths.
The common advice for setting symbol paths in Windbg is to use .symfix
, which adds the public Microsoft symbol server to your symbol path. This will allow Windbg to download PDBs from Microsoft for many Windows DLLs, including MFC DLLs. However, those PDBs don't include the private symbols needed for source stepping.
Instead, you need to tell Windbg to first look for the private-symbol PDBs that were installed with Visual Studio, and second to look to the symbol server:
.sympath c:\windows\symbols\dll
.symfix+ c:\symbols
Or, if you want to copy and paste into the File > Symbol File Path... dialog, use this:
c:\windows\symbols\dll;srv*c:\symbols*http://msdl.microsoft.com/download/symbols
The c:\symbols
path given to .symfix+
tells Windbg where to store cached copies of any PDBs it downloads from the server.
You can check that the correct PDB was found by starting an MFC app with Windbg (windbg app.exe
), forcing the MFC symbols to load, and checking the output (this is a log of a Windbg command session):
0:000> $$ setup the correct sympath
0:000> .sympath c:\windows\symbols\dll;srv*c:\symbols*http://msdl.microsoft.com/download/symbols
Symbol search path is: c:\windows\symbols\dll;srv*c:\symbols*http://msdl.microsoft.com/download/symbols
Expanded Symbol search path is: c:\windows\symbols\dll;srv*c:\symbols*http://msdl.microsoft.com/download/symbols
0:000> $$ find the MFC DLL's full path
0:000> lm fm mfc*
start end module name
528e0000 52fa2000 mfc100d C:\Windows\SysWOW64\mfc100d.dll
72390000 7239d000 MFC100ENU C:\Windows\SysWOW64\MFC100ENU.DLL
0:000> $$ force the symbols to load
0:000> .reload /f C:\Windows\SysWOW64\mfc100d.dll
0:000> $$ check for "private pdb symbols"
0:000> lm m mfc*
start end module name
528e0000 52fa2000 mfc100d (private pdb symbols) c:\windows\symbols\dll\mfc100d.i386.pdb
72390000 7239d000 MFC100ENU (deferred)
Note the mfc100d line contains private pdb symbols. If that last command shows mfc100d (pdb symbols)
, without the word private, you don't have the correct PDB loaded, and you won't be able to step into MFC source. Try looking at your your sympath again. You can also try turning on !sym noisy
and running the .reload /f mfcdllpath
command to see more diagnostics about trying to load the PDB.
If you've done the default Visual Studio install, your MFC (and C-runtime) sources will be at:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\atl
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfc
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfcm
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src
For VS2010. Past versions have a similar directory layout. You can set that up with:
.sympath C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\atl;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfc;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfcm;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src;
Or copy and paste the above line (without .sympath
) into the File > Source File Path... dialog.
If those directories don't exist, you can look to see where Visual Studio thinks the MFC source code is.
VS2010 (and probably 2012):
VS2008 and earlier
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With