如果已达到断点A,则启用断点B [英] Enable breakpoint B if breakpoint A has been hit

查看:101
本文介绍了如果已达到断点A,则启用断点B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常发现自己在代码中的某个位置设置了一个断点A,并在命中该断点时手动启用了一个或多个断点.一个典型的情况是,当我调试单元测试而不关心前面的测试时.

I'm often find myself setting a breakpoint A somewhere in the code and manually enabling one or more breakpoints when this breakpoint is hit. A typical case is when I'm debugging an unittest and don't care about the preceding tests.

void testAddZeros()
{
  Number a(0);
  Number b(0);
  Number result = a.add(b);
  assert((a + b) == Number(0))
}
void testAddOnes()
{
  Number a(1);
  Number b(1);
  Number result = a.add(b);
  assert((a + b) == Number(2));
}
void testAddNegativeNumber()
{
  Number a(1);
  Number b(-1)
  Number result = a.add(b);
  assert((a + b) == Number(0));
}

想象一下testAddZeros()testAddOnes()是否运行正常,但testAddNegativeNumber().在这种情况下,在Number result = a.add(b);处设置断点将是开始调试的自然位置.现在,假设错误位于Number::add内部的某个深处,因此我们对在Numbers::add早期发生的事情并没有真正的兴趣.我想做的是在Numbers::add内的某个地方设置一个断点,该断点仅在我位于testAddNegativeNumber() -test内时触发.

Imagine if testAddZeros() and testAddOnes() runs fine, but testAddNegativeNumber(). In this case setting a breakpoint at Number result = a.add(b); would be a natural place to start debugging. Now imagine that the error is located somewhere deep inside Number::add, so we're not really interrested in the stuff that occurs early in Numbers::add. What I want to do is to set a breakpoint somewhere inside Numbers::add that only triggers if I'm inside the testAddNegativeNumber()-test.

是否有任何方法可以在击中断点A时自动启用断点B?

Is there any way to automatically enable breakpoint B when breakpoint A is hit?

推荐答案

通过使用一些全局存储来保存将启用依赖断点的标记,即使不更改代码也可以获取依赖断点.

You can get the dependent breakpoints even without changing the code, by using some global storage to hold the marker that will enable dependent breakpoint.

我发现的最易访问的存储之一是应用程序域自定义属性.可以通过System.AppDomain.CurrentDomain.GetData和SetData方法访问它们.

One of the most accessible storages that I've found is app domain custom properties. They can be accessed by System.AppDomain.CurrentDomain.GetData and SetData methods.

因此,在第一个断点处,您可以使用以下命令定义命中时"设置:

So on first breakpoint you define a "when hit" setting with :

{System.AppDomain.CurrentDomain.SetData("break",true)}

{System.AppDomain.CurrentDomain.SetData("break",true)}

在相关断点上,将命中条件设置为:

On the dependent breakpoint, set hit condition to:

System.AppDomain.CurrentDomain.GetData("break")!=空

System.AppDomain.CurrentDomain.GetData("break") != null

这篇关于如果已达到断点A,则启用断点B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