Debugger does not step into MFC source code - c++

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?
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.

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.

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

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.

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.

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.
Configuration: MSVS2022 Pro, Windows10, use MFC as a dynamic library.

Related

Debugging injected DLL with Visual Studio not working

I injected a C++ DLL into a target process like described here. In Visual Studio I want to debug the injected DLL like a "normal" application. I followed this tutorial which seems reasonable but Visual Studio does not break and only says:
The breakpoint will not currently be hit. No symbols have been loaded for this document.
Why? I'm using the default Debug configuration (with debugging symbols I believe). The DLL is injected successfully and executed the DllMain but Visual Studio does not "notice" that even though it is attached to the target process. Is there anything "special" I need to consider configuring in Visual Studio?
As far as I know even if the Dll was built with Debug configuration it won't contain all symbols necessary for debugging. You will still need its symbol file which is generated when building.
I assume you didn't build the DLL yourself because otherwise Visual Studio should be able to find the symbol file on your disk by itself. The symbol file has .pdb as extension and usually resides inside the build folder. You need to locate it and tell Visual Studio where to search for it during your debug session. When you have found the symbol file select "Debugging" from Visual Studio's menu bar and follow this path: "Options" => "Debugging" => "Symbols". Hit the button with the green plus sign to add the location where the symbol file resides. Take note that you only need to add the file's location, specifying its name is not required.

Visual Studio 2012 Performance Analysis failing to load symbol file

