简体   繁体   English

Eclipse调试断点仅在特定子类的虚拟调用时停止

[英]Eclipse debug breakpoint stopping only on virtual invocation of specific subclass

Let's say we have an abstract class with method onPoke(..). 假设我们有一个带有方法onPoke(..)的抽象类。

abstract class BaseValuePanel{
  void onPoke(int depth){
      //blah, blah, ...
  }
}
  • Classes NumberValuePanel, AttributeValuePanel, CategoryValuePanel extend BaseValuePanel. 类NumberValuePanel,AttributeValuePanel,CategoryValuePanel扩展BaseValuePanel。
  • Among others, class DecimalValuePanel extends NumberValuePanel. 其中,DecimalValuePanel类扩展了NumberValuePanel。
  • Among others, class EstimationValuePanel extends DecimalValuePanel. 其中,类EstimationValuePanel扩展了DecimalValuePanel。
  • None of the extension classes overrides onPoke(..) method. 没有任何扩展类覆盖onPoke(..)方法。

Now, I wish to place a breakpoint on onPoke(..) but only when invoked thro an object of the class EstimationValuePanel. 现在,我希望在onPoke(..)上放置一个断点,但仅在调用类EstimationValuePanel的对象时。

Because right now, if I placed a breakpoint on onPoke(..), the debugger would stop thousands of instances (because of the extensive descendant classes of BaseValuePanel) and only one of which was due to invocation thro EstimationValuePanel. 因为现在,如果我在onPoke(..)上放置一个断点,调试器将停止数千个实例(因为BaseValuePanel的广泛后代类),并且其中只有一个是由于EstimationValuePanel的调用。

What is the sequence of set-up or strategy of breakpoint set-up that I need to employ, in order to allow the debugger to stop only when the method was invoked thro EstimationValuePanel. 我需要采用的断点设置的设置顺序或策略是什么,以便允许调试器仅在EstimationValuePanel调用方法时停止。

What I meant by virtual breakpoint ...: 我的意思是虚拟断点......:
That is, in Java as opposed to C#, non-private, non-static, (overridable) methods are naturally virtual. 也就是说,在Java而不是C#中,非私有,非静态(可覆盖)方法自然是虚拟的。 Hence, virtual invocation here. 因此,虚拟调用在这里。

Of course you can override the method in class EstimationValuePanel and set the breakpoint only there. 当然,您可以覆盖EstimationValuePanel类中的方法,并仅在那里设置断点。

But you can also use conditional breakpoints: go to the properties of the breakpoint on the method onPoke() (right-click or Ctrl + double-click) and select "Conditional". 但您也可以使用条件断点:转到方法onPoke()上的断点属性(右键单击 Ctrl +双击)并选择“条件”。 In the text area below you can enter the following condition: 在下面的文本区域中,您可以输入以下条件:

this instanceof EstimationValuePanel

This means the condition is evaluated everytime the method is entered. 这意味着每次输入方法时都会评估条件。 So if you experience perfomance issues, you should prefer to override the method in EstimationValuePanel. 因此,如果遇到性能问题,则应优先覆盖EstimationValuePanel中的方法。

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

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