Java Eclipse中调用者的条件断点 [英] Conditional breakpoint by caller in Java eclipse

查看:154
本文介绍了Java Eclipse中调用者的条件断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Eclipse调试器中的Java程序中的监视点来跟踪值的更改.类的层次结构非常复杂,我跟踪的值包装在容器中,该容器在许多地方都使用过.

I am trying to track a change of a value using watchpoint in a Java program in Eclipse debugger. The class hierarchy is pretty complex and the value I am tracking is wrapped in container, which is used on many places.

更具体地说,有一个容器SizeRequirement,它具有我正在跟踪的属性minimum.此类在许多地方的许多布局管理器中用于许多组件,以定义对组件尺寸的要求.我需要捕获确切的调用,在其中为一个特定的布局管理器和其中的一个特定组件更改/设置值.是否可以按调用者过滤断点?我将尝试使用一些抽象代码来解释该问题:

To be more specific, there is a container SizeRequirement, which has a property minimum, which I am tracking. This class is used by many layout managers on many places for many components to define requirement for component's sizes. I need to catch exact call, where the value changes/is set for one specific layout manager and one specific component in it. Is it possible to filter breakpoints by caller? I will try to explain the problem using some abstract code:

class ValueContainer {
  public String value;
}

class A {

  private ValueContainer valueContainer;

  public A () {
    valueContainer = new ValueContainer();
    valueContainer.value = "setByA";
  }

}

class B {

  private ValueContainer valueContainer;

  public B () {
    valueContainer = new ValueContainer();
    valueContainer.value = "setByB";
  }

}

我在value上设置了一个观察点,并且我只希望断点仅在A类设置了value并暂停B调用时才挂起.

I set a watchpoint on value and I only want breakpoint to suspend only when the value is set by class A and ignore calls by B.

更糟糕的是,类SizeRequirement是swing库的一部分,并且已深入集成到代码中,因此我无法在要跟踪它的某个确切位置使用继承将其替换为某些子级.

To make things worse, class SizeRequirement is part of swing library and is deeply integrated in code, so I cannot use inheritance to replace it by some child on some exact place where I want to track it.

编辑

这就是我用作条件断点条件的条件.信不信由你,它行得通. :)

So this is what I used as conditional breakpoint condition. Believe or not, it works. :)

    StackTraceElement[] arr = Thread.currentThread().getStackTrace();
    boolean contains = false;
    for(StackTraceElement e : arr) {
        if (e.getClassName().contains("A")) {
            contains = true;
            break;
        }
    }

推荐答案

这很令人讨厌,而且速度可能很慢,但是您可以使用

It's pretty disgusting and probably slow, but you can use

Thread.currentThread().getStackTrace()[2].getClassName().contains("A")

作为断点条件.

基于此错误 https://bugs.eclipse.org/bugs/show_bug.cgi?id = 72961 我不认为Eclipse将直接支持它

Based on this bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=72961 I don't think Eclipse will support it directly

这篇关于Java Eclipse中调用者的条件断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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