get current StackFrame thru JDI

Discussion in 'Java' started by Ken.C, Feb 5, 2007.

  1. Ken.C

    Ken.C Guest

    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
    Ken.C, Feb 5, 2007
    #1
    1. Advertising

  2. Ken.C

    Chris Uppal Guest

    Ken.C wrote:

    > 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
    Chris Uppal, Feb 7, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Fidge
    Replies:
    0
    Views:
    1,119
    Ben Fidge
    Jan 15, 2005
  2. Joe Rattz
    Replies:
    3
    Views:
    434
    Scott Allen
    Jun 15, 2005
  3. NOBODY
    Replies:
    3
    Views:
    576
    Larry Barowski
    Feb 4, 2004
  4. Replies:
    2
    Views:
    349
    Jamie
    Feb 11, 2005
  5. Random

    read parameters through StackFrame

    Random, Aug 13, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    321
    Random
    Aug 13, 2007
Loading...

Share This Page