“没有可用于当前位置的源代码”

哈哈哈,我也遇到这个问题,烦了我半个小时那个弹框。不过我解决它的问题居然是往那个源文件随便敲点注释上去,让它编译时得以重新编译。就这样好了,设断点时,那个可恶的弹框就不再出现了。

单步调试时出错,原来的断点处显示一个空心圆加一个右下角的警告图标,假如从另一个函数跳入到设置这种无效断点的文件时,便会出现错误的对话框。

网上搜了一下原因,有人写:

昨天对dnn跟踪调试的时,设了断点后运行到断点处总提示“The breakpoint will not currently be hit. The source code is different from the original version”,搜了一下,原因是:
The problem you're running into is caused by a new feature in the compilers and debugger to keep track of checksums for source files. Using this mechanism we can tell if the source file we're displaying in the debugger matches the original file used to build the application.
When you change a source file while debugging, and Edit and Continue is unavailable or disabled, you'll see warnings about the source not matching. Since Beta 2 we've improved the error message (no longer a Yes/No dialog, just a warning with an OK button). We've also changed the behavior so your breakpoints will no longer show this message when a source file does not match.
To clarify what the message is asking you to do: right-click on the breakpoint in question, and you should see a Location item. On the resulting dialog you should see an override checkbox which will get rid of the message you're seeing when you hover over your breakpoints. Or you could go to Tools->Options->Debugging->General and uncheck the "Require source to exactly match..." option, which will turn off all checksum functionality in the debugger.
偶的英语不太好,大致上看明白了,从菜单栏的 Tools->Options->Debugging->General  
取消 "Require source to exactly match..." 项的选择。
还有两个可能是
1.
打开项目属性,选择调试选项卡,将启用非托管代码调试一项钩上。
2.
由于Terminal Services 这个服务被禁用了,将这个服务设为自动,将这个服务启动。

我试了一下,确实就好了,下面是另一种方法,但不管用的:

*******************************

Source file: D:\Projects\StereoMatch\stereomatcher.cpp

Module: D:\Projects\StereoMatch\Debug\StereoMatch.exe

Process: [4024] StereoMatch.exe

The source file is different from when the module was built. Would you like the debugger to use it anyway?

*******************************

***********************************

At StereoMatcher.cpp, line 166 ('ComputeCorrespondence()', line 128)

The breakpoint will not currently be hit. The source code is different from the original version.

To allow the breakpoint to be hit when the source code is different, right-click on the breakpoint, choose 'Location ...', and turn on 'Allow the source code to be different from the original version.

To allow this for all breakpoints, disable the option 'Require source files to exactly match the original version' under Tools, Options, Debugging, General'

***********************************

When the compiler generates debug information, it will generate a hash (AFAICT, only MD5 is supported at this point) over all contributing source files (i.e. the .cpp file and all #include'd files). This information along with the full path of the files on the build machine eventually end up in the PDB file.

Now when the debugger tries to obtain a source file, it gets the full path name from the PDB file does some path-based mapping and opens the file. Then it generates the hash and check if it matches the one saved in the PDB.

In your case, it does not and that suggests your source file is outdated. You can force the debugger to ignore such mismatches, but it is obviously a feature designed to prevent you from looking at outdated source files while debugging.

Are you quite certain sources and debug information are from the same version (obviously you could just rebuild on your box to make sure)? May it works if you...

Delete all the files in the folders:

..\bin\Debug , ..\bin\Release, ..\obj\Debug , ..\obj\Release, ...obj\Debug\Refactor

For your primary program and the aditional projects in the solution and recompile.

Regards.

If there are any static libraries that you link to, these might be causing the problems. Do you see the problem for all files? Are these files included from precompiled source files (e.g. in static libs)?

There's the dia2dump sample, that might help you understand the problem. You need to build it first. Once you have, you can dump the hash for some of the conflicting files and compare against the real MD5 hash of the source files.

最后我还是想办法解决了这个问题,方法是先取消“Require source files to exactly match the original version”选项,然后修改一下程序,再在该文件设断点调试一下,然后重新选定“Require source files to exactly……”选项,这样就好了。

最后我想,断点调试失效的原因应该是我当时调试中间的时候顺便改写了程序,导致Visual Studio 2005对此进行了记录,而后面好像又强行关掉了Visual Studio 2005,导致记录没有被清除,后面就老是通不过源文件和debbuger编译时文件的同步检测。而后面我重新设断点调试和重新选中同步测试选项相当于把错误记录又清除掉了,所以就修复啦。

原文地址:https://www.cnblogs.com/freedesert/p/2656945.html