简体   繁体   English

你如何根据另一个断点被击中添加条件中断? 可视化 C++

[英]How do you add conditional breaking based on another breakpoint being hit? Visual C++

I have a bunch of generic code that is used a lot, which i'd like to poke into in order to deal with a bug in a certain specific case.我有一堆经常使用的通用代码,我想深入研究这些代码以处理特定情况下的错误。

So I'd like to break on a set of breakpoints only if some other breakpoint has been hit.因此,仅当遇到其他断点时,我才想在一组断点上中断。 Is there a way to do this in Visual 2005?有没有办法在 Visual 2005 中做到这一点? I'm using C++ code.我正在使用 C++ 代码。

Thanks!谢谢!

请记住,您可以禁用断点 - 禁用第二个断点可能更容易/更高效/更干净(然后将调试标志添加到您的代码并重新编译)您的断点窗口 - 每次调试时只需单击两次鼠标... :)

If the trigger logic is complex enough, sometimes I find it easier to just add a DebugBreak ();如果触发逻辑足够复杂,有时我会发现添加一个DebugBreak () 更容易; call into the source.调用源。

Have your first breakpoint change the value of some variable to a magic value (you can use a conditional breakpoint, with an expression which changed the variable and then returned true).让您的第一个断点将某个变量的值更改为一个魔术值(您可以使用条件断点,使用一个更改变量然后返回 true 的表达式)。 Then, have the second breakpoint break when the variable is at that magic value.然后,当变量处于那个神奇值时,让第二个断点中断。 eg,例如,

int debug_flag = 0;

First breakpoint condition:第一个断点条件:

debug_flag = 0xdeadbeef, true

Second breakpoint condition:第二个断点条件:

debug_flag == 0xdeadbeef

Ten years later...十年后...

An easy way to do what the OP wants would be to use the immediate window to define a global variable, and use it as suggested by @chris-jester-young in breakpoints conditions.执行 OP 想要的操作的一种简单方法是使用立即窗口来定义全局变量,并按照 @chris-jester-young 的建议在断点条件下使用它。

Did the trick for me anyway.反正对我有用。

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

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