I have used the Visual Studio 2012 Performance Analysis to profile my C++ code for a long time, but recently when I try to use it seems to be failing to load the symbols as I get this error when I try to view the details
Matching symbols could not be found. Choose the 'Symbol Settings..'
link to add the symbol file location and then reload the report.
I have visited Options -> Debugging -> Symbols but I don't know what I need to add so that the symbols load correctly.
Currently in that menu Symbol file (.pdf) locations: has one option available in it and it called Microsoft Symbol Servers and it is selected. In the Cashe symbols in this directory: I can see it is being set in a temp folder but when I go that folder I see it is empty.
What do I need to add so that the symbols load correctly?
I asked this question on MSDN and I was told that this is a known issue with Visual Studio 2012 and Windows 8.1. Microsoft has either by now fixed it or will fix it in a future update. Here is a link to the MSDN question.
make sure you build your project with .pdb files and add these to the list of symbol locations (possible library pdb's as well). I know this should be a comment, but i don't have the reputation for it yet :(

Cannot step into the code while debugging a C DLL file in Visual Studio 2012

I have a separate Visual Studio solution with the DLL written in C. I use it in another solution; in a console C++ project. While debugging the console project I step into a DLL function.
However, the page is opened reporting that There is no source code available for the current location with call stack location MyConsole.exe!_tailMerge_MyLibrary_dll(). I use delay loading of the DLL file in the console project. As the no source code page is displayed, I inspect the output window and find symbols loaded of the DLL line. Why does Visual Studio 2012 fail to step into this DLL code?
I had the same problem and the following solved mine. I set "Debugger Type" to "Mixed" on the properties page of the main project. My main project is managed code while the .dll is native.
It happens, when dealing with external projects that Visual Studio asks you if you have the code. If you cancel the process, the requested file gets added to a list in the solution and it remembers NOT to ask for the file again.
Check your Solution Property Pages > Debug Source Files. First, make sure your file is NOT in Do not look for these source files: and then make sure you add the location of the sources in the Directories containing source code. This should help fix the problem.

visual studio 2010 c++ debugging symbols loaded but can't find source code

I've specified symbol (pdb) file inside 2010 so that it is loaded correctly but I get the No source available error and the Browse to Find Source Code is greyed out. Does anyone know how I can specify the source code directory or look inside the pdb to find out where it is?
EDIT: My DLL is being called by an external program. The error is happening inside my DLL so I have the source code. When the error occurs I click Debug, the pdb symbols are loaded but not the source.
If you moved the DLL from its build directory then the debugger is unlikely to be able to find the source code files itself. First thing you can do is to right-click the Solution root node in the Solution Explorer window, Properties, Common Properties, Debug Source Files and add the path to the DLL project source directory.
Second way: the debugger prompts you the first time it needs to find a source code file. If you ever clicked Cancel on that dialog, pretty common thing to do when you don't know what it is really asking, then the IDE remembers your selection and won't prompt you again. Fix that by deleting or renaming the hidden .suo file in the solution directory.
From what I understand you just want to debug your program, that you have in form of DLL. The problem is that external program uses this DLL and you click "Debug" from the window that pops up after the error occurs.
I assume you want to open your project in Visual Studio and then press Ctrl + Alt + P to open "Attach to Process" window, where you should select process that uses this DLL (iexplore.exe or whatever you are working with) so that you can toggle some breakpoints there and see what's going on before the error occurs.
The hack by #Hans Passant works, but there's actually an official way to achieve this: right click your solution at the solution explorer, select properties / Common Properties / Debug source files. You should be able to see and edit a list of all files where you previously selected 'cancel' when prompted for a source path.

LINK : fatal error LNK1104: cannot open file 'MSVCRTD.lib'

I'm a novice C++ developer. I encontered the error message indicates "LINK :fatal error LNK1104: cannot open file 'MSVCRTD.lib'" while I'm trying to debug every single project in Microsoft Visual C++ 2010 Express. I searched on Stack overflow and Google for any possible resolution, but I couldn't find exact and precise answer. What I have understood is that the "msvcrtd.lib" file should be in "\Microsoft Visual Studio 10.0\VC\lib", but that file is not there in my case. What should I do?
For the poor souls out there who are struggling with this, after an hour of research I found a solution for my Visual Studio Enterprise 2017:
First, lets find where is your library file located:
With windows explorer, go to your directory where Visual Studio is installed, (default: C:\Program Files (x86)\Microsoft Visual Studio) and do a search for msvcrtd.lib
I found mine to be in here:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\lib\onecore\x86
Quick Fix (for one project only):
Right click on your project, click on properties, navigate to Linker, add that path to Additional Library Directories
Permanent Fix (for all projects)
Open a project
navigate to View > Property Manager (it could be under Other Windows)
Expand all folders and multi select all "Microsoft.cpp.Win32.user" & "Microsoft.cpp.64.user"
Right click and go to properties
Navigate to VC++ Directories
Add the path to default Library Directories
Go to your project properties, select Linker from left. Add this to "Additional Library Directories":
"(Your Visual Studio Path)\VC\lib"
For example:
C:\Program Files\Microsoft Visual Studio 10.0\VC\lib
I came across this problem when compiling a sample app using VS2017
Hope this will help
There is a check box that says "Inherit from parent or project defaults" in some of the property dialogs in Project Properties. Make sure that check box is checked for your Include and Library directories property windows and of course for your Additional Dependencies window.
If you use VS2017, please read it. Or just ignore this answer...It may be invalid for other VS version.
Do not trust anyone who told you to add lib path.
Here's suggestions:
[BEST] You just need to install these via VS_installer (most of us just need x86/x64 version below)
VC++ 2017 version version_numbers Libs for Spectre [(x86 and x64) | (ARM) | (ARM64)]
Visual C++ ATL for [(x86/x64) | ARM | ARM64] with Spectre Mitigations
Visual C++ MFC for [x86/x64 | ARM | ARM64] with Spectre Mitigations
[NAIVE] or disable Spectre Option for every Solution
(Why We are so hard to global disable it)
[LAUGH] Or never use VS2017
This is VisualStudioTeam's fault and Microsoft is guilty.
Why?
You can't make a global configuration to disable /QSpectre, and IDK when and why VS2017 enable it in one day. So the best way is install Spectre? ahhha?
For VS 2019, Spectre Mitigation is enabled by default.
So the right way to fix the issue would be to install VC++ Libs for Spectre.
But, to quickly resolve the issue, you may disable Spectre Mitigation
Project Properties -> C/C++ -> Code Generation -> Spectre Mitigation -> Disabled
https://devblogs.microsoft.com/cppblog/spectre-mitigations-in-msvc/
I ran into this issue. The file existed on my machine, it was in the search path. I was stumped as the error result is really unhelpful. In my case I had turned on Spectre mitigation, but had not downloaded the runtime libs for Spectre. Once I did the download all was right with the world. I had to get this installed on my CI build servers also, as these libs are not installed with VS by default.
I have solved this problem, you need install all spectre lib.
Vistual Studio Installer->Modify->Component->Any spectre lib.
This solution can be adapted to any project.
For me this issue happens after installing the (Windows Driver Kit): https://learn.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk
Uninstalling it fixes the problem. Just posting here as a related issue for people looking for solutions: After installing WDK VC++ is broken
Scenario:
Windows 10 with Visual Studio 2017 (FRESH installation).
'C' project (LINK : fatal error LNK1104: cannot open file 'MSVCRTD.lib').
Resolve:
Run 'Visual Studio Installer'.
Click button 'Modify'.
Select 'Desktop development with C++'.
From "Installation details"(usually on the right-sidebar) select:
4.1. VC++ 2015.3 v14.00(v140) toolset for desktop.
Version of 'toolset' in 4.1. is just for example.
Click button 'Modify', to apply changes.
Right-click 'SomeProject' -> 'Properties' ->
'Linker' ->
'General' ->
'Additional Library Directories': $(VCToolsInstallDir)\lib\x86
(!!! for x64 project: 'Additional Library Directories': $(VCToolsInstallDir)\lib\x64 !!!)
it is also worth checking that MSVCRTD.lib file is present in "C:\Program Files\Microsoft Visual Studio 10.0\VC\lib" for x64 and in C:\Program Files(x86)\Microsoft Visual Studio 10.0\VC\lib for 32 bit. Sometimes VS might not be installed properly OR these files might get deleted accidentally.
I just had this error, in my case rebuilding the project while doing nothing else worked for me.
Here's my situation
Visual studio crashed and I had to re-install and my new installation path is different than the previous one. then I had this error
the error showed that the library is located at
D:\program\Microsoft Visual Studio\...
while it should be
D:\program files\Microsoft Visual Studio\...
as I said I just rebuilt it and it worked for me and if you have a multi-solution project you have to rebuild the whole-solution
I solved the problem by adding #using <mscorlib.dll> in the main file
This indicates that Visual Studio wasn't able to find the lib (Library) directory which contains msvcrtd.lib.
IMPORTANT: This lib directory also contains linkers required during the compilation process.
So, all you need to do is override the Library Directory location. You can do so with the help of Environment Variables.
I referred to this StackOverflow Post for help. As per the answer posted, the Environment Variable LIB refers to the path where the Linker Libraries are located. Why is this method better? Because this will apply to all the projects instead of just a particular project. Also, you don't need to download anything extra. It just works...
Follow the steps below to achieve this:
STEP-1: Search for "msvcrtd.lib" in the search bar.
STEP-2: Click "Open File Location" (available in context menu)
STEP-3: Copy the address of the directory from the address bar.
STEP-4: Search "Environment" in the taskbar and click on "Edit the system environment variables".
STEP-5: Click on "Environment Variables..." button.
STEP-6: Under "System variables" section, click on "New..." button. A dialog would pop up.
STEP-7: In the dialog box, enter the following:
Variable name: LIB
Variable value: [The directory you copied in "STEP-3"]
And press "OK"
Now, you are all done!
The above answer was not quite accurate for me. I have VS2010 Ultimate installed and the file in question is not in my Visual Studio 10.0\VC folder. Rather I found it in the Visual Studio 9.0\VC folder. So if that's the case for anyone, follow the lead to change the Linker but use the Visual Studio 9.0\VC folder instead. It worked for me.
For Visual Studio 2017
Go to your project properties, select Linker from left. Add this to "Additional Library Directories":
C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\VC\lib
I got a slightly different error
LNK1104 cannot open file 'MSVCURTD.lib'
Note it is msvcUrtd (not msvcrtd), but the file is not found on my system.
Solved it by setting the following options:
Project Properties
General
Character Set: Not Set
Common Language Runtime Support: Common Language Runtime Support (/clr)
Hope that helps.
In VS2017 (Community/Enterprise/Ultimate/Professional):
Add the path(s) of the folder(s) which include your desired ".lib" file(s) in the following path in VS:
(Right Click)Project(in Solution Explorer)->Properties->Configuration Properties->Linker->General->Additional Library Directories
If there are more than one ".lib" file use ';' to separate them otherwise click on the edit box corresponds to "Additional Library Directories" then click on "" in drop down menu and add all desired ".lib" files in newly opened window one by one and in a easy to handle manner.
I ran into this using Visual Studio 2017. I tried the solutions suggested here with explicitly adding paths to where the 'MSVCRT.lib' file was located. But I felt this probably wasn't the correct approach because previously for the past several weeks this had not been a problem with my project.
After trial and error, I discovered that if I left an empty or blank value in the Linker --> Input section, it would give me the error about LNK1104: cannot open file 'MSVCRT.lib'. Eventually I figured out that I should leave this value there instead.
On the Visual Studio project, right-Clicking on the project item in the Solution explorer panel (not the Solution itself, which is the topmost item), then select Properties. From there do the following:
Linker --> Input : %(AdditionalDependencies)
This additional information might be helpful, if you got into the situation the same way I did. I have discovered that I should not put any non-system library paths in the Linker --> Input section. With my project I was trying to compile with external .lib files. Previously I had a value in this input section like: $(ProjectDir)lib; %(AdditionalDependencies) but this lead to other problems. I discovered the correct place (it seems so far) to put paths for referencing external .lib files in a C/C++ project in Visual Studio 2017 is here:
VC++ Directories --> Library Directories : $(ProjectDir)lib; $(LibraryPath)
Note the $(LibraryPath) value will include extra values such as inherited from parents. My folder project contained a folder called 'lib' which is why I had the first value there before the semicolon.
I have included the following path
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86
and
C:\local\boost_1_64_0\lib64-msvc-14.1
To
project properties-> linker-> Additional Directories
Click here : Image shows linking of boost and MSVC2017