简体   繁体   English

Visual Studio调试器跳过断点

[英]Visual Studio Debugger skips over breakpoints

My Visual Studio 2008 IDE is behaving in a very bizarre fashion while debugging a unit test: I have a breakpoint and when I hit it and then try to step with F10 the test concludes. 在调试单元测试时,我的Visual Studio 2008 IDE表现得非常怪异:我有一个断点,当我碰到断点,然后尝试使用F10时,测试就结束了。 If I Set breakpoints on every line inside the method being tested I will end up at a random one, not the next one on the following line. 如果我在要测试的方法内的每一行上设置断点,我将得到一个随机的断点,而不是下一行的下一个断点。 I have cleaned and rebuilt the solution after a clean system restart. 干净的系统重新启动后,我已经清理并重建了解决方案。 The behavior persists. 该行为仍然存在。 Has anyone else experienced this and come to a conclusion. 有没有其他人经历过这一点并得出结论。

This test only used the main execution thread (no additional threads are being created) 该测试仅使用主执行线程(未创建其他线程)

There was a post VS2008 SP1 hotfix released that solves a number of debugging problems. VS2008 SP1发布了一个修补程序,解决了许多调试问题。 The KB article is here , the hotfix download is here . KB文章在这里 ,修补程序下载在这里


UPDATE: the hotfix download location was retired, I don't know of an alternative download location. 更新:修复程序下载位置已停用,我不知道其他下载位置。 Please edit this post if you find one. 如果找到一个,请编辑此帖子。

This behaviour happens if you debug the release build (since lines are optimized away). 如果您调试发布版本,则会发生此行为(因为优化了行)。

It also happened to me in the past if by accident I'm debugging an older exe somewhere else (as set by the project config), instead of the most recently build one ;^) 如果我偶然在其他地方调试了一个较旧的exe(由项目配置设置),而不是最近构建的一个;这也是我的经历; ^)

I had similar issues on VS 2003. It turned out that I was using wrong symbols so they could not be bind to correct source. 我在VS 2003上遇到过类似的问题。事实证明,我使用了错误的符号,因此无法将其绑定到正确的源。

