javadebuggingbreakpointsjdi

Java Debug Interface: put the breakpoints at arbitrary locations in the code


I am using the Java Debug Interface API to write the custom programs for debugging the Java applications I write. I am able to add breakpoints to the start of a required method invocation by using the code as:

ReferenceType classRef = vm.classesByName(className).get(0);
Method meth = classRef.methodsByName(methodName).get(0);
BreakpointRequest brF1 = vm.eventRequestManager().createBreakpointRequest(meth.location());
brF1.enable();

However I am unable to make out how to get Location objects for arbitrary locations within the source files.


Solution

  • There are several ways to retrieve a Location for other locations in a source file.

    E. g., Method has several operations for this:

    Also ReferenceType has operations for this. Just browse for the usage of Location.