开发者

JDI/JPDA Event Filtering

In JDI, there is the API to exclude events from processed events in JVM used by JPDA. This is done using:

  1. addExclusionFilter(String) to exclude some pattern; e.g. addExclusionFilter("java.*")
  2. addClassFilter(String) to include some pattern; e.g. addClassFilter("java.util.*")

Now, I need both. I need to exclude all events coming from "java.*" but I need to receive events from "java.util.Iterator".

Also, note that for instance java.util.Iterator is an interface impl开发者_如何学Goemented by some private class in java.util.AbstractList. How do we receive such events to java.util.Iterator?

When I used both methods, I actually do not receive events any more. Do you have an idea how to do that? Thanks in advance.


You can use the addClassFilter method that takes a ReferenceType as an argument, which (unlike the String-arg version) matches any subtype of the given type. With jdiscript and Java 8, firing on Iterator method calls could look something like:

public static void main(String[] args) {
    JDIScript j = new JDIScript(new VMLauncher(OPTIONS, MAIN).start());

    OnVMStart start = se -> {
        List<ReferenceType> rts = j.vm().classesByName("java.util.Iterator");
        j.methodEntryRequest(me -> {
            println("Your handler here");
        }).addClassFilter(rts.get(0))
          .enable();
    };

    j.run(start);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