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:
addExclusionFilter(String)
to exclude some pattern; e.g.addExclusionFilter("java.*")
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);
}
精彩评论