Debugger does not step into MFC source code
Asked Answered
Z

5

8

I have a new SDI project in VS2010 but I can't step into MFC source. I followed the steps here and it seems like the resource symbols are not loaded for some reasons but it wouldn't load on right click either as described in the most voted answer there.

When I go into debug >> Windows > Modules, that window shows the symbol status column as Cannot find or open the PDB file. I guess that's the problem but when I right click on any one module (for example mfc100enu.dll) I get another dialog with similar message than can't find symbol file.

What could have gone wrong that it can't find symbol files and how to fix this?

Module Window

The function I want to step into is LoadFrame in below in my basic SDI application.

BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext) 
{
    // base class does the real work

    if (!CFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))
    {
        return FALSE;
    }

...
}

Any hints how can I not load them and what might be wrong? Thanks

Update

I was able to get VS2010 to load the symbol files by going to Tools->Options->Debugging->Symbols and select checkbox "Microsoft Symbol Servers" and now Visual Studio loads PDBs automatically. However I still can't step into the function.

Zamia answered 22/4, 2014 at 14:52 Comment(9)
mfc code is proprietary AFAIK, I don't think you can.Damned
Where do you want to step into? I just checked with VS2005 and it allows me to step into objcore.cpp which is located for me here: C:\Program Files (x86)\Microsoft Visual Studio 8\VC\atlmfc\src\mfcHardheaded
@marcin_j I updated question with the function.Zamia
Also it looks like you are trying to debug MFC application that uses non debug MFC dll, it should end with d - in my case its mfc80ud.dll. Maybe thats the problem.Hardheaded
@LuchianGrigore: MFC if proprietary, but the MFC sources are distributed with Visual Studio, and normally (and fortunately) you can step into MFC code.Basketwork
ok, now I see mfc100ud.dll on your list. CFrameWndEx should be in afxframewndex.h, search your VS installation if such file existsHardheaded
@marcin_j yes its there in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\includeZamia
@zadane do you have VS 2010 SP1 installed?Hardheaded
Yes SP1 is installed, I have kept it very up to date.Zamia
C
8

Change your mfc library linking mode to static library. In project properties >> Configuration Properties >> General >> Use of MFC

After debugging, you can change back to what you like. Hope this help.

Cussed answered 15/11, 2015 at 12:1 Comment(2)
This is the right solution. But in VS2019, it's located under Configuration Properties >> Advanced >> Use of MFCJovial
This ought not be the proper solution, but it's the only one that has worked for me in MSVS2022 so far. I tried loading and caching all symbols, adding the cache dir to the symbol sources, adding MFC lib dir there too, switching debug mode to /DEBUG, but until I linked statically, it wouldn't step into it. Modules window shows everything as loaded.Counterstamp
I
7

I found that adding the symbol servers didn't solve the problem for me.

What did solve the problem was adding this directory to the list of locations to look for symbols. Not sure why Visual Studio doesn't add this itself.

C:\Windows\Symbols\dll

Inhalator answered 23/3, 2015 at 10:33 Comment(1)
With my install of VS 2015, adding C:\Windows\Symbols\dll didn't help, however adding a few directories from C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\lib did help.Lunn
H
4

With Visual Studio 2019, I had same issue. I can't step-into MFC base classes with VC debugger. I have solved it with adding Symbol dir. to "Symbol file locations".

Tools > Options > Debugging > Symbols

  • C:\Program Files (x86)\Microsoft Visual Studio\2019\ (Edition)\VC\Tools\MSVC\14.27.29110\atlmfc\lib\x86
  • C:\Program Files (x86)\Microsoft Visual Studio\2019\ (Edition)\VC\Tools\MSVC\14.27.29110\atlmfc\lib\x64

Additionally, this setting can't solve MBCS - Multi-byte character set project. For multibyte project, you have to use "Microsoft Symbol Server". VS installer does not install required symbol files for you. It means you cannot debug MBCS project without public network to MS.

  • Check "Microsoft Symbol Servers" option at "Symbol file locations"

Check next links for more information.

https://learn.microsoft.com/ko-kr/cpp/mfc/mfc-mbcs-dll-add-on

https://support.smartbear.com/testcomplete/docs/app-testing/desktop/visual-c/preparing/mfc-debug-info.html#WindowsSymbolCache

I think VS2019 installer and installation are too complex. And MS changes it rapidly. They must not continue it before all developer leaves VS platform.

Hourihan answered 8/4, 2021 at 0:55 Comment(0)
E
3

You need a Visual Studio Professional or above. Then you get the sources and debug symbols for MFC. If that is given, you only need to ensure that the PDBs are located in the symbol path, which should be the case with a proper Visual Studio installation.

Euraeurasia answered 22/4, 2014 at 15:1 Comment(3)
I am using VS2010 professional. Also in tools >> Options >> Debugging >> Symbols and I clicked on Load all symbols to load all symbols just in case but to no use.Zamia
@zadane : did you install the MFC source files during the installation ? (Not sure if the installer asks).Basketwork
@MichaelWalz This was a long time back but I am sure MFC source code was installed because this probably came up abruptly down the road and probably resolved itself later somehow as well.Zamia
C
1

I created a cache dir for symbols and loaded them all. The Modules windows told me that the proper PDB loaded OK. But I still couldn not step into MFC. After playing with other solutions, like adding symbols cache and mfc lib directories to symbol locations, linking statically (which worked), it appeared that simply checking

Tools > Options > Debugging -> General -> Enable Just My Code

OFF

did the trick. I tried stepping into CWinAppEx::InitInstance and now I can.

enter image description here

Configuration: MSVS2022 Pro, Windows10, use MFC as a dynamic library.

Counterstamp answered 25/10, 2022 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.