简体   繁体   English

调试时自动禁用 Visual Studio 断点

[英]Visual Studio Breakpoints being automatically disabled while debugging

I am running C++ code in VS 2012. I have set a simple Breakpoint我在 VS 2012 中运行 C++ 代码。我设置了一个简单的断点

int main(int argc, char **argv)
{
    time_t start_time;
    time(&start_time);

    DUALISO_TIME dualiso_time;
    IO_TIME io_time = {0.0, 0.0};
    IO_INFO io_info;
    IJK::ERROR error;
    cout <<"DEBUG "<< endl;  // I have set a breakpoint.

While debugging the breakpoint briefly turns white (from red) but the debugger does not break at the break point, it just continues on.在调试断点时,断点短暂地变为白色(从红色),但调试器不会在断点处中断,而是继续进行。 (The code is being run because it prints DEBUG in console.) I have searched for a while but I have not found any solution. (代码正在运行,因为它在控制台中打印 DEBUG。)我已经搜索了一段时间,但没有找到任何解决方案。

Some notes.一些笔记。 The particular project is selected as the startUp Project.特定项目被选为启动项目。 I have tried cleaning and re-building.我试过清理和重建。 The part of the code is definitely being run.代码的一部分肯定正在运行。 I can even see the BreakPoint changing to white from red briefly, but the debugger is not stopping at the point.我什至可以看到 BreakPoint 短暂地从红色变为白色,但调试器并没有就此停止。 Here is SCREEN SHOT这是屏幕截图

Some reasons a breakpoint will not to be hit:断点不会被命中的一些原因:

  • The executable and the code do not match.可执行文件和代码不匹配。 For example, you changed the code, but the executable was in use when you compiled, and was not actually updated.例如,您更改了代码,但编译时可执行文件正在使用中,实际上并未更新。
  • The executable is running in Administrative mode, but Visual Studio is running as a regular user.可执行文件在管理模式下运行,但 Visual Studio 以普通用户身份运行。
  • Breakpoints can be disabled, but still exist.断点可以被禁用,但仍然存在。 Go to the breakpoints window and be sure the breakpoint is enabled.转到断点窗口并确保启用了断点。

One extra reason, if you work with C# at least (not sure if exactly the same applies to C++ projects):一个额外的原因,如果您至少使用 C#(不确定是否完全相同适用于 C++ 项目):

Your current build configuration is not configured to produce PDB files.您当前的构建配置未配置为生成 PDB 文件。

Go to your project, right click > Properties > Build > Advanced... > Debugging information .转到您的项目,右键单击 > Properties > Build > Advanced... > Debugging information

Set that to full .将其设置为full

Here are some reasons that weren't mentioned already:以下是一些尚未提及的原因:

  • macros can remove code in the preprocess phase可以删除预处理阶段的代码
  • optimizations .优化 Some code can be optimised out.一些代码可以优化出来。 Use no optimizations in order to debug.不使用优化以进行调试。

When the breakpoints are white that is the indication that Visual Studio is unable to match up the place in the source file with the application it is being debugged.当断点为白色时,表示 Visual Studio 无法将源文件中的位置与正在调试的应用程序匹配。 Typically this occurs for the following reasons通常发生这种情况的原因如下

  • The source and executable are out of date.源代码和可执行文件已过期。 A full rebuild will often fix this完全重建通常会解决这个问题
  • The PDB files for the executable cannot be located.无法找到可执行文件的 PDB 文件。 Go to Debug -> Windows -> Modules and make sure the PDB is correctly loaded转到 Debug -> Windows -> Modules 并确保 PDB 已正确加载

This can happen because of compiler optimizations.这可能是由于编译器优化而发生的。 If you compiled with gcc -O then the program will be optimized and Visual Studio breakpoints will become disabled after attaching the program.如果你用gcc -O编译,那么程序将被优化,并且在附加程序后 Visual Studio 断点将被禁用。 To solve this, you can disable the compiler optimization with additional 0 following the -O like below.为了解决这个问题,您可以在 -O 后面加上 0 来禁用编译器优化,如下所示。

gcc -O0

You can also use gcc -Og (available from gcc 4.8).您还可以使用gcc -Og (可从 gcc 4.8 获得)。 This should allow both optimization and debugging.这应该允许优化和调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM