visual-studio 为什么我不能调试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/540536/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why can't I debug?
提问by MainID
When I was about to debug C++ program in VS2005,the program didn't stop at the breakpoints.
当我准备在VS2005中调试C++程序时,程序并没有停在断点处。
The VS said"No symbols are loaded for any call stack frame. The source code cannot be displayed".
VS 说“没有为任何调用堆栈帧加载符号。无法显示源代码”。
What can I do?
我能做什么?
回答by MainID
Thanks to everybody.
感谢大家。
Finally,I found a solution here.
最后,我在这里找到了解决方案。
To enable debugging:
1) Goto Project->HelloWorld Properties
2) On the left expand "Configuration Properties"
3) Expand "C/C++"
4) On the left, Select "General"
5) On the right, change "Debug Information Format" to "Program Database For Edit And Continue (/ZI)"
5) On the left, Select "Optimization"
6) On the right, change "Optimization" to "Disabled (/Od)"
7) On the left, expand "Linker"
8) On the left, select "Debugging"
9) On the right, change "Generate Debug Info" to "Yes"
10) Click ok
11) Set your breakpoints
12) Rebuild your application
Also when running your application use Ctrl+F5 to build and run it, this keeps the console window open long enough for you to see your output.
要启用调试:
1) 转到项目->HelloWorld 属性
2)在左侧展开“配置属性”
3) 展开“C/C++”
4)在左侧,选择“常规”
5)在右侧,将“Debug Information Format”更改为“Program Database For Edit And Continue (/ZI)”
5)在左侧,选择“优化”
6)在右侧,将“优化”更改为“禁用(/Od)”
7)在左侧,展开“链接器”
8)在左侧,选择“调试”
9)在右侧,将“Generate Debug Info”更改为“Yes”
10)点击确定
11) 设置断点
12) 重建您的应用程序
此外,在运行您的应用程序时,使用 Ctrl+F5 来构建和运行它,这会使控制台窗口保持打开足够长的时间,以便您看到您的输出。
回答by Steve Rowe
A few steps to try:
尝试的几个步骤:
- Debug->Step Into (this will ensure you stop right after you start)
- Debug->Windows->Modules
- Look for your foo.exe on the list.
- Check Symbol Status. Does it say it is loaded?
- If not, go to the path and ensure that: a) there is a file called foo.pdb there b) the timestamp on foo.pdb matches foo.exe (or is really close)
- Debug->Step Into(这将确保您在开始后立即停止)
- 调试->Windows->模块
- 在列表中查找您的 foo.exe。
- 检查符号状态。它说它已加载?
- 如果没有,请转到路径并确保:a) 那里有一个名为 foo.pdb 的文件 b) foo.pdb 上的时间戳与 foo.exe 匹配(或非常接近)
回答by Steve Rowe
For whatever reason you don't have the right symbols (.pdb files) in the symbol path. This could be for several reasons:
无论出于何种原因,您在符号路径中都没有正确的符号(.pdb 文件)。这可能有以下几个原因:
1) Your binary was compiled more recently than the .pdb files. Try recompiling everything.
1) 您的二进制文件的编译时间比 .pdb 文件的编译时间要晚。尝试重新编译所有内容。
2) You are trying to debug a .dll and forgot to copy the .pdb files. Copy those files too.
2) 您正在尝试调试 .dll 并忘记复制 .pdb 文件。也复制这些文件。
It's also possible that your code isn't being executed like you think.
您的代码也可能没有像您想象的那样执行。
回答by annakata
Complete clean and rebuild, making sure .pdb's get created?
完成清理和重建,确保 .pdb 被创建?
回答by jpoh
It sounds like you're attaching to a process rather than running a conventional debug session? If you are indeed attaching to a process, it is important to ensure that binaries that you are trying to debug were built with the same source code currently open in your IDE.
听起来您要附加到进程而不是运行传统的调试会话?如果您确实要附加到某个进程,请务必确保您尝试调试的二进制文件是使用当前在 IDE 中打开的相同源代码构建的。
回答by Stephen Curial
I've experienced this problem (using c# in VS) when trying to debug my unit tests.
我在尝试调试单元测试时遇到了这个问题(在 VS 中使用 c#)。
You can add the following code that will launch a new instance of the debugger that will allow you yo step through your code like normal:
您可以添加以下代码来启动调试器的新实例,让您可以像平常一样单步调试代码:
System.Diagnostics.Debugger.Launch();
System.Diagnostics.Debugger.Break();
回答by mort
Just to add another possibility not yet covered by MainID:
只是添加 MainID 尚未涵盖的另一种可能性:
When debugging, I actually started some program that would call into the classes I wanted to debug (it's some sort of add on). The called program is partly written in unmanaged C++. When I checked "Enable unmanaged code debugging" the error would come up (and subsequently the program crashed) because the program did not have any debug information.
在调试时,我实际上启动了一些程序来调用我想要调试的类(这是某种添加)。被调用的程序部分是用非托管 C++ 编写的。当我选中“启用非托管代码调试”时,会出现错误(随后程序崩溃),因为程序没有任何调试信息。
回答by creativemujahid
I have solved this problem in WP7 by doing this:
我通过这样做在 WP7 中解决了这个问题:
- Right click the project from Solution Explorer (Ctrl+W+S)
- Select Rebuild.
- Again, select the project, right click it and choose Deploy.
- Start Debugging (F5)
- 右键单击解决方案资源管理器中的项目 ( Ctrl+W+S)
- 选择重建。
- 再次选择项目,右键单击它并选择部署。
- 开始调试 (F5)
I hope it will help you!
我希望它会帮助你!

