get current StackFrame thru JDI

K

Ken.C

Hi,
I did Google search but didn't get much useful info...
Basically, I encountered IndexOutOfBoundsException when trying to get
current stack frame:
1 void methodEntryEvent(MethodEntryEvent event) {
2 Method method = event.method();
3 ThreadReference thread = (ThreadReference) event.thread();
4 try {
5 StackFrame stackFrame = thread.frame(0);
.............
}
catch(IncompatibleThreadStateException e){
........
}
}

The exception occurred at line 5. Test codes running on the target VM
are:

public static void main(String[] args) {
String name = "Someone";
System.out.println(foo(name));
}

private static String foo(String name) {
System.out.println(bar(888));
return "Hi, " + name + ".";
}

private static int bar(int a) {
return 999;
}

Does anyone know why the stack counter is always 0 in my codes?

Thanks a lot
 
C

Chris Uppal

Ken.C said:
Does anyone know why the stack counter is always 0 in my codes?

I know very little about JDI, but no one else has replied so....

Was the thread suspended at the time the event was generated ? If not then I
doubt whether frames are available (since the thread will have gone on
executing while the event was passed through the event queue). See the
documentation for

EntryRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL)

And then you'll have to resume() the target ThreadReference. There's more
documentation about it, but I've only skimmed that -- you should probably read
it more carefully than me ;-)

-- chris
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top