Make sure in a following: 请确保以下内容:

  1. That you're using the Debug build (or that any kind of Optimization is turned off) 您正在使用Debug版本(或已关闭任何类型的优化功能)
  2. That build output path is OK ( that "Project Properties\\Linker\\Output File" match to the exe you're debugging) 该构建输出路径是确定的(“ Project Properties \\ Linker \\ Output File”与您正在调试的exe匹配)
  3. That you don't place breakpoints on variable declarations: ie if you place a break point on "int some_variable;", you will never hit it but instead you'll hit the first place after it where you defining\\initialize something or calling some methods 不要在变量声明上放置断点:即,如果在“ int some_variable;”上放置断点,则永远不会命中它,而是会在定义\\初始化某些内容或调用某些内容时将其放在第一位方法
  4. You can't step-into with F10 (executes next statement) but with F11 (executes next statement and follows execution into method calls) 您不能使用F10(执行下一条语句),而可以使用F11(执行下一条语句,然后执行到方法调用中)
  5. Make sure you don't have any filters on breakpoints (ie Hit count or condition) 确保您没有任何断点过滤器(例如,命中数或条件)

ps try placing the DebugBreak(); ps尝试放置DebugBreak(); function in both methods (unless this code is executed inside some loop so this might be frustrating). 在这两种方法中都起作用(除非此代码在某个循环内执行,否则可能会令人沮丧)。 This should cause terminating your process when execution reach any of these functions (so you can continue with debugging from that particular place). 当执行达到任何这些功能时,这将导致终止进程(因此您可以从该特定位置继续进行调试)。

当您运行多个线程时,也会发生此行为。

Even in a Debug build, compiler optimizations could explain this behaviour. 即使在Debug版本中,编译器优化也可以解释这种现象。 Under project properties, "Build", verify that the checkbox 'optimize code' is turned off. 在项目属性“构建”下,确认已关闭“优化代码”复选框。 I have seen this turned on by default after upgrading certain projects from .Net 1.1. 从.Net 1.1升级某些项目后,我默认情况下已启用此功能。

Are you putting your breakpoints inside code that is part of a generated class? 您是否将断点放在生成的类的代码中?

I have experienced this problem on the client site of a service reference. 我在服务参考的客户端站点上遇到了此问题。 The generated classes are partial classes with the 生成的类是带有

    [System.Diagnostics.DebuggerStepThroughAttribute()]

attribute applied. 属性已应用。 Even when my breakpoint was in a different file, but still part of the attributed class, the breakpoint would be skipped. 即使当我的断点在另一个文件中,但仍属于属性类的一部分时,也会跳过该断点。

I removed that attribute from the generated Reference.cs file and the debugger worked as I expected. 我从生成的Reference.cs文件中删除了该属性,调试器按预期工作。

Of course, this isn't a permanent solution because if the Reference.cs file gets regenerated, the attribute comes back. 当然,这不是永久性的解决方案,因为如果重新生成Reference.cs文件,则该属性会返回。

May be it is too late to reply, I got same issue in VS2012 to fix that please check if menu Test>TestSettings> "LocalTestRun.TestRunConfig" is checked, if it is checked uncheck it and it will stop skipping the code lines. 可能为时已晚,我在VS2012中遇到了同样的问题,要修复,请检查菜单Test> TestSettings>“ LocalTestRun.TestRunConfig”是否已选中,如果未选中则将停止跳过代码行。 May be same for Vs2008 also work. 可能与Vs2008相同,也可以。

This may be as simple as a case of the testing framework not loading the same assembly that you're currently working on. 这可能就像测试框架没有加载您当前正在使用的同一程序集一样简单。 I've had this happen in rare cases in NUnit, which works off a copy of your assembly under test; 我在NUnit中很少见到这种情况,它可以处理被测程序集的副本。 occasionally, it stopped copying over the most recent version. 偶尔,它会停止复制最新版本。 Are your breakpoints decorated with a "symbols have not been loaded" indicator? 您的断点是否装饰有“未加载符号”指示符?

Go into Project->Properties and uncheck "Optimize Code" 进入“项目”->“属性”,然后取消选中“优化代码”

This is the case if you see code such as DataSet ds = new DataSet(); 如果您看到诸如DataSet ds = new DataSet();的代码,就是这种情况。 gets hit on the debugger but code like string Test = "Test"; 被调试器击中,但是像字符串Test =“ Test”这样的代码; gets skipped. 被跳过。

I ran into this in Visual Studio Community 2013. The behavior appears to be by design. 我在Visual Studio Community 2013中遇到了此问题。此行为似乎是设计使然。 When running tests, execution will not stop on breakpoints. 运行测试时,执行不会在断点处停止。 When you want execution to stop on breakpoints, selects TEST --> Debug rather than TEST --> Run. 如果要在断点处停止执行,请选择TEST-> Debug,而不是TEST-> Run。

My unit tests were testing under x86. 我的单元测试是在x86下进行的。 Changing them to x64 worked. 将它们更改为x64可行。

Menu 菜单

Test -> Test Settings -> Default Processor Architecture -> x64 . Test -> Test Settings -> Default Processor Architecture -> x64

F10 is Step Over , F5 is continue to next breakpoint, F11 is Step Into, which executes the next line of code then waits. F10是Step Over ,F5是下一个断点,F11是Step Into,执行下一行代码然后等待。 That is what you are probably looking for. 那可能就是您想要的。

I just encountered the same issues and went through all the suggestions above with no luck. 我只是遇到了同样的问题,并且碰巧遇到了以上所有建议。 Come to find out at some point in the past someone had changed the method signature to be "private" when it must be "static" or "public". 过去发现有人在方法签名必须为“静态”或“公共”时将其更改为“私有”。 As soon as I changed the test method's signature back to "public", the break points started working again. 一旦将测试方法的签名重新更改为“ public”,这些断点就会重新开始工作。

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

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