JPDA/JDI: will breakpoints on "suspend_none" policy still send an event?

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...");

// 93:public void echoPath(String k, String v) {
// 94: echoPath(System.out, k, v);

ReferenceType rt = cpe.referenceType();
out("rt="+rt);

// * ()V
// * ([Ljava/lang/String;)V
// * (IIII)Z
List ml = rt.methodsByName("echoPath",
"(Ljava/lang/String;Ljava/lang/String;)V");
//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;
}
}
 
L

Larry Barowski

NOBODY said:
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:
...

I just tried setting the suspend policy to none for breakpoints in our
JDI debugger and it still gets hit. So the suspend policy is not the
problem,
but I don't see any bug that is obvious to me. Are you sure the line 94
according to your text editor or whatever is also 94 according to JDI?

Also, a general warning if you plan to produce a bulletproof
application that uses JDI: make sure to read the "Global Exceptions"
section on the JDI docs overview page - almost every method can
throw a bunch of exceptions that are undocumented in the rest of
the javadoc.


-Larry Barowski
 
N

NOBODY

Yes I use a correct line number.

The bug is in the EventSet:
even if I called vm.resume() after the vmstartedevent,
even if the eventset does not contain any suspend policy event,
I had to call eventset.resume() on every eventset,
like I had to acknoledge the eventset anyway.

I will report it to sun.
 
L

Larry Barowski

NOBODY said:
Yes I use a correct line number.

The bug is in the EventSet:
even if I called vm.resume() after the vmstartedevent,
even if the eventset does not contain any suspend policy event,
I had to call eventset.resume() on every eventset,
like I had to acknoledge the eventset anyway.

I will report it to sun.

Well, EventSet.resume() has no description in the javadoc.
Calling it may be a requirement, but they should document that
at EventSet.resume() and EventQueue.remove() if it is.

-Larry Barowski
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top