N
NOBODY
Hi,
I just started with the java debugger interface JDI.
I managed to start a jvm on my test class, request and received a class
prepare event so that I can
request and enable a breakpoint on a valid method and location in that
method. The test code run fine,
the process stdout/stderr are read correctly., and are sane, and the
program exits fine.
The problem is that I dont get any breakpoint event, "cnt" is still 0.
According to my test code logic, it should return 4.
I don't want to "break", just trace. Is that possible at all?
Here is only the event setup code. The other classes are not required
because they work fine.
Unless you have some other code question, here is the code:
------
package testjdi;
import java.util.List;
import com.sun.jdi.AbsentInformationException;
import com.sun.jdi.Location;
import com.sun.jdi.Method;
import com.sun.jdi.ReferenceType;
import com.sun.jdi.connect.Connector;
import com.sun.jdi.event.BreakpointEvent;
import com.sun.jdi.event.ClassPrepareEvent;
import com.sun.jdi.event.Event;
import com.sun.jdi.event.VMDeathEvent;
import com.sun.jdi.event.VMDisconnectEvent;
import com.sun.jdi.event.VMStartEvent;
import com.sun.jdi.request.BreakpointRequest;
import com.sun.jdi.request.ClassPrepareRequest;
import com.sun.jdi.request.EventRequest;
import com.sun.jdi.request.EventRequestManager;
public class ColumnFormatterTestStateHandler implements JDIStateHandler {
static final String CLAZZ = "testjdi.ColumnFormatter";
int cnt = 0;
public int getCount() {
return cnt;
}
private void out(Object obj) {
System.out.println("~jdi handler: "+obj);
}
//CALLED FIRST
public void setupArguments(Connector.StringArgument vmargs,
Connector.StringArgument mainargs) {
vmargs.setValue("-cp C:\\java\\eclipse_prj\\output");
mainargs.setValue(CLAZZ+" arg1 \"long arg2 with space\"
arg3");
}
//CALLED SECOND
public void setupTracing(EventRequestManager erm) {
ClassPrepareRequest cpr = erm.createClassPrepareRequest();
cpr.addClassFilter(CLAZZ);//warning: supposed to be a regex
//cpr.addCountFilter(1);
cpr.enable();
}
private void setupHitCountTracer(ClassPrepareEvent cpe) {
out("preparing trace counter breakpoint...");
// 93ublic void echoPath(String k, String v) {
// 94: echoPath(System.out, k, v);
ReferenceType rt = cpe.referenceType();
out("rt="+rt);
// * ()V
// * ([Ljava/lang/StringV
// * (IIII)Z
List ml = rt.methodsByName("echoPath",
"(Ljava/lang/String;Ljava/lang/StringV");
//out(ml);
Method m = (Method)ml.iterator().next();
out("m="+m);
Location loc = null;
try {
List ll = m.locationsOfLine(94);
//out(ll);
loc = (Location)ll.iterator().next();
out("loc="+loc);
} catch (AbsentInformationException e) {
out("no such line location: "+e);
return;
}
BreakpointRequest br = cpe.virtualMachine
().eventRequestManager().createBreakpointRequest(loc);
out("br="+br);
br.setSuspendPolicy(EventRequest.SUSPEND_NONE);
br.enable();
}
//CALLED IN LOOP over eventqueue
public boolean handleEvent(Event ev) {
out(ev);
if(ev instanceof VMStartEvent) {
out("calling vm.resume()...");
ev.virtualMachine().resume();
} else if(ev instanceof VMDisconnectEvent) {
return true;
} else if(ev instanceof VMDeathEvent) {
return true;
} else if(ev instanceof BreakpointEvent) {
cnt++;
} else if(ev instanceof ClassPrepareEvent) {
ClassPrepareEvent cpe = (ClassPrepareEvent)ev;
setupHitCountTracer(cpe);
}
return false;
}
}
I just started with the java debugger interface JDI.
I managed to start a jvm on my test class, request and received a class
prepare event so that I can
request and enable a breakpoint on a valid method and location in that
method. The test code run fine,
the process stdout/stderr are read correctly., and are sane, and the
program exits fine.
The problem is that I dont get any breakpoint event, "cnt" is still 0.
According to my test code logic, it should return 4.
I don't want to "break", just trace. Is that possible at all?
Here is only the event setup code. The other classes are not required
because they work fine.
Unless you have some other code question, here is the code:
------
package testjdi;
import java.util.List;
import com.sun.jdi.AbsentInformationException;
import com.sun.jdi.Location;
import com.sun.jdi.Method;
import com.sun.jdi.ReferenceType;
import com.sun.jdi.connect.Connector;
import com.sun.jdi.event.BreakpointEvent;
import com.sun.jdi.event.ClassPrepareEvent;
import com.sun.jdi.event.Event;
import com.sun.jdi.event.VMDeathEvent;
import com.sun.jdi.event.VMDisconnectEvent;
import com.sun.jdi.event.VMStartEvent;
import com.sun.jdi.request.BreakpointRequest;
import com.sun.jdi.request.ClassPrepareRequest;
import com.sun.jdi.request.EventRequest;
import com.sun.jdi.request.EventRequestManager;
public class ColumnFormatterTestStateHandler implements JDIStateHandler {
static final String CLAZZ = "testjdi.ColumnFormatter";
int cnt = 0;
public int getCount() {
return cnt;
}
private void out(Object obj) {
System.out.println("~jdi handler: "+obj);
}
//CALLED FIRST
public void setupArguments(Connector.StringArgument vmargs,
Connector.StringArgument mainargs) {
vmargs.setValue("-cp C:\\java\\eclipse_prj\\output");
mainargs.setValue(CLAZZ+" arg1 \"long arg2 with space\"
arg3");
}
//CALLED SECOND
public void setupTracing(EventRequestManager erm) {
ClassPrepareRequest cpr = erm.createClassPrepareRequest();
cpr.addClassFilter(CLAZZ);//warning: supposed to be a regex
//cpr.addCountFilter(1);
cpr.enable();
}
private void setupHitCountTracer(ClassPrepareEvent cpe) {
out("preparing trace counter breakpoint...");
// 93ublic void echoPath(String k, String v) {
// 94: echoPath(System.out, k, v);
ReferenceType rt = cpe.referenceType();
out("rt="+rt);
// * ()V
// * ([Ljava/lang/StringV
// * (IIII)Z
List ml = rt.methodsByName("echoPath",
"(Ljava/lang/String;Ljava/lang/StringV");
//out(ml);
Method m = (Method)ml.iterator().next();
out("m="+m);
Location loc = null;
try {
List ll = m.locationsOfLine(94);
//out(ll);
loc = (Location)ll.iterator().next();
out("loc="+loc);
} catch (AbsentInformationException e) {
out("no such line location: "+e);
return;
}
BreakpointRequest br = cpe.virtualMachine
().eventRequestManager().createBreakpointRequest(loc);
out("br="+br);
br.setSuspendPolicy(EventRequest.SUSPEND_NONE);
br.enable();
}
//CALLED IN LOOP over eventqueue
public boolean handleEvent(Event ev) {
out(ev);
if(ev instanceof VMStartEvent) {
out("calling vm.resume()...");
ev.virtualMachine().resume();
} else if(ev instanceof VMDisconnectEvent) {
return true;
} else if(ev instanceof VMDeathEvent) {
return true;
} else if(ev instanceof BreakpointEvent) {
cnt++;
} else if(ev instanceof ClassPrepareEvent) {
ClassPrepareEvent cpe = (ClassPrepareEvent)ev;
setupHitCountTracer(cpe);
}
return false;
}
}