1

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 implemented 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.

nobeh
  • 9,784
  • 10
  • 49
  • 66
  • what do u mean by "I actually receive events any more"? – janetsmith Jun 18 '12 at 04:42
  • Sorry that was a mistake by me, question updated. – nobeh Jun 18 '12 at 07:12
  • For receiving "java.util.Iterator " events addClassFilter("java.util.Iterator") is enough. Your method was not working because you had excluded "java.util.Iterator" already by applying exclusion filter on "java.*". – rainyday Sep 22 '17 at 07:23

1 Answers1

1

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);
}
jfager
  • 279
  • 1
  • 8