Stepping into MFC source code with Windbg
Asked Answered
S

1

5

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?

Sufferance answered 22/2, 2013 at 18:56 Comment(0)
S
11

Stepping into MFC source code requires two things: loading the correct MFC symbols, and setting up the correct source paths.

MFC Symbols

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.

MFC Source Paths

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):

  • Launch Visual Studio
  • Open a project
  • In the Project menu, choose Properties
  • In the left pane, expand Configuration Properties and choose VC++ Directories
  • In the right pane, look at the value of Source Directories

VS2008 and earlier

  • Launch Visual Studio
  • In the Tools menu, choose Options
  • In the left pane, expand Projects and Solutions and choose VC++ Directories
  • In the right pane, look at the value of Source Directories
Sufferance answered 22/2, 2013 at 18:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.